Undeceived 392 Posted August 24, 2014 Hi guys - another array question, I guess... :rolleyes: I want to save all kinds of stuff to the weapon pool, including the following constellation: All content of a crate (weapons, magazines, items), but also backpacks, vests and uniform which are in that crate plus their own content. That would be: Array of weapons in crate = weaponCargo crate Array of magazines in crate = magazineCargo crate Array of items in crate = itemCargo crate Array of additional containers in crate (backpacks, vests, uniforms) = backpackCargo crate, vestCargo doesn't exist, neither does uniformCargo Array of the content of the backpacks, vests and uniforms = ?? The backpacks, vests and uniforms themselves in the crate are not so important to me, but their content is. Does anyone have an idea, how to get these arrays? Thanks for your time! Share this post Link to post Share on other sites
Larrow 2823 Posted August 25, 2014 Use the everyContainer command. That will return a nested array of containers within. Each inner array holds [classname, object reference] . You can then use the reference along with normal commands like itemCargo etc Share this post Link to post Share on other sites
Undeceived 392 Posted August 25, 2014 (edited) That's great, Larrow, thanks for pointing me in the right direction! containersincrate = everyContainer crate; Now I can check items, weapons and mags in every of these containers: magazineCargo ((containersincrate select 0) select 1) magazineCargo ((containersincrate select 1) select 1) The only thing left now is... How do I read out the items automatically? The thing is that I don't know how many containers will be in that crate. That gets a bit complicated again, for me at least. :D Thanks! Edited August 25, 2014 by Undeceived Share this post Link to post Share on other sites
John Kozak 14 Posted August 25, 2014 That's great, Larrow, thanks for pointing me in the right direction!containersincrate = everyContainer crate; Now I can check items, weapons and mags in every of these containers: magazineCargo ((containersincrate select 0) select 1) magazineCargo ((containersincrate select 1) select 1) The only thing left now is... How do I read out the items automatically? The thing is that I don't know how many containers will be in that crate. That gets a bit complicated again, for me at least. :D Thanks! Use recursion, Luke function_getContents = { _items = magazinesCargo _this + itemCargo _this ; // you extend this with weapons, launchers, etc... {_items=_items + (_x select 1) call function_getContents } foreach (every container _this); _items; } Needs some debugging - writing from smartphone. Share this post Link to post Share on other sites
Larrow 2823 Posted August 25, 2014 Quick test piece _containersInCrate = everyContainer crate; _numContainers = count _containersInCrate; _containerArray = []; for "_i" from 0 to (_numContainers -1) do { _containerClass = _containersInCrate select _i select 0; _containerRef = _containersInCrate select _i select 1; _containerItems = itemCargo _containerRef;; _containerMagazines = magazineCargo _containerRef; _containerWeapons = weaponCargo _containerRef; _containerArray = _containerArray + [ [_containerClass, _containerItems, _containerMagazines, _containerWeapons] ]; }; _container array would end up looking something like (B_Soldier_F default Uniform and Vest plus a Backpack with a gun and 2 mags added to him dumped into the crate) [ //First Container [ "U_B_CombatUniform_mcam", //Container Class [ //Items "FirstAidKit" ], [ //Magazines "30Rnd_65x39_caseless_mag", "30Rnd_65x39_caseless_mag", "Chemlight_green" ], [ //Weapons ] ], //Second Container [ "V_PlateCarrier1_rgr", [ ], [ "30Rnd_65x39_caseless_mag", "30Rnd_65x39_caseless_mag", "30Rnd_65x39_caseless_mag", "30Rnd_65x39_caseless_mag", "30Rnd_65x39_caseless_mag", "30Rnd_65x39_caseless_mag", "30Rnd_65x39_caseless_mag", "16Rnd_9x21_Mag", "16Rnd_9x21_Mag", "SmokeShell", "SmokeShellGreen", "Chemlight_green", "HandGrenade", "HandGrenade" ], [ ] ], //Third container [ "B_AssaultPack_blk", [ ], [ "16Rnd_9x21_Mag", "11Rnd_45ACP_Mag" ], [ "hgun_Pistol_heavy_01_F" ] ] ] Adding containers back filled with items { _containerClass = _x select 0; if (_containerClass iskindof "bag_base") then { crate addBackpackCargoGlobal [_containerClass, 1]; }else{ crate addItemCargoGlobal [_containerClass,1]; }; _containerRef = (everyContainer crate) select ((count (everyContainer crate)) -1) select 1; _items = _x select 1; _magazines = _x select 2; _weapons = _x select 3; { _typeArray = _x; _arrayNum = _forEachIndex; if (count _typeArray > 0) then { { switch _arrayNum do { case 0 : { _containerRef addItemCargoGlobal [_x, 1]; }; case 1 : { _containerRef addMagazineCargoGlobal [_x, 1]; }; case 2 : { _containerRef addWeaponCargoGlobal [_x, 1]; }; }; }forEach _typeArray; }; }forEach [_items, _magazines, _weapons];; }forEach _containerArray; And heres all my test code, Just place a player with the code below pasted in its init, an ammo box called crate and test it out. player addAction ["export crate", { thread = [] spawn { _containersInCrate = everyContainer crate; _numContainers = count _containersInCrate; _containerArray = []; for "_i" from 0 to (_numContainers -1) do { _containerClass = _containersInCrate select _i select 0; _containerRef = _containersInCrate select _i select 1; _containerItems = itemCargo _containerRef;; _containerMagazines = magazineCargo _containerRef; _containerWeapons = weaponCargo _containerRef; _containerArray = _containerArray + [ [_containerClass, _containerItems, _containerMagazines, _containerWeapons] ]; }; hintSilent str _containerArray; copyToClipboard str _containerArray; cArray = _containerArray; }; }]; player addAction ["empty crate", { clearItemCargoGlobal crate; clearMagazineCargoGlobal crate; clearWeaponCargoGlobal crate; clearBackpackCargoGlobal crate; }]; player addAction ["refill crate", { { _containerClass = _x select 0; if (_containerClass iskindof "bag_base") then { crate addBackpackCargoGlobal [_containerClass, 1]; }else{ crate addItemCargoGlobal [_containerClass,1]; }; _containerRef = (everyContainer crate) select ((count (everyContainer crate)) -1) select 1; _items = _x select 1; _magazines = _x select 2; _weapons = _x select 3; { _typeArray = _x; _arrayNum = _forEachIndex; if (count _typeArray > 0) then { { switch _arrayNum do { case 0 : { _containerRef addItemCargoGlobal [_x, 1]; }; case 1 : { _containerRef addMagazineCargoGlobal [_x, 1]; }; case 2 : { _containerRef addWeaponCargoGlobal [_x, 1]; }; }; }forEach _typeArray; }; }forEach [_items, _magazines, _weapons];; }forEach cArray; }]; player addAction ["player add Vest", {player addVest "V_Chestrig_blk"}]; player addAction ["player add Backpack", {player addBackpack "B_AssaultPack_blk"}]; player addAction ["player add Uniform", {player addUniform "U_B_CombatUniform_mcam"}]; Gives you several actions export crate refill crate empty crate player add Uniform player add Vaest player add BackPack Share this post Link to post Share on other sites
Undeceived 392 Posted August 26, 2014 Larrow, thank you so much!! I changed some things (and most likely made it more complicated than needed :) ), but it seems to work now as I need it to save everything in the weapon pool. THANKS! :) Share this post Link to post Share on other sites
Undeceived 392 Posted September 25, 2014 Larrow, can you help me once more with this? How can I remove the containers from the crate (or from the _containerArray) after retrieving their contents? I'm asking because there's that bug in the weapon pool system: http://forums.bistudio.com/showthread.php?182958-Weapon-Pool-duplicates-itself-in-campaign-progress-!-! It happens for items, mags and weapons, but also for vests, if they are in the crate. The result is that after approx. four missions I have about 30 vests in the weapon pool - which is quite annoying... :rolleyes: Thank you! Share this post Link to post Share on other sites