aeroson 8 Posted March 8, 2013 (edited) These scripts don't work anymore. BI recently added getUnitLoadout and setUnitLoadout, use those. 2016-05-12, I wholeheartedly thank and tip my imaginary fedora to the amazing employee who did this for us, BI needs more of your kind. Thank you good sire. If you are using ACE3 you can use ACE_common_fnc_getAllGear and ACE_common_fnc_setAllGear Sorry. Support for this has been discontinued. Though I will gladly accept any pull requests on github.Summary / infoI guarantee backwards compatibility.These scripts allows you set/get (load/save)all of the unit's gear, including:uniform, vest, backpack, contents of it, all quiped items, all three weapons with their attachments, currently loaded magazines and number of ammo in magazines.All this while preserving order of items.Useful for saving/loading loadouts.Ideal for revive scripts where you have to set exactly the same loadout to newly created unit.Uses workaround with placeholders to add vest/backpack items, so items stay where you put them.Why should i use it ?Well i was sceptical at first as well, i was like hell i don't need to use 200 lines script if i can just write it with 20 lines. That's basically how i started. After days of testing and debuging i found out that Arma 3 is not perfect. And to make the loadout set/get functions work as expected i had to figure out many workarounds and spend much more time on this than i would expect. In the end it turns out to be this big but it does also works perfectly and exactly how you would expect it to work. If you are interested in the workarounds scroll to the bottom of this post. Also if you decide not to use this, i will most likely come to your thread and tell you all the bugs your loadout saving/loading code has (which you could have avoided by using this), by now i can tell it only by looking at the code.License, legal stuffYou are free to use GET/SET Loadout scripts for whatever you wish to, including any kind of contests. Though it would be nice of you to put my name into credits.UsageJust an explanation on how it works. waitUntil { !isNull player }; // Wait for player to initialize // Saves loadout of player into var loadout loadout=[player] call compile preprocessFileLineNumbers 'get_loadout.sqf'; // Sets player's loadout from var loadout 0=[player,loadout] execVM 'set_loadout.sqf'; Here an example of usage within map's init.sqf, it does save loadout upon map's init and then loads it after respawn, you can also save/load loadout at every ammobox. waitUntil { !isNull player }; // Wait for player to initialize // Compile scripts getLoadout = compile preprocessFileLineNumbers 'get_loadout.sqf'; setLoadout = compile preprocessFileLineNumbers 'set_loadout.sqf'; // Lets wait 10 seconds, hopefully all crates will spawn by then sleep 10; // Save default loadout loadout = [player] call getLoadout; // Add save/load loadout actions to all ammo boxes { _x addAction ["<t color='#ff1111'>Save loadout</t>", "get_loadout.sqf"]; _x addAction ["<t color='#00cc00'>Load loadout</t>", "set_loadout.sqf"]; } forEach nearestObjects [getpos player,["ReammoBox","ReammoBox_F"],15000]; // Load saved loadout on respawn player addEventHandler ["Respawn", { [player,loadout] spawn setLoadout; } ]; Another example of map's init.sqf, this one will make you respawn with same gear, you had when you died. waitUntil { !isNull player }; // Wait for player to initialize // Compile scripts getLoadout = compile preprocessFileLineNumbers 'get_loadout.sqf'; setLoadout = compile preprocessFileLineNumbers 'set_loadout.sqf'; // Save loadout every 2 seconds [] spawn { while{true} do { if(alive player) then { loadout = [player,["repetitive"]] call getLoadout; }; sleep 2; }; }; // Load saved loadout on respawn player addEventHandler ["Respawn", { [player,loadout] spawn setLoadout; } ]; A slight edit of previous code, this one will save your magazines ammo count as well. waitUntil { !isNull player }; // Wait for player to initialize // Compile scripts getLoadout = compile preprocessFileLineNumbers 'get_loadout.sqf'; setLoadout = compile preprocessFileLineNumbers 'set_loadout.sqf'; // Save loadout (including ammo count) every 2 seconds [] spawn { while{true} do { if(alive player) then { loadout = [player,["ammo","repetitive"]] call getLoadout; }; sleep 2; }; }; // Load saved loadout (including ammo count) on respawn player addEventHandler ["Respawn", { [player,loadout,["ammo"]] spawn setLoadout; } ]; ParametersYou can find this inside each script as well.get_loadout.sqf0 : target unit1 : (optional) array of options, default [] :"ammo" will save ammo count of partially emptied magazines"repetitive" intended for repetitive use, will not use selectWeapon, means no visible effect on solder, but will not save magazines of assigned items such as laser designator batteriesset_loadout.sqf0 : target unit1 : array of strings/arrays containing desired target unit's loadout, obtained from get_loadout.sqf2 : (optional) array of options, default [] : ["ammo"] will allow loading of partially emptied magazines, otherwise magazines will be fullFixes / HelpFor those struggling with file hierarchyNotice the description.ext file, you need that if you want respawn. Check out wiki for how-to. community.bistudio.com/wiki/Description.extIf your loadout is loaded but you can not use grenades try this // Load saved loadout on respawn player addEventHandler ["Respawn", { [] spawn { sleep 1; // If it still doest not work add more sleep D: [player,loadout] call setLoadout; }; } ]; You can tinker with profileNamespace for persistent loadouts // Saves var loadout into profileNamespace, which is persistent profileNamespace setVariable ["loadout",loadout]; // Loads loadout from profileNamespace into var loadout loadout=profileNamespace getVariable "loadout"; Loadout managerA simple scroll wheel based loadout manager.Uses profileNamespace so all loadouts are saved permanently into your profile.You can load all previously saved loadouts in VAS (both new and old)Offer loadout is WIP.Requires compiled set/get functions (usually in the mission's init.sqf) getLoadout = compile preprocessFileLineNumbers 'get_loadout.sqf'; setLoadout = compile preprocessFileLineNumbers 'set_loadout.sqf'; http://i.imgur.com/XlDqn8g.png (304 kB)Put this into init line of object you wish to be loadout manager 0 = [this] execVM 'loadout_manager.sqf'; Downloaddownload get_loadout.sqfdownload set_loadout.sqfdownload loadout_manager.sqfdownload example mission (not updated)Changelogget_loadout.sqf v3.4- Added: "repetitve" option flag, will not use selectWeapon, means no visible effect on solder, but will not save magazines of assigned items such as laser designator batteries- Added: weapons magazines are now saved using the new magazinesAmmoFull commandv3.3- Fixed: assigned items magazines are saved only if you can select itv3.2- Added: Saving magazines of assignedItems (laser designator)v3.1- Fixed: Error when trying to add empty googles or headgear (sms)v3.0- Fixed: In dev branch, goggles and headgear are no longer part of assignedItemsv2.9- Fixed: Backpacks in backpack are now savedv2.8- Minor fixesv2.7- Added: Option to save magazines ammo count- Fixed: Gunlight is turned on againv2.6- Fixed: currentMuzzle returns 0 if your are passenger in some vehicles, this caused the script to crash on string comparison (you can't compare integer and string)v2.5- Minor fixesv2.4- Added: Saves currently selected firing modev2.3- Edit: No need for it anymore Added: Saving currently loaded magazines is now optional, you can disable it. Good if you want to respawn with same loadout, so it doesn't reset your firing mode every 2 seconds.v2.2- Added: Saves currently loaded magazines, and currently selected weapon/muzzlev2.1- Added private statement to prevent inconsistencies set_loadout.sqf v4.3- Added: now using addItemTo commands- Fixed: assigned binocular/laser designator is now properly addedv4.2- Fixed: Goggles and headgear are now removed before adding assigned itemsv4.1- Better vest/uniform placeholder filling (madbull)v4.0- Added: Loading magazines of assignedItems (laser designator)- Fixed: Launchers ammo should not disappear anymore (Moridou62)v3.9- Removed: pointless use of removeItemFromPrimaryWeaponv3.8- Minor fixesv3.7- Added: Option to load magazines ammo countv3.6- Minor fixesv3.5- Added: Loads saved firing mode.v3.4- Added: Loads saved loaded magazines and selects saved selected weapon/muzzle, backwards compatiblev3.3- Fixed: Magazine for MXM ends with Mag but once you check for it in magazines player it ends with mag, this caused the script to waitUntil forever >_<v3.2- Fixed: Both weapons and glasses are now added to backpack- Various tweaks and code cleanup by Nimrodv3.1- Added placeholder solution for vest as well, glasses are now properly added to backpackv3.0- Added waitUntils for uniform, vest and backpack, to make sure we have them before adding itemsv2.9- Added private statement to prevent inconsistenciesv2.8- Removed micro sleeps and added waitUntils for magazines, to make sure that weapon's are added loaded under any circumstancesv2.7- Fixed: Improved item type check, now it does properly recognize Binocular as weaponv2.6- Added: Now adds one magazine for each muzzle (UGL comes loaded)v2.5- Added: Micro sleep to fix spawn in underwear issues (thanks to sxp2high)v2.4- Added: Better item type check- Fixed: Handgun attachments are now addedv2.3- Fixed: Backpack items adding is now functional- Added: You will switch to weapons if they do exists in following order: primary weapon, handgun, secondary weapon (launchers)- Fixed: Default primary/secondary weapons are now removed even if you don't have them in loadout- Fixed: No more error messages, due to non existing attachments loadout_manager.sqf v1.4- Removed: Old VAS from VAS loadout selectionv1.1- Added: You can now load VAS saved loadouts both new and oldv1- Initial release Creditseggbeast and his Evolution for extensive testing and feedbackNimrod and sxp2high for code edit and ideasFoxhound for constantly updating this on armaholicTonic's VAS for ideasSMS for reporting issueand of course everyone who participated anyhowProblems and factsI made _add function that checks cfg attributes and classes to select correct add command, this allowed me use uniformItems, vestItems and backpackItems commands. No need to save magazines and items separately. _add = { private ["_target","_item"]; _target = _this select 0; _item = _this select 1; if(isClass(configFile>>"CfgMagazines">>_item)) then { _target addMagazine _item; } else { if(isClass(configFile>>"CfgWeapons">>_item>>"WeaponSlotsInfo") && getNumber(configFile>>"CfgWeapons">>_item>>"showempty")==1) then { _target addWeapon _item; } else { _target addItem _item; }; }; }; There is no unitVest, so to add something to vest you have to keep adding small placeholders while {loadUniform _target < 1} do { _target addItem "itemWatch"; }; add stuff to vest here.For backpack there is unitBackpack, but apparently you can not add every item with addItemCargo (such as glasses, can be added into inventory with addItem), so i use the placeholder solution for backpack as well.Yet i still use the command addWeaponCargo because addWeapon will add the weapon into hands. _add = { private ["_target","_item"]; _target = _this select 0; _item = _this select 1; if(isClass(configFile>>"CfgMagazines">>_item)) then { unitBackpack _target addMagazineCargo [_item,1]; } else { if(getNumber(configFile>>"CfgVehicles">>_item>>"isbackpack")==1) then { unitBackpack _target addBackpackCargo [_item,1]; } else { if(isClass(configFile>>"CfgWeapons">>_item>>"WeaponSlotsInfo") && getNumber(configFile>>"CfgWeapons">>_item>>"showempty")==1) then { unitBackpack _target addWeaponCargo [_item,1]; } else { _target addItem _item; }; }; }; }; You can retreive currently loaded magazines by using selectWeapon and currentMagazine, just be sure to selectWeapon each muzzle on the primary weapon, to get currently loaded GL as well. (from Tonic's VAS)You can use new command clearAllItemsFromBackpack. (Nimrod)First magazine from config for MXM (maybe some other weapons too) ends with Mag, you can add it, but in magazines player it ends with mag (small case m). Use toLower it if you are doing some string comparison.If you are seeing someone holding and firing invisible weapon. Do selectWeapon, that seems to fix it.Backpackitems do not contain backpacks, you need to use backpackcargo to get backpacks within backpack ( ). But those backpacks are empty, you can't make infinite recursive backpack D:Willing to participate ? github.com/aeroson/a3-loadout Edited May 13, 2016 by aeroson lel 1 Share this post Link to post Share on other sites
fedator 0 Posted March 8, 2013 very helpful, thanks Share this post Link to post Share on other sites
aeroson 8 Posted March 8, 2013 I'm glad it came in handy. Updated it, now you can use it in addAction. Share this post Link to post Share on other sites
pridit 10 Posted March 9, 2013 Doesn't seem to include all box types, in particular [bLUE] Supply box. I would try and include it myself but I have no idea what the name of that particular box type is. Share this post Link to post Share on other sites
aeroson 8 Posted March 9, 2013 (edited) Thank you. Updated the init.sqf code, changed the classnames to ["ReammoBox","ReammoBox_F"], tested and works for all/13 ammo boxes. Also check out this module, it might suit your needs better. Riouken's Selectable loadouts - Module Edited March 9, 2013 by aeroson Share this post Link to post Share on other sites
pridit 10 Posted March 9, 2013 (edited) Thanks, works perfectly. Not interested in the other script as I'm just looking for a basic save/load and this serves that purpose perfectly. Edited March 9, 2013 by Pridit Share this post Link to post Share on other sites
Juulloo 1 Posted March 9, 2013 In multiplayer however, if someone loads their loadout I still see the loadout they had previously. The gunshots don't make sounds then, only the impact. This can be pretty gamebreaking. Is there any way to fix this script for MP as well? Share this post Link to post Share on other sites
nedley 10 Posted March 9, 2013 I have tried in MP and it works, however I changed: init: // Load saved loadout on respawnplayer addMPEventHandler ["MPRespawn", { [player,loadout] call setLoadout; } ]; Share this post Link to post Share on other sites
Juulloo 1 Posted March 9, 2013 But if they still load from a crate, does it show the correct weapons etc? Or did you disable loading from crate? Share this post Link to post Share on other sites
aeroson 8 Posted March 9, 2013 (edited) Iam clueless, was looking for hints in other's loadout scripts, but nothing :( Could you give me your server name (thru steam) and possibly reproduce it ? Also not sure if it will help, byt try to add this code to the bottom of fnc_set_loadout.sqf _t setPos (getPos _t); _m = primaryWeapon _t; if(_m != "") then { _mz = getArray(configFile>>"CfgWeapons">>_m>>"muzzles"); if (_mz select 0 != "this") then { _m = _mz select 0; }; _t selectWeapon _m; }; Updated Edited March 9, 2013 by aeroson Share this post Link to post Share on other sites
Juulloo 1 Posted March 9, 2013 I tested it now with the added code, and it works like a charm. I can see peoples loadouts being changed, everything works. You might want to add this added code to your first post so others dont run into this problem anymore. Thank you for your quick response! Share this post Link to post Share on other sites
PRiME 1 Posted March 9, 2013 (edited) Tried this in SP editor and I do Save Loadout then dropped a few items including backpack and clothing and then used LOAD loadout and it just put back my backpack and just 1 clip and gun. Seems it doesn't loadup everything :( Actual items left, loadout that was loaded in as you can see in inventory. ALLOT missing http://dl.dropbox.com/u/41627694/ARMA3/loadoutUntitled.jpg (201 kB) ---------- Post added at 00:39 ---------- Previous post was at 00:22 ---------- Ok, A) Doesn't load back clothing B) only loads back 1 clip per weapon, so if I save it with 10 clips and load it gives me 1 or 2 clips for that weapon. Appears to save Weapon and Attachments fine. Edited March 9, 2013 by PRiME Share this post Link to post Share on other sites
aeroson 8 Posted March 9, 2013 Updated/Fixed @PRiME: Thank you and iam sorry i did not really test it with backpacks. Although now it doesn't update the backpack load indicator properly =/ Share this post Link to post Share on other sites
PRiME 1 Posted March 9, 2013 (edited) Ok can you fix the number of magazines saved? I will have a look at it myself but atm it only gives you 1 mag whereas before I had 11-12 mags for my weapon. It will need to count those in backpack/vests as well. This is going good, almost there :) Skip my idea, better to check weapons mag type then do a counter for each weapon using if statements. I will try to figure code out. Edited March 9, 2013 by PRiME Share this post Link to post Share on other sites
aeroson 8 Posted March 9, 2013 (edited) Updated/Fixed again Seems to have fixed it, but iam sure you will find more bugs :D Iam saving all items from uniform, vest and backpack in separate arrays, so no need to count mags. And thank you for your assistance it's much appreciated. Edited March 9, 2013 by aeroson Share this post Link to post Share on other sites
PRiME 1 Posted March 9, 2013 Cool that seems to have fixed majority of the problems. Cheers Share this post Link to post Share on other sites
pero2589 1 Posted March 9, 2013 Works nice, well done! Share this post Link to post Share on other sites
Guest Posted March 9, 2013 Thanks for sending this our way :cool: Release frontpaged on the Armaholic homepage. [ALPHA] Loadout set/get functions v2 Share this post Link to post Share on other sites
aeroson 8 Posted March 10, 2013 Updated/Fixed So far looks like this will be the final version... Until you/i find more bugs =/ Share this post Link to post Share on other sites
TricksterOC 1 Posted March 10, 2013 (edited) still fairly noobed to editing. I get and understand most of what I read but must be brain froze Could you clarify where or how to install this awesome script thanks UPDATE Brain unfrozen-MORE COFFEE--GOT IT!! sorry for the inquiry Edited March 10, 2013 by TricksterOC Updated Share this post Link to post Share on other sites
xx-LSD-xx 10 Posted March 11, 2013 (edited) I found some more errors. Rather funny I re-spawned in my underwear but was able to get my load out when I walked up to the ammo box. Here is a screenshot http://steamcommunity.com/profiles/76561197991695677/screenshots Also you have this: / Sets player's loadout from var loadout 0=[player,loadout] execVM 'set_loadout.sqf'; You don't have a loadout.sqf file you have fnc_set_loadout.sqf file and it comes up an error. Here's a screen shot http://steamcommunity.com/profiles/76561197991695677/screenshots All in all it needs a little tweaking but great job. Basically it works with a little comedy throw in. Just a heads up. Cheers:cool: Edited March 11, 2013 by xx-LSD-xx Share this post Link to post Share on other sites
aeroson 8 Posted March 11, 2013 (edited) I think you somehow loaded empty loadout, thats why you had only underwear. And thank you D: renamed it. EDIT: It was a bug in the respawn with same loadout init.sqf script :( Edited March 22, 2013 by aeroson Share this post Link to post Share on other sites
stevos758 10 Posted March 11, 2013 I am new to map making. Do I place the SQM in my mission folder. Paste PHP codes in ammo box in editor? or can I paste the second PHP code in the mission init.sqf? Share this post Link to post Share on other sites
aeroson 8 Posted March 11, 2013 (edited) Once you save mission in editor it should create mission.SQM with MISSIONNAME.Stratis in your C:\Users\PROFILENAME\Documents\Arma 3\missions or C:\Users\PROFILENAME\Documents\Arma 3\MPmissions You then put those files into this folder, just like this: Notice the description.ext file, you need that if you want respawn. Check out wiki for how-to. community.bistudio.com/wiki/Description.ext Edited March 11, 2013 by aeroson Share this post Link to post Share on other sites
stevos758 10 Posted March 11, 2013 Excellent! Thank you very much. Share this post Link to post Share on other sites