diff --git a/addons/arsenal/XEH_PREP.hpp b/addons/arsenal/XEH_PREP.hpp index 94d4739b60..d0819056f2 100644 --- a/addons/arsenal/XEH_PREP.hpp +++ b/addons/arsenal/XEH_PREP.hpp @@ -78,6 +78,7 @@ PREP(removeStat); PREP(removeVirtualItems); PREP(renameDefaultLoadout); PREP(replaceUniqueItemsLoadout); +PREP(saveLoadout); PREP(scanConfig); PREP(showItem); PREP(sortPanel); diff --git a/addons/arsenal/functions/fnc_saveLoadout.sqf b/addons/arsenal/functions/fnc_saveLoadout.sqf new file mode 100644 index 0000000000..05e712e45f --- /dev/null +++ b/addons/arsenal/functions/fnc_saveLoadout.sqf @@ -0,0 +1,37 @@ +#include "..\script_component.hpp" +/* + * Author: DartRuffian + * Saves a given loadout to the client's profile. + * + * Arguments: + * 0: Name of loadout + * 1: CBA extended loadout or getUnitLoadout array + * 2: Replace existing loadout (default: false) + * + * Return Value: + * True if loadout was saved, otherwise false + * + * Example: + * ["Current Loadout", getUnitLoadout ACE_player] call ace_arsenal_fnc_saveLoadout + * + * Public: Yes + */ + +params [["_name", "", [""]], ["_loadout", [], [[]]], ["_replaceExisting", false, [false]]]; + +if (_name == "" || {_loadout isEqualTo []}) exitWith { false }; + +private _loadouts = profileNamespace getVariable [QGVAR(saved_loadouts), []]; +private _loadoutIndex = _loadouts findIf {(_x#0) == _name}; + +// If a loadout with same name already exists and no overwriting enabled, quit +if (!_replaceExisting && {_loadoutIndex != -1}) exitWith { false }; + +if (_loadoutIndex == -1) then { + _loadouts pushBack [_name, _loadout]; +} else { + _loadouts set [_loadoutIndex, [_name, _loadout]]; +}; + +profileNamespace setVariable [QGVAR(saved_loadouts), _loadouts]; +true diff --git a/docs/wiki/framework/arsenal-framework.md b/docs/wiki/framework/arsenal-framework.md index 954bbc0a7e..a02dcdf646 100644 --- a/docs/wiki/framework/arsenal-framework.md +++ b/docs/wiki/framework/arsenal-framework.md @@ -588,3 +588,12 @@ TAG_my_arsenal_essentials = ["arifle_AK12_F", "LMG_03_F"]; [ace_arsenal_currentBox, TAG_my_arsenal_essentials] call ace_arsenal_fnc_addVirtualItems }] call CBA_fnc_addEventHandler; ``` + +### 10.4 Saving loadouts to profile +A loadout can be saved to the player's profile using `ace_arsenal_fnc_saveLoadout`. + +```sqf +private _loadout = [ACE_player] call CBA_fnc_getLoadout; // or getUnitLoadout ACE_player +private _replaceExisting = true; // optional, default: false +["Current Loadout", _loadout, _replaceExisting] call ace_arsenal_fnc_saveLoadout; +```