Jump to content
Sign in to follow this  
_qor

array question

Recommended Posts

Hey there,

I never really worked with arrays, so I have got a simple question about it.

There are 3 ammocrates and I want to fill them up all with the same weapon gear.

So I tried to do this:

_this = [box1, box2, box3];

_this addWeaponCargo...
_this addMagazineCargo...

But apparently this is not the way arrays work ;)

I just want to avoid to paste _this select 1/2/3 to each ~50 lines.

So is there a way to simplify this with an array, or do I have to achieve it with another code?

Thanks for help!

Share this post


Link to post
Share on other sites

Use this for example:

{_x addWeaponCargo ["M16A2",5]; _x addMagazineCargo ["30Rnd_556x45_Stanag",5];} forEach [box1, box2, box3];

Edited by survivorluz

Share this post


Link to post
Share on other sites

Thank you all!

But although I will use survivorluz's code, I am still asking myself why this array doesnt work.

I already read the array beginner's guide, but it doesnt answer my question.

So when using _this = [box1, box2, box3], _this would contain box1, box2 and box3.

Cant I pass on all this content to a code with one variable?

Share this post


Link to post
Share on other sites

My multiplayer ammoboxes filler script for ArmA3. You can use this for ArmA2 too, you must only rewrite the classes of items,magazines and weapons. In some kinds of scripts you don't need to use variables. ;)

//Multiplayer ammoboxes filler script created by [CSLA]LUKI for ArmA3

clearMagazineCargoGlobal box1;
clearWeaponCargoGlobal box1;
clearMagazineCargoGlobal box2;
clearWeaponCargoGlobal box2;
clearMagazineCargoGlobal box3;
clearWeaponCargoGlobal box3;

// weapons, items and magazines for ammobox box1
box1 addItemCargoGlobal ["acc_flashlight",9];
box1 addItemCargoGlobal ["FirstAidKit",9];
box1 addItemCargoGlobal ["Binocular",9];
box1 addWeaponCargoGlobal ["arifle_MX_F",9];
box1 addMagazineCargoGlobal ["100Rnd_65x39_caseless_mag",9];
box1 addMagazineCargoGlobal ["100Rnd_65x39_caseless_mag_Tracer",9];
box1 addBackpackCargoGlobal ["B_Carryall_oli",9]; 
box1 addBackpackCargoGlobal ["B_Bergen_rgr",9];
box1 addBackpackCargoGlobal ["B_HuntingBackpack",9];


// weapons, items and magazines for ammobox box2
box2 addItemCargoGlobal ["acc_flashlight",9];
box2 addItemCargoGlobal ["FirstAidKit",9];
box2 addItemCargoGlobal ["Binocular",9];
box2 addWeaponCargoGlobal ["arifle_MX_F",9];
box2 addMagazineCargoGlobal ["100Rnd_65x39_caseless_mag",9];
box2 addMagazineCargoGlobal ["100Rnd_65x39_caseless_mag_Tracer",9];
box2 addBackpackCargoGlobal ["B_Carryall_oli",9]; 
box2 addBackpackCargoGlobal ["B_Bergen_rgr",9];
box2 addBackpackCargoGlobal ["B_HuntingBackpack",9];


// weapons, items and magazines for ammobox box3
box3 addItemCargoGlobal ["acc_flashlight",9];
box3 addItemCargoGlobal ["FirstAidKit",9];
box3 addItemCargoGlobal ["Binocular",9];
box3 addWeaponCargoGlobal ["arifle_MX_F",9];
box3 addMagazineCargoGlobal ["100Rnd_65x39_caseless_mag",9];
box3 addMagazineCargoGlobal ["100Rnd_65x39_caseless_mag_Tracer",9];
box3 addBackpackCargoGlobal ["B_Carryall_oli",9]; 
box3 addBackpackCargoGlobal ["B_Bergen_rgr",9];
box3 addBackpackCargoGlobal ["B_HuntingBackpack",9];

Edited by [CSLA]LUKI
mistake in code

Share this post


Link to post
Share on other sites
Thank you all!

But although I will use survivorluz's code, I am still asking myself why this array doesnt work.

I already read the array beginner's guide, but it doesnt answer my question.

So when using _this = [box1, box2, box3], _this would contain box1, box2 and box3.

Cant I pass on all this content to a code with one variable?

Hey QoR,

The reason why your script wont work is because of the parameters of AddWeaponCargo and AddMagazineCargo.

https://community.bistudio.com/wiki/addWeaponCargo & https://community.bistudio.com/wiki/addMagazineCargo

As seen on the wiki, the correct syntax is: vehicleName addMagazineCargo [magazineName, count]

where vehicleName is an 'Object', not an 'Array'. For more info on what an 'Object' may include: https://community.bistudio.com/wiki/Object

I hope this helped you, basically it's just syntaxes that you have to follow. Survivorluz's code is an efficient way of using forEach to fill up multiple 'Objects' aka crates.

edit: Do realize that you can use Survivorluz's code in a different display using the brackets.

original:

{_x addWeaponCargo ["M16A2",5]; _x addMagazineCargo ["30Rnd_556x45_Stanag",5];} forEach [box1, box2, box3]; 

new:

{
_x addWeaponCargo ["M16A2",5]; 
_x addMagazineCargo ["30Rnd_556x45_Stanag",5];
} forEach [box1, box2, box3]; 

This will make it easier for you to add a big list of weapons&mags to multiple crates at once.

Kind regards,

Sanchez

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  

×