Jump to content
Undeceived

Recognize and count magazines, weapons and items in nested array

Recommended Posts

Hi guys,

 

The code I use generates this array with two "main" backpack-arrays in which again there are separated arrays of items, magazines and weapons:

 

_array = [["B_Carryall_khk",["CUP_optic_PGO7V"],["CUP_30Rnd_545x39_AK_M","CUP_30Rnd_545x39_AK_M"],["CUP_arifle_AK74","CUP_arifle_G36C"]],["B_TacticalPack_blk",["CUP_optic_PSO_1","FirstAidKit"],["CUP_30Rnd_556x45_G36"],["CUP_smg_bizon_snds"]]]

 

What I need now is the total number of weapons, of magazines and of items in this array.

 

The result should look like this:

_totalNumberOfItems  //3 (one PGO7V optic, one AK PSO-1 scope and one FirstAidKit)

_totalNumberOfMagazines //3 (two AK magazines and one G36 magazine)

_totalNumberOfWeapons //3 (one AK74, one G36c and one Bizon)

 

Any help? Thanks a lot!

Share this post


Link to post
Share on other sites

If you sub-arrays always have the same scheme, I mean :

[typeOf backPackOne, [items],[magazines],[weapons]]  even if some arrays are empty,

it's simple:
 

_totalNumberOfItems  = 0;
_totalNumberOfMagazines = 0;
_totalNumberOfWeapons = 0;

for "_i" from 0 to count _array -1 do {
  _subArray = _array select _i;
  _totalNumberOfItems = _totalNumberOfItems + count (_subArray select 1);
  _totalNumberOfMagazines = _totalNumberOfMagazines + count (_subArray select 2);
  _totalNumberOfWeapons = _totalNumberOfWeapons + + count (_subArray select 3);
};

 

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites
2 hours ago, pierremgi said:

 

 

And I thought I'd have to compare the classnames with the config file and so on. Good idea with the scheme, very simple indeed (I wouldn't have been able to do it nevertheless). Thanks, pierremgi, much appreciated!

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

×