OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting Multiplayer => Topic started by: fleepee on 08 Feb 2009, 14:58:23

Title: Give specific magazines i have to another unit
Post by: fleepee 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! ;)
Title: Re: Give specific magazines i have to another unit
Post by: Deadfast 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
};
Title: Re: Give specific magazines i have to another unit
Post by: fleepee 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
Title: Re: Give specific magazines i have to another unit
Post by: Deadfast 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];
Title: Re: Give specific magazines i have to another unit
Post by: fleepee 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...
Title: Re: Give specific magazines i have to another unit
Post by: Deadfast 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.
Title: Re: Give specific magazines i have to another unit
Post by: fleepee 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: