Jump to content
sbondo1234

Adding multiple items in one command

Recommended Posts

I am trying to add magazines for a weapon to the player when they load a preset kit.

I currently have it like this:

_unit addItemToBackpack "20Rnd_762x51_Mag";

It works right now and adds one magazine to the player's backpack, but I want to add multiple mags to their backpack with one line of code instead of writing it out 20 times.

 

Any help would be greatly appreciated.

Share this post


Link to post
Share on other sites
for "_i" from 0 to 19 do { _unit addItemToBackpack "20Rnd_762x51_Mag" };

This will perform the code in the brackets {} 20 times and give _unit 20 magazines in the backpack.

"from 0 to 19" means that the game counts 0, 1, 2, 3... until 19 and including 19. Since it's starting on 0, which adds another digit, the code will run 20 times.

if you want, and it would be easier to read, you can also write:

for "_i" from 1 to 20 do {};

More info here: https://community.bistudio.com/wiki/for

  • Like 1

Share this post


Link to post
Share on other sites
//Specifically to backpack
backpackContainer _unit addMagazineCargoGlobal [ "20Rnd_762x51_Mag", 20 ];

//Any where in units inventory
_unit addMagazines [ "20Rnd_762x51_Mag", 20 ];

 

  • Like 3

Share this post


Link to post
Share on other sites
19 hours ago, Larrow said:

//Specifically to backpack
backpackContainer _unit addMagazineCargoGlobal [ "20Rnd_762x51_Mag", 20 ];

//Any where in units inventory
_unit addMagazines [ "20Rnd_762x51_Mag", 20 ];

 

 

19 hours ago, MrEmcee said:

for "_i" from 0 to 19 do { _unit addItemToBackpack "20Rnd_762x51_Mag" };

This will perform the code in the brackets {} 20 times and give _unit 20 magazines in the backpack.

"from 0 to 19" means that the game counts 0, 1, 2, 3... until 19 and including 19. Since it's starting on 0, which adds another digit, the code will run 20 times.

if you want, and it would be easier to read, you can also write:


for "_i" from 1 to 20 do {};

More info here: https://community.bistudio.com/wiki/for

Thanks a lot!

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

×