/* AUTHOR: aeroson NAPATH_ME: loadout_manager.sqf VERSION: 1.4 DOWNLOAD, DOCUMENTATION & PARTICIPATE: https://github.com/aeroson/get-set-loadout http://forums.bistudio.com/showthread.php?148577-GET-SET-Loadout-(saves-and-loads-pretty-much-everything) REQUIRES: requires compiled set/get functions (usually in the mission's init.sqf) getLoadout = compile preprocessFileLineNumbers 'fnc_get_loadout.sqf'; setLoadout = compile preprocessFileLineNumbers 'fnc_set_loadout.sqf'; USAGE: put this into init line of object you wish to be loadout manager 0 = [this] execVM 'loadout_manager.sqf'; */ //OPTIONS: #define SHOW_MENU_FOR [#save,#load,#remove,#vas] #define PROFILE_VAR_NAME aero_loadout // CONNECTORS: #define QUOTE(A) #A #define FUNC_getLoadout getLoadout #define FUNC_setLoadout setLoadout //#define PATH_ME QUOTE(aero\client\loadout\loadout_manager.sqf) #define PATH_ME QUOTE(loadout_manager.sqf) if (isDedicated) exitWith {}; private["_obj","_vasAdd","_actions","_args","_removeActions","_mainMenu","_loadout","_arg1","_version"]; _obj = _this select 0; // remove all actions added by this script _removeActions = { { _obj removeAction _x; } foreach _actions; _actions = []; }; // show main menu _mainMenu = { private ["_loadout","_any","_l","_show"]; call _removeActions; _loadout = profileNamespace getVariable QUOTE(PROFILE_VAR_NAME); if !isNil("_loadout") then { _any = false; for "_i" from 0 to count(_loadout) do { _l = _loadout select _i; if (!isNil("_l")) then { _any = true; if("load" in SHOW_MENU_FOR) then { _actions = _actions + [_obj addAction [format["Load %1",_l select 0], PATH_ME, ["load",_i], 3000-_i]]; }; }; }; if ((_any)&&("remove" in SHOW_MENU_FOR)) then { _actions = _actions + [ _obj addAction ["Remove loadout ...", PATH_ME, ["remove_menu"], 2004] ]; }; }; if("save" in SHOW_MENU_FOR) then { _actions = _actions + [ _obj addAction ["Save loadout ...", PATH_ME, ["save_menu"], 2008] ]; }; /*if("offer" in SHOW_MENU_FOR) then { _actions = _actions + [ _obj addAction ["Offer loadout ...", PATH_ME, ["offer_menu"], 2002] ]; };*/ if ("vas" in SHOW_MENU_FOR) then { _any = false; for "_i" from 0 to 9 do { if(!isnil {profileNameSpace getVariable format["vas_gear_new_%1",_i]}) then { _any = true; }; }; if(_any) then { _actions = _actions + [ _obj addAction ["Load VAS loadout ...", PATH_ME, ["vas_menu"], 2000] ]; }; }; }; _vasAdd = { 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 { if(!isNull unitBackpack _target) then { unitBackpack _target addWeaponCargo [_item,1]; }; } else { _target addItem _item; }; }; }; _target = player; _args = ["back",0]; if (count(_this)>1) then { _args = _this select 3; }; _actions = _obj getVariable "actions"; if isNil("_actions") then { _obj setVariable ["actions",[],false]; _actions = []; }; _arg1 = _args select 1; _loadout = profileNamespace getVariable QUOTE(PROFILE_VAR_NAME); if isNil("_loadout") then { profileNamespace setVariable [QUOTE(PROFILE_VAR_NAME),[]]; }; switch (_args select 0) do { case "back": { call _mainMenu; }; case "save_menu": { call _removeActions; _actions = _actions + [_obj addAction ["... back", PATH_ME, ["back"], 3001, false, false]]; _actions = _actions + [_obj addAction ["Save as new", PATH_ME, ["save",-1], 3000]]; for "_i" from 0 to (count(_loadout)-1) do { _l = _loadout select _i; if !isNil("_l") then { _actions = _actions + [_obj addAction [format["Replace %1",_l select 0], PATH_ME, ["save",_i], 2000-_i]]; }; }; }; case "remove_menu": { call _removeActions; _actions = _actions + [_obj addAction ["... back", PATH_ME, ["back"], 3000, false, false]]; for "_i" from 0 to (count(_loadout)-1) do { _l = _loadout select _i; if !isNil("_l") then { _actions = _actions + [_obj addAction [format["Remove %1",_l select 0], PATH_ME, ["remove",_i], 2000-_i]]; }; }; }; case "remove": { // set desired loadout at index to nil (remove it) _loadoutName = (_loadout select _arg1) select 0; hint parseText format["Removed loadot"]; _loadout set[_arg1, nil]; profileNamespace setVariable [QUOTE(PROFILE_VAR_NAME),_loadout]; call _mainMenu; }; case "save": { // find empty loadout index if (_arg1==-1) then { _i = 0; while {_i<=count(_loadout)} do { _l = _loadout select _i; if isNil("_l") then { _arg1 = _i; _i = count(_loadout); // end loop }; _i = _i + 1; }; }; _loadoutName = "" + "" + "" + "" + "" + "" + ""; hintSilent parseText format["Saving loadout"]; _loadout set [ _arg1, [ _loadoutName, [_target] call FUNC_getLoadout ] ]; profileNamespace setVariable [QUOTE(PROFILE_VAR_NAME),_loadout]; saveProfileNamespace; hint parseText format["Saved loadout"]; call _mainMenu; }; case "load": { _loadout = _loadout select _arg1; if ( isNil("_loadout") ) then { hint "This loadout is empty !"; } else { _loadoutName = _loadout select 0; hint parseText format["Loading loadout"]; [_target, _loadout select 1] call FUNC_setLoadout; loadout = _loadout select 1; // to work with spawn loadout loading hint parseText format["Loaded loadout"]; //hint parseText format["Loaded

%1",_loadoutName]; }; }; case "offer_menu": { call _removeActions; _actions = _actions + [_obj addAction ["... back", PATH_ME, ["back"], 3001, false, false]]; _actions = _actions + [_obj addAction ["Refresh ...", PATH_ME, ["offer_menu"], 3000, false, false]]; _i = 0; { if (isPlayer _x) then { _actions = _actions + [_obj addAction [format["Offer to %1", name _x], PATH_ME, ["offer",_x], 2000-_i]]; }; _i = _i + 1; } forEach nearestObjects [getPos _target, ["CAManBase"], 5]; }; case "offer": { if (_target distance _arg1 > 5) then { hint "Too far, refresh and try again"; } else { offer_loadout = [_target, [_target] call FUNC_getLoadout]; (owner _arg1) publicVariableClient "aero_offer_loadout"; hint format["Loadout offered to %1", name _arg1]; call _mainMenu; }; }; case "vas_menu": { call _removeActions; _actions = _actions + [_obj addAction ["... back", PATH_ME, ["back"], 3000, false, false]]; for "_i" from 0 to 9 do { if(!isnil {profileNameSpace getVariable format["vas_gear_new_%1",_i]}) then { _loadout = profileNameSpace getVariable format["vas_gear_new_%1",_i]; _actions = _actions + [_obj addAction [format["Load %1", _loadout select 0], PATH_ME, ["vas_load_new",_i], 2000-_i]]; }; }; }; case "vas_load_new": { _l = profileNameSpace getVariable format["vas_gear_new_%1",_arg1]; _loadoutName = _l select 0; hint parseText format["Loading VAS loadout"]; /* 0 "drhdrhdrh", 1 "LMG_Mk200_ARCO_bipod_F", 2 "launch_NLAW_F", 3 "hgun_P07_F", 4 ["HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","SmokeShellGreen","SmokeShellGreen","SmokeShellGreen","SmokeShellYellow","SmokeShellYellow","SmokeShellYellow","SmokeShellYellow","SmokeShellPurple","SmokeShellPurple","SmokeShellPurple","SmokeShellPurple","SmokeShellBlue","SmokeShellBlue","SmokeShellBlue","SmokeShellBlue","SmokeShellBlue","SmokeShellOrange","SmokeShellOrange","SmokeShellOrange","SmokeShellOrange","SmokeShellOrange","SmokeShell","SmokeShell","SmokeShell","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","DemoCharge_Remote_Mag","200Rnd_65x39_cased_Box_Tracer","200Rnd_65x39_cased_Box_Tracer","200Rnd_65x39_cased_Box","DemoCharge_Remote_Mag","200Rnd_65x39_cased_Box","16Rnd_9x21_Mag","200Rnd_65x39_cased_Box","NLAW_F","16Rnd_9x21_Mag"], 5 "U_B_CombatUniform_mcam", 6 "V_PlateCarrierGL_rgr", 7 "B_Kitbag_mcamo", 8 ["ItemMap","ItemCompass","ItemWatch","ItemRadio","ItemGPS","G_Tactical_Clear","NVGoggles","H_HelmetB_paint","Binocular"], 9 ["muzzle_snds_H_MG","","optic_Arco"], 10 ["","",""] 11 ["muzzle_snds_L","",""], 12 [], 13 ["FirstAidKit","FirstAidKit"], 14 ["FirstAidKit","FirstAidKit","FirstAidKit","FirstAidKit","FirstAidKit","FirstAidKit","FirstAidKit","FirstAidKit","FirstAidKit","FirstAidKit","FirstAidKit","FirstAidKit","FirstAidKit","FirstAidKit","FirstAidKit","FirstAidKit","FirstAidKit","FirstAidKit","FirstAidKit","FirstAidKit","FirstAidKit","FirstAidKit","FirstAidKit","FirstAidKit"] ]*/ /* _primary = _loadout select 1; _launcher = _loadout select 2; _handgun = _loadout select 3; _magazines = _loadout select 4; _uniform = _loadout select 5; _vest = _loadout select 6; _backpack = _loadout select 7; _items = _loadout select 8; _primitems = _loadout select 9; _secitems = _loadout select 10; _handgunitems = _loadout select 11; _uitems = _loadout select 12; _vitems = _loadout select 13; _bitems = _loadout select 14; */ [_target, [ _l select 8, _l select 1, _l select 9, _l select 3, _l select 11, _l select 2, _l select 10, _l select 5, _l select 12, _l select 6, _l select 13, _l select 7, _l select 14 ] ] call FUNC_setLoadout; { [_target, _x] call _vasAdd; } forEach (_l select 4); loadout = [_target] call FUNC_getLoadout; // to work with spawn loadout loading hint parseText format["Loaded VAS loadout"]; }; default { hint "Invalid argument"; }; }; _obj setVariable ["actions",_actions,false];