rimblock 0 Posted February 1, 2015 Hi, Coming from A2, the new A3 equipment options are vast can a little confusing. 1. Removing items. I am currently removing all default items from an new unit using the following commands. Are all of them needed or am I missing anything ?. removeAllAssignedItems _newUnit; removeGoggles _newUnit; removeHeadgear _newUnit; removeAllWeapons _newUnit; removeAllContainers _newUnit; 2. Adding items. The items I would like to add are currently in an arrays. Some items do not seem to be added correctly and I am not clear what I am doing wrong. Any pointers would be very welcome. Primary Weapon (none of the weapons adds are working so probably something fundamentally wrong with this method). Array(_charPrimaryWeapon): ["arifle_MX_ACO_pointer_F",["","acc_pointer_IR","optic_Aco"]] Code: if !((_charPrimaryWeapon select 0) isEqualTo "") then { diag_log format["[%1] Adding primary weapon (%2).",_scriptname, (_charPrimaryWeapon select 0)]; _newUnit addWeapon (_charPrimaryWeapon select 0); if ((count (_charPrimaryWeapon select 1)) > 0) then { { if !(_x isEqualTo "") then { diag_log format["[%1] Adding item to primary weapon (%2).",_scriptname, _x]; _newUnit addPrimaryWeaponItem _x; }; } count (_charPrimaryWeapon select 1); }; }else{ diag_log format["[%1] No primary weapon to add.",_scriptname]; }; Result: No weapon added. Assigned items Array (_charAssignedItems): ["ItemMap","ItemCompass","ItemWatch"] Code: if !((_charAssignedItems select 0) isEqualTo "") then { { diag_log format["[%1] Adding assigned item (%2).",_scriptname, _x]; _newUnit linkItem _x; } count _charAssignedItems; }; Result: No items added. items (added to uniform in this case) Array (_charUniform): ["U_IG_Guerilla1_1",["FirstAidKit","30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","Chemlight_green"],[""]] Code: if !(((_charUniform select 1)select 0) isEqualTo "") then { { diag_log format["[%1] Adding item to uniform (%2).",_scriptname, _x]; _newUnit addItemToUniform _x; } count (_charUniform select 1); }; Result: All items added but only one of the two mags added. For all of the above examples, the diaglog lines come out as I would expect if it had worked. 2:34:47 "[ds\addons\dominion_server\functions\playerLoad\fnc_s_assignloadout.sqf] Adding item to uniform (FirstAidKit)." 2:34:47 "[fnc_s_assignloadout.sqf] Adding item to uniform (30Rnd_65x39_caseless_mag)." 2:34:47 "[fnc_s_assignloadout.sqf] Adding item to uniform (30Rnd_65x39_caseless_mag)." 2:34:47 "[fnc_s_assignloadout.sqf] Adding item to uniform (Chemlight_green)." 2:34:47 "[fnc_s_assignloadout.sqf] Adding primary weapon (arifle_MX_ACO_pointer_F)." 2:34:47 "[fnc_s_assignloadout.sqf] Adding item to primary weapon (acc_pointer_IR)." 2:34:47 "[fnc_s_assignloadout.sqf] Adding item to primary weapon (optic_Aco)." 2:34:47 "[fnc_s_assignloadout.sqf] No secondary weapon to add." 2:34:47 "[fnc_s_assignloadout.sqf] Adding handgun (hgun_P07_F)." 2:34:47 "[fnc_s_assignloadout.sqf] Adding assigned item (ItemMap)." 2:34:47 "[fnc_s_assignloadout.sqf] Adding assigned item (ItemCompass)." 2:34:47 "[fnc_s_assignloadout.sqf] Adding assigned item (ItemWatch)." I can add hats and uniforms just fine but the other items are proving to be problematic. Share this post Link to post Share on other sites
das attorney 840 Posted February 1, 2015 You need to return true/false if you are fiddling around with count instead of forEach { if (blah blah) then { // array stuff }; true } count (_charPrimaryWeapon select 1) ; Share this post Link to post Share on other sites
Larrow 2155 Posted February 1, 2015 All works fine here RimBlock, testing your code from the debug console.. h = [] spawn { _newUnit = player; removeAllAssignedItems _newUnit; removeGoggles _newUnit; removeHeadgear _newUnit; removeAllWeapons _newUnit; removeAllContainers _newUnit; _charPrimaryWeapon = ["arifle_MX_ACO_pointer_F",["","acc_pointer_IR","optic_Aco"]]; if !((_charPrimaryWeapon select 0) isEqualTo "") then { _newUnit addWeaponGlobal (_charPrimaryWeapon select 0); if ((count (_charPrimaryWeapon select 1)) > 0) then { { if !(_x isEqualTo "") then { _newUnit addPrimaryWeaponItem _x; }; } count (_charPrimaryWeapon select 1); }; }; _charAssignedItems = ["ItemMap","ItemCompass","ItemWatch"]; if !((_charAssignedItems select 0) isEqualTo "") then { { _newUnit linkItem _x; } count _charAssignedItems; }; _charUniform = ["U_IG_Guerilla1_1",["FirstAidKit","30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","Chemlight_green"],[""]]; if !( _charUniform select 0 isEqualTo "" ) then { _newUnit forceAddUniform ( _charUniform select 0 ); }; if !(((_charUniform select 1)select 0) isEqualTo "") then { { _newUnit addItemToUniform _x; } count (_charUniform select 1); }; }; Couple of notes Primary Weapon (none of the weapons adds are working so probably something fundamentally wrong with this method).Array(_charPrimaryWeapon): ["arifle_MX_ACO_pointer_F",["","acc_pointer_IR","optic_Aco"]] Code: if !((_charPrimaryWeapon select 0) isEqualTo "") then { diag_log format["[%1] Adding primary weapon (%2).",_scriptname, (_charPrimaryWeapon select 0)]; _newUnit addWeapon (_charPrimaryWeapon select 0); if ((count (_charPrimaryWeapon select 1)) > 0) then { { if !(_x isEqualTo "") then { diag_log format["[%1] Adding item to primary weapon (%2).",_scriptname, _x]; _newUnit addPrimaryWeaponItem _x; }; } count (_charPrimaryWeapon select 1); }; }else{ diag_log format["[%1] No primary weapon to add.",_scriptname]; }; May want to use addWeaponGlobal.Does not cause any problems but you are adding a weapon that already has (via its config) attachments, "arifle_MX_ACO_pointer_F" already includes an ACO and a IR pointer. You need to return true/false if you are fiddling around with count instead of forEach I have never come across any problems in using count without returning true/false, unless of course you need the result. It still does all the code per iteration. Share this post Link to post Share on other sites
rimblock 0 Posted February 1, 2015 (edited) You need to return true/false if you are fiddling around with count instead of forEach Why is that ?. I have never set either true or false in count loops which I use fairly extensively for my Dayz Epoch mods. The wiki mentions condition: Code that must return true for the tested element to be counted. The variable _x will contain the currently tested element. I take this to mean if counting an array then the index must return an element (ie. does the next element exist - yes = true and count it, no = false and don't count it) for the element to be counted. All works fine here RimBlock, testing your code from the debug console..Couple of notes May want to use addWeaponGlobal. Does not cause any problems but you are adding a weapon that already has (via its config) attachments, "arifle_MX_ACO_pointer_F" already includes an ACO and a IR pointer. I have never come across any problems in using count without returning true/false, unless of course you need the result. It still does all the code per iteration. Thanks for double checking. It all seems to be working ok on the server but is incorrect when the unit becomes the player on the players client. Not using addWeaponGlobal may be the issue. The unit is created and equipped on the server then passed at a specific client. The player of that client is then moved in to the unit. I had presumed that the equipment would be passed with the unit to the client but if the loadout is not is not sent globally then maybe when added then the unit may be missing some stuff at the cleint as the items are not sync'd with what was added on the server. Sound reasonable ?. Update: Ok, checked out the command and it is forced rather than global to the network. Oh well. Edited February 1, 2015 by RimBlock Share this post Link to post Share on other sites
das attorney 840 Posted February 1, 2015 Ah ok, I normally just return something as a matter of course. Maybe it's time to do some testing so I can understand this better. I def have seen errors when no return found from tested expression, but plugging in {_x setDamage 0} count allUnits Is fine... Hmm, time to go off and do some testing to understand this. Apologies for cluttering up your question thread with this offtopic stuff. Share this post Link to post Share on other sites
rimblock 0 Posted February 1, 2015 (edited) NP, we are all here to learn, me more than most :). Back to the original question... I suspect the adding code is fine but the unit is getting moved from the server to the client before the items are correctly added to it in the loadout script (due to code execution speed). Basic flow is; Server... - Create unit - Assign loadout - unit setOwner players client - PVC the unit id to the client Client... - Swap player to the unit. Assign loadout order... Headgear (Helmet / HMD) Eyewear (Goggles, binoculars) Uniform Vest Backpack Uniform items Vest items Backpack items Primary Weapon SecondaryWeapon Handgun Assigned items Headgear and uniform are fine. No eyewear, vest or backpack to add. Uniform items are fine as it the primary weapon. Handgun is missing, all assigned items are missing. I am getting some of the following errors on both server and client. 20:33:53 Error: Object(3 : 9) not found20:34:50 Error: Object(3 : 12) not found 20:34:58 CWeaponSlotsManager::DeleteWeapon: wrong weaponID! 20:35:07 CWeaponSlotsManager::DeleteWeapon: wrong weaponID! The addweaponglobal is working fine for the primary weapon but the pistol is missing. All the assigned items are missing. I am also getting the following error in the client rpt after the diag lines telling me the scripts are complete (remember the code to add assigned items is run on the server). 20:31:25 Error in expression <en { { _newUnit linkItem _x; } count _charAssi>20:31:25 Error position: <linkItem _x; } count _charAssi> 20:31:25 Error Type Nothing, expected Bool I am going to put a loop in to check that the last assigned item is listed with assigneditems before exiting and maybe that will solve it. Edited February 1, 2015 by RimBlock Share this post Link to post Share on other sites
Larrow 2155 Posted February 1, 2015 A quick test piece seems to pass off dressed units ok. Share this post Link to post Share on other sites
das attorney 840 Posted February 1, 2015 Error in expression <en { { _newUnit linkItem _x; } count _charAssi>Error position: <linkItem _x; } count _charAssi> Error Type Nothing, expected Bool That's the error I was talking about! :D Can you try returning true on that loop and see if it errors out again? Share this post Link to post Share on other sites
Larrow 2155 Posted February 1, 2015 Hmm im not getting that error in either server or client rpt. Ive definatley seen what Das is talking about but only if im trying to compare the count afterwards and i have not supplied the iteration with true/false. Share this post Link to post Share on other sites
rimblock 0 Posted February 1, 2015 (edited) Ok, so I have tried two different ways of detecting whether the items have been added. First try; After adding the assigned items, checking for the last assigned item in the array using assignedItems to see if it is reported as being available on the unit. Result: No change. The assigned items are reported as being available on the unit on the server but when the unit is sent to the client for ownership the items are missing still. Just putting in a 1 sec uiSleep at the end of the loadout script. Result: Most of the items are available on the unit when it arrives at the client (have one mag missing out of two). My assumption based on this... AddXXXXXX basically queues up the action to add the items int he game engine and updates the record that lists what is added to the unit. AssignedItems takes its info from this unit record. The inventory GUI actually checks the items on the unit. If local commands are queued but the unit gets passed to another client before they execute then they get confused. The array containing the assignedItems to be added is only available on the server so if the unit is passed to the client before the addXXXXX queue ius cleared it cannot get the array with the items to add and thus provides that error in the client RPT file. The UISleep is giving time for the ADDXXXXX queues to clear. This is pure assumption based on testing. The problem is how long to wait. Surely it will take longer if more items need to be added. Update: So far I am down to a UISleep of 0.02 for all the items to be added (well give or take a single 7.62x51 mag added to the uniform for some reason). Edited February 1, 2015 by RimBlock Share this post Link to post Share on other sites
rimblock 0 Posted February 3, 2015 Well it seems it is pretty random. I had changed the uisleep to 0.02 a couple of nights ago and it was working fine. I spun it up last night and stuff was missing again. Changing the sleep length fixed it again but this random amount of time to sleep seems to be a bit too random for my liking. I do not seem to be able to test on the server to see if the items are added as it returns the items but when the player is put in to the unit the items are missing. This means I cannot waituntil etc. I also cannot get mags to appear in the inventory. If I add two primary gun mags and two handgun mags then when I get control of the unit it has 1 of each mag loaded in to the right weapons but no second mag in the inventory (there is space available). It is only mags as the first aid kit and chemlight is fine. I have tried checking isclass for mags and using addmagazine and addmagazineglobal but neither is fixing the problem of the missing mags. Any other ideas ?? Share this post Link to post Share on other sites
rimblock 0 Posted February 3, 2015 Ok, I have moved the assign items script to the client so it is now; Server - Create character - PVC character and loadout details. Client - Wait until owner character = owner player (character has moved to player client) - assign loadout. Same problem. I have changed count to foreach. Same problem. I have split up the loadout adding script to smaller scripts for equipment, items, weapons and assigned items. Same problem. Now here is the interesting thing.... In debug I ran player addMagazine "20Rnd_762x51_Mag";player addMagazine "20Rnd_762x51_Mag";player addMagazine "20Rnd_762x51_Mag"; Result: 1 mag added, not 3. Whilst I am aware that I can addmagazinearray I am trying to take the output from a 'player items' command and feed it in to a script to add those items so it is an array of individual items rather than classnames and quantity. Share this post Link to post Share on other sites