Jump to content
RyanTurner

Multi-dimensional Array [ getItemCargo ]

Recommended Posts

So I'm having a problem with Multi-dimensional Arrays within getItemCargo function.

 

So we I've been doing some Mission Phases with Items of Certain Supply Crates, this case the "loot" that the players acquire throughout the mission. I've copy the Creates Data (getItemCargo) but when I get the value to my clipboard I get this:

[["rhsgref_chicom","rhs_uniform_gorka_r_y_gloves","rhsgref_ssh68_ttsko_mountain","rhssaf_vest_md99_woodland_radio","rhssaf_uniform_m93_oakleaf_summer","rhssaf_helmet_m59_85_oakleaf","rhs_scarf","ACE_fieldDressing","ACE_packingBandage","ACE_morphine","ACE_tourniquet"]
,[1,1,1,2,2,1,1,2,1,3,1]]

And when I try to crate an Array and select the array content I simply can't doesn't give me any data via the Debug in game, hint or SQF script variable.
 

_multiArray = [
["rhsgref_chicom","rhs_uniform_gorka_r_y_gloves","rhsgref_ssh68_ttsko_mountain","rhssaf_vest_md99_woodland_radio","rhssaf_uniform_m93_oakleaf_summer","rhssaf_helmet_m59_85_oakleaf","rhs_scarf","ACE_fieldDressing","ACE_packingBandage","ACE_morphine","ACE_tourniquet"]
,[1,1,1,2,2,1,1,2,1,3,1]
]

Isn't multiArray select 0; supposed to give me the content of the first array? (the one with uniforms and weapons etc).

Because at the end of the day I want to be able to grab both arrays and grab their indexes and match between Arrays. Array1[0] and Array2[0] to match the Gear and the Amount. and just run a for loop to Merging their indexes. so I can later add them into a create in a future mission start or editor. via the "AddItemCargo".

If someoen can clarifiy me how to work with Multi-dimension.

 

What I want to do.
1) Get Crate's Content (Already working)
2) Seperate the Array and make arrays withs the content (Gear, Amount)
3) Add those Arrays into the Crate

Share this post


Link to post
Share on other sites

Yes, known difficulty with these kind of commands.

 

General case (be sure both sub-arrays have same amount of elements):

_array1then2 = getItemCargo cursorObject;

// example [["rhsgref_chicom","rhs_uniform_gorka_r_y_gloves","rhsgref_ssh68_ttsko_mountain","rhssaf_vest_md99_woodland_radio","rhssaf_uniform_m93_oakleaf_summer", "rhssaf_helmet_m59_85_oakleaf","rhs_scarf","ACE_fieldDressing","ACE_packingBandage","ACE_morphine","ACE_tourniquet"] ,[1,1,1,2,2,1,1,2,1,3,1]]

 

_array12pair = _array1then2#0 apply {[_x,_array1then2#1#(_array1then2#0 find _x)]};

 // will return : [["rhsgref_chicom",1],["rhs_uniform_gorka_r_y_gloves",1],["rhsgref_ssh68_ttsko_mountain",1],["rhssaf_vest_md99_woodland_radio",2],["rhssaf_uniform_m93_oakleaf_summer",2],["rhssaf_helmet_m59_85_oakleaf",1],["rhs_scarf",1],["ACE_fieldDressing",2],["ACE_packingBandage",1],["ACE_morphine",3],["ACE_tourniquet",1]]

Now you can add these items into another crate (nextCrate):
 

{nextCrate addItemCargoGlobal _x} count _array12pair;

 

Copying complete crate content (including backpacks, vests, uniforms, and their own contents):

From crate1 (you can add you own backpacks, vests, uniforms if enough room or crate such as "VirtualReammoBox_camonet_F"

to crate2 (all items, weapons, mags, backpacks,... and their content will be copied, no matter the capacity of the crate2 (but you will not add anything else if you overload it!)


 

MGI_CRATECOPY = {
  params ["_crate1","_crate2"];
  _crate1 setVariable ["MGI_VEHCONT",[]];  
  _items = getItemCargo _crate1;  
  _mags = magazinesAmmoCargo _crate1;  
  (_crate1 getVariable "MGI_VEHCONT") pushBackUnique [_crate1,_items #0 apply {[_x,_items #1#(_items #0 find _x)]},(_mags arrayintersect _mags) apply {private _v= _x;_x+[{_v isEqualTo _x} count _mags]},weaponsItemsCargo _crate1,backpackCargo _crate1];  
  {  
    _items = getItemCargo (_x #1);  
    _mags = magazinesAmmoCargo (_x #1);  
    (_crate1 getVariable "MGI_VEHCONT") pushBack [_x select 0,_items #0 apply {[_x,_items #1#(_items #0 find _x)]},(_mags arrayintersect _mags) apply {private _v= _x;_x+[{_v isEqualTo _x} count _mags]},weaponsItemsCargo (_x select 1),[]]
  } forEach everyContainer _crate1;  

  {  
    _x params ["_cont",["_it",[]],["_mag",[]],["_wp",[]],["_bpk",[]]];  
    if (_cont isEqualType "") then {  
      _cont = everyContainer _crate2 select (_foreachindex -1) select 1;  
    } else {  
      _cont = _crate2;  
    };  
    clearItemCargoGlobal _cont;  
    clearMagazineCargoGlobal _cont;  
    clearWeaponCargoGlobal _cont;  
    clearBackpackCargoGlobal _cont;  
    {_cont addItemCargoGlobal [_x#0,_x#1]} count _it;  
    {_cont addMagazineAmmoCargo [_x#0,_x#2,_x#1]} count _mag;  
    {_cont addWeaponWithAttachmentsCargoGlobal [_x,1]} count _wp;  
    {_cont addBackpackCargoGlobal [_x,1]} count _bpk;  
  } forEach (_crate1 getVariable ["MGI_VEHCONT",[]]);
};

[crate1,crate2] call MGI_CRATECOPY;

Note: crate1 and crate2 must be crates or vehicles. This script doesn't work on units (but it's possible with some other commands)

 

  • Like 3

Share this post


Link to post
Share on other sites

This looks neat and all but aren't you create 2 loops (apply and find) which are not needed? @pierremgi

_array1then2 = getItemCargo cursorObject;
_array12pair = _array1then2#0 apply {[_x,_array1then2#1#(_array1then2#0 find_x)]};
{nextCrate addItemCargoGlobal _x} count _array12pair;

why not using the original array for filling the 2nd crate?

_array1then2 = getItemCargo cursorObject;

{
 nextCrate addItemCargoGlobal [ _x, (_array1then2 select 1 select _forEachIndex) ]; 
} forEach (_array1then2 select 0);

not tested. 

Maybe I ve overseen something but this looks simpler and faster to me ...

Share this post


Link to post
Share on other sites

Yes, you can write that. It was more an example from the transformed array:  [["a","b","c"],[1,2,3]]   >>>   [["a",1],["b",2],["c",3]]

forEach is slower than count ... when you can use count as is, for many elements.

Share this post


Link to post
Share on other sites
3 minutes ago, pierremgi said:

forEach is slower than count

for sure but not if u have to add 2 other loops to have it working... but I understood it was an example

Share this post


Link to post
Share on other sites

I was checking as you mention, out of already pre-created (in the editor) crates and named them since I can't do that on the editor. The storage amount i don't have a problem since we use "Ammo Cache Empty" (VirtualRealAmmoBox w/o Camo-net). Is there a possible way to save the data to an external file? Save it the output of the "_count" ?

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

×