diff --git a/addons/common/CfgFunctions.hpp b/addons/common/CfgFunctions.hpp index fde194db6..2dc436a2b 100644 --- a/addons/common/CfgFunctions.hpp +++ b/addons/common/CfgFunctions.hpp @@ -78,6 +78,10 @@ class CfgFunctions { PATHTO_FNC(addBinocularMagazine); PATHTO_FNC(removeBinocularMagazine); PATHTO_FNC(randomizeFacewear); + PATHTO_FNC(getUnitLoadout); + PATHTO_FNC(filterLoadout); + PATHTO_FNC(addLoadoutFilter); + PATHTO_FNC(removeLoadoutFilter); }; class Cargo { diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index b9e762ed3..93d7bd2a1 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -45,6 +45,7 @@ GVAR(featureCamerasNames) = [ call COMPILE_FILE(init_gauss); call COMPILE_FILE(init_perFrameHandler); call COMPILE_FILE(init_delayLess); +call COMPILE_FILE(init_filteredLoadout); // Due to activateAddons being overwritten by eachother (only the last executed command will be active), we apply this bandaid GVAR(addons) = call (uiNamespace getVariable [QGVAR(addons), {[]}]); diff --git a/addons/common/fnc_addLoadoutFilter.sqf b/addons/common/fnc_addLoadoutFilter.sqf new file mode 100644 index 000000000..1f987c7e6 --- /dev/null +++ b/addons/common/fnc_addLoadoutFilter.sqf @@ -0,0 +1,43 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_addLoadoutFilter + +Description: + Add a filter for CBA_fnc_getUnitLoadout. + +Parameters: + _function - The function you wish to execute. + +Passed Arguments: + _this + 0: _loadout - A getUnitLoadout array + 1: _handle - A number representing the handle of the function. Same as '_handle' returned by this function. + +Returns: + _handle - A number representing the handle of the function. Use this to remove the handler. + +Examples: + Remove the radio from loadouts + (begin example) + _handle = [{ + params ["_loadout", "_handle"]; + if ((_loadout select 9) select 2 == "ItemRadio") then { + (_loadout select 9) set [2, ""]; + }; + _loadout + }] call CBA_fnc_addLoadoutFilter; + (end) + +Author: + SynixeBrett +---------------------------------------------------------------------------- */ + +params [["_function", {}, [{}]]]; + +if (_function isEqualTo {}) exitWith {-1}; + +private _handle = GVAR(filterLoadoutHandles) pushBack count GVAR(filterLoadoutArray); + +GVAR(filterLoadoutArray) pushBack [_function, _handle]; + +_handle diff --git a/addons/common/fnc_filterLoadout.sqf b/addons/common/fnc_filterLoadout.sqf new file mode 100644 index 000000000..cdd091c5c --- /dev/null +++ b/addons/common/fnc_filterLoadout.sqf @@ -0,0 +1,30 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_filterLoadout + +Description: + Used to filter a getUnitLoadout array. + +Parameters: + _loadout - getUnitLoadout array + +Example: + (begin example) + _loadout = [getUnitLoadout player] call CBA_fnc_filterLoadout; + (end) + +Returns: + filtered getUnitLoadout array + +Author: + SynixeBrett +---------------------------------------------------------------------------- */ +SCRIPT(filterLoadout); + +params [["_loadout", [], [[]]]]; + +{ + _loadout = [_loadout] call (_x select 0); +} forEach GVAR(filterLoadoutArray); + +_loadout diff --git a/addons/common/fnc_getUnitLoadout.sqf b/addons/common/fnc_getUnitLoadout.sqf new file mode 100644 index 000000000..1171dc942 --- /dev/null +++ b/addons/common/fnc_getUnitLoadout.sqf @@ -0,0 +1,28 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_getUnitLoadout + +Description: + Return the loadout of a unit with CBA_fnc_filterLoadout applied. + +Parameters: + _unit - Unit to get loadout of + +Returns: + _loadout - `getUnitLoadout` array + +Examples: + (begin example) + private _loadout = [player] call CBA_fnc_getUnitLoadout; + (end) + +Author: + SynixeBrett +---------------------------------------------------------------------------- */ +SCRIPT(getUnitLoadout); + +params [["_unit", objNull, [objNull]]]; + +if (_unit isEqualTo objNull) exitWith {[]}; + +[getUnitLoadout _unit] call CBA_fnc_filterLoadout diff --git a/addons/common/fnc_removeLoadoutFilter.sqf b/addons/common/fnc_removeLoadoutFilter.sqf new file mode 100644 index 000000000..3f5198a5a --- /dev/null +++ b/addons/common/fnc_removeLoadoutFilter.sqf @@ -0,0 +1,54 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_removeLoadoutFilter + +Description: + Remove a handler that you have added using CBA_fnc_addLoadoutFilter. + +Parameters: + _handle - The function handle you wish to remove. + +Returns: + true if removed successful, false otherwise + +Examples: + (begin example) + _handle = [myLoadoutFilter] call CBA_fnc_addLoadoutFilter; + sleep 10; + [_handle] call CBA_fnc_removeLoadoutFilter; + (end) + +Author: + Nou & Jaynus, SynixeBrett +---------------------------------------------------------------------------- */ + +params [["_handle", -1, [0]]]; + +[{ + params ["_handle"]; + + private _index = GVAR(filterLoadoutHandles) param [_handle]; + if (isNil "_index") exitWith {false}; + + GVAR(filterLoadoutHandles) set [_handle, nil]; + (GVAR(filterLoadoutArray) select _index) set [0, {}]; + + if (GVAR(filterLoadoutToRemove) isEqualTo []) then { + { + { + GVAR(filterLoadoutArray) set [_x, objNull]; + } forEach GVAR(filterLoadoutToRemove); + + GVAR(filterLoadoutArray) = GVAR(filterLoadoutArray) - [objNull]; + GVAR(filterLoadoutToRemove) = []; + + { + _x params ["", "_index"]; + GVAR(filterLoadoutHandles) set [_index, _forEachIndex]; + } forEach GVAR(filterLoadoutArray); + } call CBA_fnc_execNextFrame; + }; + + GVAR(filterLoadoutToRemove) pushBackUnique _index; + true +}, _handle] call CBA_fnc_directCall; diff --git a/addons/common/init_filteredLoadout.sqf b/addons/common/init_filteredLoadout.sqf new file mode 100644 index 000000000..613da87e4 --- /dev/null +++ b/addons/common/init_filteredLoadout.sqf @@ -0,0 +1,5 @@ +#include "script_component.hpp" + +GVAR(filterLoadoutArray) = []; +GVAR(filterLoadoutHandles) = []; +GVAR(filterLoadoutToRemove) = [];