Home   Help Search Login Register  

Author Topic: Give specific magazines i have to another unit  (Read 1872 times)

0 Members and 1 Guest are viewing this topic.

Offline fleepee

  • Members
  • *
  • Enter the Matrix!
Give specific magazines i have to another unit
« on: 08 Feb 2009, 14:58:23 »
hi!
I wanted to make a script to check if the player was having specific magazines ("15Rnd_9x19_M9SD"), and if so, give them to another unit (released prisoner) with an unloaded M9sd gun... but my scripting skills are what they are, and I need help for that purpose!!
thanks! ;)

Offline Deadfast

  • Members
  • *
Re: Give specific magazines i have to another unit
« Reply #1 on: 08 Feb 2009, 21:56:01 »
There you go:

Code: [Select]
_armed = soldier1; //define which unit is supposed to give out the mag
_unarmed = prisoner1; //define which unit gets the mag
_mag = "15Rnd_9x19_M9SD"; //define which mag should be given
_gun = "M9SD"; //define which gun should _unarmed get

if (_mag in (magazines player)) then //check if player has the mag
{
_armed removeMagazine _mag; //remove the mag from the player
_unarmed addMagazine _mag; //add the mag to the prisoner
_unarmed addWeapon _gun; //give him the weapon
};
« Last Edit: 08 Feb 2009, 21:58:31 by Deadfast »

Offline fleepee

  • Members
  • *
  • Enter the Matrix!
Re: Give specific magazines i have to another unit
« Reply #2 on: 08 Feb 2009, 22:15:12 »
 ;)
It works, but it took me hours to solve the problem of looping the script to give all the specific ammo to the other guy...

I wanted to add the number of magazines given in a sidechat sentence, (+ a different one if there's only one magazine given) with the %1 and a variable, but i was unable to do a corect script... :no:
Do you have an idea?
here's my code: (don't need to add the gun, the guy has his weapon, but no ammo)
Code: [Select]
_armed = _player
_unarmed = _hostage
_mag = "15Rnd_9x19_M9SD"
_magnumber=0

#loop
if (_mag in (magazines _player)) then {goto "muni"} else {goto "exit"}

#muni
jenai=true
_armed removeMagazine _mag
_unarmed addMagazine _mag
_magnumber=_magnumber+1
goto  "loop"

#exit
~0.6
if (_mag in (magazines _hostage)) then {_player sidechat localize "str_mag1"}
~3
if (_mag in (magazines _hostage)) then {reload _hostage}
exit
« Last Edit: 09 Feb 2009, 18:48:07 by fleepee »

Offline Deadfast

  • Members
  • *
Re: Give specific magazines i have to another unit
« Reply #3 on: 09 Feb 2009, 21:16:20 »
OK, there you go:

Code: (giveAmmo.sqf) [Select]
_armed = soldier1; //define which unit is supposed to give out the mag
_unarmed = prisoner1; //define which unit gets the mag
_mag = "15Rnd_9x19_M9SD"; //define which mag should be given
_gun = "M9SD"; //define which gun should _unarmed get

_num = 0;
while {_mag in (magazines player)} do //loop as long as _armed has mags
{
_armed removeMagazine _mag; //remove the mag from the player
_unarmed addMagazine _mag; //add the mag to the prisoner

_num = _num + 1; // +1 magazine given
};

player sideChat format [localize "STR_stringtableEntry", _num];
« Last Edit: 09 Feb 2009, 23:25:37 by Deadfast »

Offline fleepee

  • Members
  • *
  • Enter the Matrix!
Re: Give specific magazines i have to another unit
« Reply #4 on: 09 Feb 2009, 22:45:45 »
Quote
player sideChat format ["I gave the prisoner %1 magazines.", _num];
I forgot to mention that i was using a stringtable for the english and french version of dialogs...

Offline Deadfast

  • Members
  • *
Re: Give specific magazines i have to another unit
« Reply #5 on: 09 Feb 2009, 23:04:30 »
No problem, just change it to:

Code: [Select]
player sideChat format [localize "STR_stringtableEntry", _num];


Code: (stringtable.csv) [Select]
LANGUAGE, English, French
STR_stringtableEntry, "I gave the prisoner %1 magazines.", "I gave the prisoner %1 magazines."

Obviously translate that French part ;)

%1 is where the value of variable _num will be written out.
« Last Edit: 09 Feb 2009, 23:25:29 by Deadfast »

Offline fleepee

  • Members
  • *
  • Enter the Matrix!
Re: Give specific magazines i have to another unit
« Reply #6 on: 09 Feb 2009, 23:12:07 »
 :clap:
Thank you very much!!
It's so simple... when you know the codes!! :D
"Merci beaucoup!", that's for the french touch... Big thanks again, you're so quick! :good: