meatball 25 Posted March 10, 2014 I've written up a script that goes through and pulls random items from a players inventory. The script is working, but it's throwing a bunch of "Error Zero divisor" errors in the rpt. Here's an example block of code: if ((count vestitems player) > 0) then { for "_i" from 0 to (count vestitems player) do {_randLost = random 5; if (_randLost >= 3) then { if (isClass(configFile >> "CfgMagazines")) then { player removeMagazine ((vestitems player) select _i); } else { if (isClass(configFile >> "CfgWeapons")) then { player removeweapon ((vestitems player) select _i); } else { player removeitem ((vestitems player) select _i); }; }; }; }; }; And then in the rpt I see a whole lot of these: Error in expression <ayer removeMagazine ((vestitems player) select _i); } else { if (isClass(configF> Error position: <select _i); } else { if (isClass(configF> Error Zero divisor Like I said, the script does work correctly, I'd just like to figure out why it's tossing all those errors into the report and see if I can make the script cleaner. Share this post Link to post Share on other sites
Grumpy Old Man 3511 Posted March 10, 2014 probably the usual -1 error for arrays? try (count vestitems player -1) since the first index of an array is 0 this could be the cause. Share this post Link to post Share on other sites
das attorney 854 Posted March 10, 2014 That should be pretty much it (accessing elements that don't exist). Share this post Link to post Share on other sites
na_palm 19 Posted March 10, 2014 would this not always return TRUE: if (isClass(configFile >> "CfgMagazines")) then { so the else branch is never reached? I would think there needs to be a conditional to the vestitem in question... possibly with typeOf or inheritsFrom Share this post Link to post Share on other sites
das attorney 854 Posted March 10, 2014 The item could be "ItemCompass" for example which is in "CfgWeapons", so I can see why Meatball is querying which config it is defined in. Share this post Link to post Share on other sites
na_palm 19 Posted March 10, 2014 thats clear and wasn't my question -> isClass(configFile >> "CfgMagazines") always returns true as "CfgMagazines" is an class under configFile Share this post Link to post Share on other sites
das attorney 854 Posted March 10, 2014 (edited) Oh right like: if (isClass(configFile >> "CfgMagazines" >> ((vestitems player) select _i))) then { Missed that first time round EDIT: Well spotted! Edited March 10, 2014 by Das Attorney Share this post Link to post Share on other sites
meatball 25 Posted March 10, 2014 Ah...I see. I think that's close, but I'm still seeing an zero divisor error on the first isClass check line in this updated one: if ((count vestitems player) > 0) then { for "_i" from 0 to (count vestitems player - 1) do {_randLost = random 5; if (_randLost >= 3) then { if (isClass(configFile >> "CfgMagazines" >> ((vestitems player) select _i))) then { player removeMagazine ((vestitems player) select _i); } else { if (isClass(configFile >> "CfgWeapons" >> ((vestitems player) select _i))) then { player removeweapon ((vestitems player) select _i); } else { player removeitem ((vestitems player) select _i); }; }; }; }; }; ---------- Post added at 17:24 ---------- Previous post was at 17:17 ---------- I think I might have an idea of what's happening though... Let's say there's 5 items in the array. So it'll loop through the if block 5 times. Say the second item gets dropped, now the array only has 4 items, by the time the loop gets up to the fifth go around (_i = 4), that array item is gone. Share this post Link to post Share on other sites
na_palm 19 Posted March 10, 2014 (edited) could you copy/paste the error from the log, couldn't see what should be wrong ---------- Post added at 18:34 ---------- Previous post was at 18:27 ---------- _delList = []; for "_i" from 0 to (count vestitems player - 1) do { _randLost = random 5; if (_randLost >= 3) then { _delList set [count _delList, ((vestitems player) select _i)]; }; }; { if (isClass(configFile >> "CfgMagazines" >> _x)) then { player removeMagazine _x; } else { if (isClass(configFile >> "CfgWeapons" >> _x)) then { player removeweapon _x; } else { player removeitem _x; }; }; }forEach _delList; this should work then Edited March 10, 2014 by Na_Palm Share this post Link to post Share on other sites
meatball 25 Posted March 10, 2014 Just this over and over again... Error in expression < >> "CfgMagazines" >> (vestitems player select _i))) then { player removeMagazin> Error position: <select _i))) then { player removeMagazin> Error Zero divisor File C:\Users\mb\Documents\Arma 3 - Other Profiles\Meatball\mpmissions\[Co-08]_Babel.clafghan\miscScripts\loseGear.sqf, line 52 Error in expression < >> "CfgMagazines" >> (vestitems player select _i))) then { player removeMagazin> Error position: <select _i))) then { player removeMagazin> Error Zero divisor File C:\Users\mb\Documents\Arma 3 - Other Profiles\Meatball\mpmissions\[Co-08]_Babel.clafghan\miscScripts\loseGear.sqf, line 52 Error in expression <> "CfgMagazines" >> ((vestitems player) select _i))) then { player removeMagazin> Error position: <select _i))) then { player removeMagazin> Error Zero divisor File C:\Users\mb\Documents\Arma 3 - Other Profiles\Meatball\mpmissions\[Co-08]_Babel.clafghan\miscScripts\loseGear.sqf, line 52 Error in expression <> "CfgMagazines" >> ((vestitems player) select _i))) then { player removeMagazin> Error position: <select _i))) then { player removeMagazin> Error Zero divisor ---------- Post added at 17:43 ---------- Previous post was at 17:34 ---------- Well, there you go, thanks guys! That cleared up all the errors. Here's the 'final' script. // Lose Random Items Script v 0.2 // By Meatball // Coding Insight from Na_Palm, Grumpy Old Man & Das Attorney private ["_delListU","_delListB","_delListV","_randWpn","_randLost"]; _randWpn = floor (random 3); if (_randWpn == 0) then { if (primaryweapon player != "") then { player unassignItem (primaryweapon player); player removeWeapon (primaryweapon player); }; } else { if (_randWpn == 1) then { if (secondaryweapon player != "") then { player unassignItem (secondaryweapon player); player removeWeapon (secondaryweapon player); }; player removePrimaryWeaponItem "optic_Arco"; player removePrimaryWeaponItem "optic_ACO_grn"; } else { if (handgunweapon player != "") then { player unassignItem (handgunweapon player); player removeWeapon (handgunweapon player); }; player removePrimaryWeaponItem "optic_Arco"; player removePrimaryWeaponItem "optic_ACO_grn"; }; }; _delListU = []; for "_i" from 0 to (count uniformitems player - 1) do {_randLost = random 5; if (_randLost >= 3) then { _delListU set [count _delListU, ((uniformitems player) select _i)]; }; }; { if (isClass(configFile >> "CfgMagazines" >> _x)) then { player removeMagazine _x; } else { if (isClass(configFile >> "CfgWeapons" >> _x)) then { player removeweapon _x; } else { player removeitem _x; }; }; }forEach _delListU; _delListV = []; for "_i" from 0 to (count vestitems player - 1) do {_randLost = random 5; if (_randLost >= 3) then { _delListV set [count _delListV, ((vestitems player) select _i)]; }; }; { if (isClass(configFile >> "CfgMagazines" >> _x)) then { player removeMagazine _x; } else { if (isClass(configFile >> "CfgWeapons" >> _x)) then { player removeweapon _x; } else { player removeitem _x; }; }; }forEach _delListV; _delListB = []; for "_i" from 0 to (count backpackitems player - 1) do {_randLost = random 5; if (_randLost >= 3) then { _delListB set [count _delListB, ((backpackitems player) select _i)]; }; }; { if (isClass(configFile >> "CfgMagazines" >> _x)) then { player removeMagazine _x; } else { if (isClass(configFile >> "CfgWeapons" >> _x)) then { player removeweapon _x; } else { player removeitem _x; }; }; }forEach _delListB; Share this post Link to post Share on other sites
das attorney 854 Posted March 11, 2014 Good man posting up your results - glad to see you got it sorted :) Share this post Link to post Share on other sites
meatball 25 Posted March 13, 2014 Alright, so I've run up into a bit of a weird issue with a related script. So, basically what I'm doing is the players get on an AI chopper, it gets shot down and they get tossed out, losing some gear (the script above). The rest of the script I wrote swaps out their backpack for a chute, then on landing swaps the chute back for their backpack. The problem is that it seems to work fine, unless...the player role starts with a default gear loadout in their pack. If that player pulls out any (or all) of the default backpack gear and sticks other stuff in, they'll end up on the ground not only with some of the new gear they put back in, but _all_ of the gear from the original loadout. I've tried a bunch of different commands, but can't seem to get anything to work. Anyone have any thoughts on the following script? // Run loseGear script loseGear = execVM "miscScripts\loseGear.sqf"; waitUntil {scriptDone loseGear}; // Throw the player out of the chopper. moveout player; _gear = []; _backpack = backpack player; _backpack2 = unitbackpack player; _backpack_items = getItemCargo (unitBackpack player); _backpack_weap = getWeaponCargo (unitBackpack player); _backpack_mags = getMagazineCargo (unitBackpack player); _gear = [_backpack_items,_backpack_weap,_backpack_mags]; // Remove Backpack & add steerable chute 3 fadeSound 0.15; removeBackpack player; sleep 1.5; player addBackpack "B_Parachute"; deleteVehicle _backpack2; waitUntil {isTouchingGround player}; // Take off parachute removeBackpack player; // Replace backpack and contents. if (_backpack == "") exitWith{}; player addbackpack _backpack; // Add items back into backpack from _gear array if (count ((_gear select 1) select 0) > 0) then { for "_i" from 0 to (count ((_gear select 1) select 0) - 1) do { (unitBackpack player) addweaponCargoGlobal [((_gear select 1) select 0) select _i,((_gear select 1) select 1) select _i]; }; }; if (count ((_gear select 2) select 0) > 0) then { for "_i" from 0 to (count ((_gear select 2) select 0) - 1) do { (unitBackpack player) addMagazineCargoGlobal [((_gear select 2) select 0) select _i,((_gear select 2) select 1) select _i]; }; }; if (count ((_gear select 0) select 0) > 0) then { for "_i" from 0 to (count ((_gear select 0) select 0) - 1) do { (unitBackpack player) addItemCargoGlobal [((_gear select 0) select 0) select _i,((_gear select 0) select 1) select _i]; }; }; Share this post Link to post Share on other sites
na_palm 19 Posted March 13, 2014 oh these backpack issues... i know your trouble. this one works for me: player addbackpack _backpack; waitUntil {(backpack player) == _backpack}; clearWeaponCargoGlobal (backpackContainer player); clearMagazineCargoGlobal (backpackContainer player); clearItemCargoGlobal (backpackContainer player); greetings Na_Palm Share this post Link to post Share on other sites
meatball 25 Posted March 13, 2014 Well hot diggety, adding that in did the trick. Thanks a ton Na_Palm! I swear, something I just scratch my head at what works and what doesn't :) Share this post Link to post Share on other sites
na_palm 19 Posted March 13, 2014 yeah the new commands are a heaven send, or so! Share this post Link to post Share on other sites