Undeceived 392 Posted October 1, 2014 Hello guys, can you help me with that... I have an array with many weapon strings, item strings, etc. I want to keep everything in that array, but REMOVE all items that are part of the classname category A3_Weapons_F_Vests. If you check this page, you will see that all vests are contained in this category. In short: How do I remove all vests from the array with one code line? Many thanks for your time! Share this post Link to post Share on other sites
dreadedentity 278 Posted October 1, 2014 subtraction [a, a, b, a, c, a, d, a, e, a] - [a] = [b, c, d, e] Share this post Link to post Share on other sites
das attorney 857 Posted October 1, 2014 Not a single line, but should still work: _badClass = [ "Vest_V_Rangemaster_belt", "Vest_V_BandollierB_khk", "Vest_V_BandollierB_cbr", "Vest_V_BandollierB_rgr", "Vest_V_BandollierB_blk", "Vest_V_PlateCarrier1_rgr", "Vest_V_PlateCarrier2_rgr", "Vest_V_PlateCarrier3_rgr", "Vest_V_PlateCarrierGL_rgr", "Vest_V_Chestrig_khk", "Vest_V_Chestrig_rgr", "Vest_V_Chestrig_blk", "Vest_V_TacVest_khk", "Vest_V_TacVest_brn", "Vest_V_TacVest_oli", "Vest_V_TacVest_blk", "Vest_V_HarnessO_brn", "Vest_V_HarnessOGL_brn", "Vest_V_RebreatherB", "Vest_V_RebreatherIR", "Vest_V_BandollierB_oli", "Vest_V_PlateCarrier1_blk", "Vest_V_PlateCarrierSpec_rgr", "Vest_V_Chestrig_oli", "Vest_V_TacVest_camo", "Vest_V_TacVest_blk_POLICE", "Vest_V_TacVestIR_blk", "Vest_V_TacVestCamo_khk", "Vest_V_HarnessO_gry", "Vest_V_HarnessOGL_gry", "Vest_V_HarnessOSpec_brn", "Vest_V_HarnessOSpec_gry", "Vest_V_PlateCarrierIA1_dgtl", "Vest_V_PlateCarrierIA2_dgtl", "Vest_V_PlateCarrierIAGL_dgtl", "Vest_V_RebreatherIA", "Weapon_V_PlateCarrier_Kerry", "Weapon_V_PlateCarrierL_CTRG", "Weapon_V_PlateCarrierH_CTRG" ]; { if (_x in _badClass) then { ARRAYTHATNEEDSSORTING set [_forEachIndex,666]; }; } forEach ARRAYTHATNEEDSSORTING; ARRAYTHATNEEDSSORTING = ARRAYTHATNEEDSSORTING - [666]; Share this post Link to post Share on other sites
jshock 512 Posted October 1, 2014 I was going to recommend going into the config, get all the classnames of vests, and then subtract that array from the overall item array (untested, and probably a few errors): _itemsArray = [blah]; _vestArray = getArray(configfile >> "cfgVehicles" >> A3_Weapons_F_Vests); _itemsArray = _itemsArray - _vestArray; I'm almost certain my config file call line is incorrect, but hopefully someone can alter that to make it correct, I'm speculating on how to get to the vests from the config without pulling up the config in-game :p. Share this post Link to post Share on other sites
das attorney 857 Posted October 1, 2014 (edited) I don't think it's a valid class. I couldn't find it in the browser at first so I checked with this: diag_log format ["%1", isClass (configFile / "CfgVehicles" / "A3_Weapons_F_Vests")]; Returns false. So then I wasn't sure if Undeceived needed the WH vests from CfgVehicles (parent is "Vest_Base_F")... or if he just wanted plain old CfgWeapons vests. So I posted that up knowing that either way, it should work. Edit: That's bollocks actually, it should only work for the WH CfgVehicles ones. In which case, you could do this: { if (_x isKindOf "Vest_Base_F") then { ARRAYTHATNEEDSSORTING set [_forEachIndex,666]; }; } forEach ARRAYTHATNEEDSSORTING; ARRAYTHATNEEDSSORTING = ARRAYTHATNEEDSSORTING - [666]; And I couldn't find any of the "Weapon_V_".... classes under CfgVehicles. Maybe my eyes are tired or wiki is not up to date. Edited October 1, 2014 by Das Attorney Share this post Link to post Share on other sites
jshock 512 Posted October 1, 2014 I don't think it's a valid class.Returns false. So then I wasn't sure if Undeceived needed the WH vests from CfgVehicles (parent is "Vest_Base_F")... or if he just wanted plain old CfgWeapons vests. So I posted that up knowing that either way, it should work. Yeah, I'm not 100% on pulling from the config, I'm just saying whatever the directory path is to the vests from CfgWeapons/Vehicles etc. Share this post Link to post Share on other sites
dreadedentity 278 Posted October 1, 2014 Basically...we need to know more about what you're trying to do. Share this post Link to post Share on other sites
iceman77 18 Posted October 1, 2014 (edited) ... In short: How do I remove all vests from the array with one code line? ... Untested. deleteAT command may only be available on dev branch atm? _itemArray = ["arifle_MXC_Holo_pointer_F","V_PlateCarrier2_rgr","B_Kitbag_rgr_Exp"]; for "_i" from 0 to (count _itemArray) - 1 do { if (getText (configfile >> "CfgWeapons" >> _itemArray select _i >> "ItemInfo" >> "_generalMacro") == "VestItem") then { _itemArray deleteAt _i; }; }; ---------- Post added at 12:05 ---------- Previous post was at 11:52 ---------- Until deleteAT command becomes available for stable: _itemArray = ["arifle_MXC_Holo_pointer_F","V_PlateCarrier2_rgr","B_Kitbag_rgr_Exp"]; for "_i" from 0 to (count _itemArray) - 1 do { if (getText (configfile >> "CfgWeapons" >> _itemArray select _i >> "ItemInfo" >> "_generalMacro") == "VestItem") then { //_itemArray deleteAt _i; _itemArray = _itemArray - [(_itemArray select _i)]; }; }; ---------- Post added at 12:16 ---------- Previous post was at 12:05 ---------- CfgVehicles version... I've been away for a while and IDK wtf is up with vests being in cfgweapons (above). Or why the vest's in cfgVehicles now start with Vest_ . . . _itemArray = ["arifle_MXC_Holo_pointer_F","Vest_V_PlateCarrier2_rgr","B_Kitbag_rgr_Exp"]; for "_i" from 0 to (count _itemArray) - 1 do { if (getText (configfile >> "CfgVehicles" >> _itemArray select _i >> "vehicleClass") == "ItemsVests") then { //_itemArray deleteAt _i; _itemArray = _itemArray - [(_itemArray select _i)]; }; }; Edited October 1, 2014 by Iceman77 Share this post Link to post Share on other sites
killzone_kid 1326 Posted October 1, 2014 I was going to recommend going into the config, get all the classnames of vests, and then subtract that array from the overall item array (untested, and probably a few errors): _itemsArray = [blah]; _vestArray = getArray(configfile >> "cfgVehicles" >> A3_Weapons_F_Vests); _itemsArray = _itemsArray - _vestArray; I'm almost certain my config file call line is incorrect, but hopefully someone can alter that to make it correct, I'm speculating on how to get to the vests from the config without pulling up the config in-game :p. [url="http://killzonekid.com/sqf-to-bbcode-converter/"][color="#FF8040"][color="#1874CD"]_vestArray[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]getArray[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#191970"][b]configFile[/b][/color] [color="#8B3E2F"][b]>[/b][/color][color="#8B3E2F"][b]>[/b][/color] [color="#7A7A7A"]"CfgPatches"[/color] [color="#8B3E2F"][b]>[/b][/color][color="#8B3E2F"][b]>[/b][/color] [color="#7A7A7A"]"A3_Weapons_F_Vests"[/color] [color="#8B3E2F"][b]>[/b][/color][color="#8B3E2F"][b]>[/b][/color] [color="#7A7A7A"]"units"[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color][/color][/url] The problem here is that these are A3 default vests, you need to manually include modded custom vests if there are any. Share this post Link to post Share on other sites
Undeceived 392 Posted October 3, 2014 (edited) Thanks a lot, guys! I didn't expect that many replies! :) wtf is up with vests being in cfgweapons (above). Or why the vest's in cfgVehicles now start with Vest_ . . . Yeah, it really is the case that in my array there are not the Vest_V_ vests, but just only the V_ vests. So I tried to go with the second suggestion and it works too, but still returns this error: Error Zero divisor This is the code I used (basically your suggestion, but only with a bigger _itemArray with more vests) with the location of the error marked as [xxx] (in the fourth line): _itemArray = ["V_BandollierB_cbr","V_Chestrig_khk","arifle_MXC_Holo_pointer_F","V_PlateCarrier2_rgr","B_Kitbag_rgr_Exp","FirstAidKit","V_Chestrig_khk","FirstAidKit"]; for "_i" from 0 to (count _itemArray) - 1 do { if (getText (configfile >> "CfgWeapons" >> _itemArray [xxx]select _i >> "ItemInfo" >> "_generalMacro") == "VestItem") then { _itemArray = _itemArray - [(_itemArray select _i)]; }; }; hint str (_itemArray); //["arifle_MXC_Holo_pointer_F","B_Kitbag_rgr_Exp","FirstAidKit","FirstAidKit"]; EDIT: The strange thing here is: When I use your array, Iceman, (which has only 1 vest in it), the error doesn't appear. As soon as I add one or more vests to it, it comes. EDIT 2: Something else that really is strange: When I have a bunch of vests in the array (e.g. see my array below), the script doesn't work reliable. One vest will still remain in the array. Funnily, if I then launch the loop once again, it cleans the array as it should from the vests. :D My example (note that the array is not cleaned perfectly after the first loop - the "V_Chestrig_khk" remains in it): POOL_ITEMS = ["V_BandollierB_oli","FirstAidKit","FirstAidKit","FirstAidKit","FirstAidKit","V_BandollierB_oli","V_PlateCarrier2_rgr","V_BandollierB_oli","V_Chestrig_khk","V_PlateCarrier1_blk","V_PlateCarrier2_rgr"]; for "_i" from 0 to (count POOL_ITEMS) - 1 do { if (getText (configfile >> "CfgWeapons" >> POOL_ITEMS select _i >> "ItemInfo" >> "_generalMacro") == "VestItem") then { POOL_ITEMS = POOL_ITEMS - [(POOL_ITEMS select _i)]; }; }; hint str (POOL_ITEMS); //["FirstAidKit","FirstAidKit","FirstAidKit","FirstAidKit","V_Chestrig_khk"]; //Applying the loop once again, finally cleans the array from vests: for "_i" from 0 to (count POOL_ITEMS) - 1 do { if (getText (configfile >> "CfgWeapons" >> POOL_ITEMS select _i >> "ItemInfo" >> "_generalMacro") == "VestItem") then { POOL_ITEMS = POOL_ITEMS - [(POOL_ITEMS select _i)]; }; }; hint str (POOL_ITEMS); //["FirstAidKit","FirstAidKit","FirstAidKit","FirstAidKit"]; Is this a bug or did the loop not repeat often enough? ---------- Post added at 13:13 ---------- Previous post was at 11:52 ---------- EDIT 3: DasAttorney's method in his first post worked too. Thanks, mate! Edited October 3, 2014 by Undeceived Share this post Link to post Share on other sites
iceman77 18 Posted October 3, 2014 (edited) Fuck the Cfg, lets try different and simpler approach. private ["_itemArray","_type"]; _itemArray = ["V_BandollierB_oli","FirstAidKit","FirstAidKit","FirstAidKit","V_BandollierB_oli","V_PlateCarrier2_rgr","V_Chestrig_khk","V_PlateCarrier1_blk","V_PlateCarrier2_rgr"]; { _type = [_x] call BIS_fnc_itemType; if ((_type select 1) == "Vest") then { _itemArray = _itemArray - [_x]; }; } forEach _itemArray; hint str (_itemArray); Or /* Description: Item Type Array Filter Parameters: 1: <Array> - Array of item strings 2: <String> - Item type String 3: <Boolean> (optional) - Debug Example: _Array = ["V_BandollierB_oli","FirstAidKit","arifle_MXC_Holo_pointer_F"]; _string = "Vest"; [_Array, _string, true] call ICE_fnc_itemArrayFilter; */ private ["_itemArray","_type","_debug","_typeArray"]; _itemArray = [_this, 0, [], [[]]] call BIS_fnc_param; _type = [_this, 1, "", [""]] call BIS_fnc_param; _debug = [_this, 2, false, [true,false]] call BIS_fnc_param; { _typeArray = [_x] call BIS_fnc_itemType; if ((_typeArray select 1) == _type) then { _itemArray = _itemArray - [_x]; }; } forEach _itemArray; if (_debug) then { player sideChat str (_itemArray); diag_log str (_itemArray); }; Edited October 4, 2014 by Iceman77 Share this post Link to post Share on other sites
dreadedentity 278 Posted October 3, 2014 (edited) Why do you guys always want to do things the hard way? Using the code KK posted... _vestArray = getArray (configFile >> "CfgPatches" >> "A3_Weapons_F_Vests" >> "units"); { _itemArray = _itemArray - [_x]; //replace _itemArray with whatever your array is called }forEach _vestArray; You guys want to iterate through the item array itself, replace the matches, then delete the matches all at once. Since that doesn't preserve the index of the matches, what's the point? This code gets the list of vests from CfgPatches, then iterates through that, removing all matches from the input array. Edited October 3, 2014 by DreadedEntity Share this post Link to post Share on other sites
iceman77 18 Posted October 3, 2014 (edited) Why do you guys always want to do things the hard way? Using the code KK posted... _vestArray = getArray (configFile >> "CfgPatches" >> "A3_Weapons_F_Vests" >> "units"); { _itemArray = _itemArray - [_x]; //replace _itemArray with whatever your array is called }forEach _vestArray; You guys want to iterate through the item array itself, replace the matches, then delete the matches all at once. Since that doesn't preserve the index of the matches, what's the point? This code gets the list of vests from CfgPatches, then iterates through that, removing all matches from the input array. That would only fetch / remove arma3 vests. What if you were using addons? I think that's why KK posted that in reply to JShock =). Why not iterate through the pre-defined array (which could contain addons), check if the selection is a vest or not, and then delete it if it is? I mean... just to be safe, so the function could be used with addons. The problem here is that these are A3 default vests, you need to manually include modded custom vests if there are any. Edited October 3, 2014 by Iceman77 Share this post Link to post Share on other sites
jshock 512 Posted October 3, 2014 With the way my redressing script works for the weapons and magazines is that the mods use the same path for the weapons to the magazines those particular weapons use. So I was thinking it wouldn't be any different for the vests. Share this post Link to post Share on other sites
dreadedentity 278 Posted October 3, 2014 Why not both? Use what I posted than iterate afterwards what you posted to clean up addOn vests. It should run a little faster _vestArray = getArray (configFile >> "CfgPatches" >> "A3_Weapons_F_Vests" >> "units"); { _itemArray = _itemArray - [_x]; }forEach _vestArray; { if (([_x] call BIS_fnc_itemType) select 1 == "Vest") then { _itemArray = _itemArray - [_x]; }; }forEach _itemArray; Share this post Link to post Share on other sites
iceman77 18 Posted October 3, 2014 With the way my redressing script works for the weapons and magazines is that the mods use the same path for the weapons to the magazines those particular weapons use. So I was thinking it wouldn't be any different for the vests. Well, I can only go by what I see =). ie; KK's post about default vests. Share this post Link to post Share on other sites
Jigsor 175 Posted October 3, 2014 I don't know if this would help, but I got Iceman's code to remove satchels from an ammo crate wich are actually magazines in the array _all_mags Like this: remove_charge_fnc = { private ["_crate","_all_mags","_type"]; _crate = _this select 0; _all_mags = magazineCargo _crate; { _type = [_x] call BIS_fnc_itemType; if ((_type select 1) == "mine") then { _all_mags = _all_mags - [_x]; }; } forEach _all_mags; clearMagazineCargoGlobal _crate; {_crate addMagazineCargoGlobal [_x, 1];} foreach _all_mags; //hint str (_all_mags); }; and calling function like this: [_ammocache] call remove_charge_fnc; after crate was created with _ammocache = createVehicle [_objtype , _pos, [], 0, "None"]; Share this post Link to post Share on other sites