Jump to content
Sign in to follow this  
Spunned

Only adds 1 magazine to inventory, but adds all in editor

Recommended Posts

Hi

In the editor, i add all my magazines to my player / npc, but if i launch the mission on a server, they all carry only one magazine.

this addUniform "U_IG_Guerilla2_3"; 
this addHeadgear "H_Beret_red"; 
this unassignItem "NVGoggles_OPFOR"; 
this removeItem "NVGoggles_OPFOR"; 
removeAllWeapons this;
this addMagazines ["30Rnd_mas_545x39_mag", 5]; 
this addWeapon "arifle_mas_aks74";

at first i simply pasted the this addMagazine "30Rnd_mas_545x39_mag"; 5 times, but that didn't work either on the server, but in the editor.

Can anyone see what i'm doing wrong?

thanks for the help

---------- Post added at 10:47 ---------- Previous post was at 09:50 ----------

Just figured it out.

Use a foreach statement to remove all the magazines the unit spawns with and THEN add the new ones.

here's the updated code:

sleep 5; this addUniform "U_O_OfficerUniform_ocamo"; this addHeadgear "H_Beret_red"; this unassignItem "NVGoggles_OPFOR"; this removeItem "NVGoggles_OPFOR"; removeAllWeapons this; {player removeMagazine _x} forEach magazines player; this addMagazines ["30Rnd_mas_545x39_mag", 8]; this addWeapon "arifle_mas_aks74";

Share this post


Link to post
Share on other sites

Good solution if you wan't to remove all magazines of all types but there is another scripting command that allows you to remove all magazines of a certain type that wouldnt remove say... pistol magazines.

// This is okay if you need to remove every magazine of every type (including pistol)
{player removeMagazine _x} forEach magazines player;

// This is the best practice (it removes all magazines of a certain type - more precise - less things can go wrong here.)
player removeMagazines "magazine_classname_here"

I would always suggest adding the weapon's to the unit first - this way they will not have to reload (whether its AI or Players) - as the magazine will be placed in the weapon and the remaining 4 will be placed in the remaining storage of the unit (Uniform, Vest, and Backpack -- Im not sure as to the priority it decides to place them in these containers).

// Adding weapon first puts a magazine in the weapon when a compatible one is added.
this addWeapon "arifle_mas_aks74";  
this addMagazines ["30Rnd_mas_545x39_mag", 5];

Keep on scripting it only gets easier! ;)

Share this post


Link to post
Share on other sites

Could always use the addweapon function. Also it will automatically add the magazines first so the unit will not go through the reloading animation.

[_unit, "arifle_MX_F" ,10 ,"30Rnd_65x39_caseless_mag"] call BIS_fnc_addWeapon;

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×