Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arsenal - Add ace_arsenal_fnc_saveLoadout as API to save loadouts #10151

Merged
merged 10 commits into from
Aug 10, 2024
1 change: 1 addition & 0 deletions addons/arsenal/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ PREP(removeStat);
PREP(removeVirtualItems);
PREP(renameDefaultLoadout);
PREP(replaceUniqueItemsLoadout);
PREP(saveLoadout);
PREP(scanConfig);
PREP(showItem);
PREP(sortPanel);
Expand Down
34 changes: 34 additions & 0 deletions addons/arsenal/functions/fnc_saveLoadout.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "..\script_component.hpp"
/*
* Author: DartRuffian
* Saves a given loadout to the client's profile.
*
* Arguments:
* 0: Name of loadout <STRING>
* 1: CBA extended loadout or getUnitLoadout array <ARRAY>
* 2: Replace existing loadout <BOOL> (default: false)
*
* Return Value:
* True if loadout was saved, otherwise false <BOOL>
*
* 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), []];
DartRuffian marked this conversation as resolved.
Show resolved Hide resolved
private _loadoutIndex = _loadouts findIf {(_x#0) == _name};

if (_loadoutIndex == -1) then {
_loadouts pushBack [_name, _loadout];
} else {
if (!_replaceExisting) exitWith { false };
johnb432 marked this conversation as resolved.
Show resolved Hide resolved
_loadouts set [_loadoutIndex, [_name, _loadout]];
};

true