From dbe0324a1ffab88b43d738f0b75b1300adacb148 Mon Sep 17 00:00:00 2001 From: Brett Date: Sat, 21 Dec 2019 13:32:20 -0600 Subject: [PATCH 1/3] Filtered Loadouts --- addons/common/CfgFunctions.hpp | 4 +++ addons/common/XEH_preInit.sqf | 1 + addons/common/fnc_addLoadoutFilter.sqf | 36 +++++++++++++++++++++++ addons/common/fnc_filterLoadout.sqf | 25 ++++++++++++++++ addons/common/fnc_getUnitLoadout.sqf | 23 +++++++++++++++ addons/common/fnc_removeLoadoutFilter.sqf | 24 +++++++++++++++ addons/common/init_filteredLoadout.sqf | 4 +++ 7 files changed, 117 insertions(+) create mode 100644 addons/common/fnc_addLoadoutFilter.sqf create mode 100644 addons/common/fnc_filterLoadout.sqf create mode 100644 addons/common/fnc_getUnitLoadout.sqf create mode 100644 addons/common/fnc_removeLoadoutFilter.sqf create mode 100644 addons/common/init_filteredLoadout.sqf 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..80567294d --- /dev/null +++ b/addons/common/fnc_addLoadoutFilter.sqf @@ -0,0 +1,36 @@ +#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 filter. +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}; + +GVAR(loadoutFilterId) = GVAR(loadoutFilterId) + 1; +GVAR(loadoutFilters) setVariable [str GVAR(loadoutFilterId), _function]; + +GVAR(loadoutFilterId) diff --git a/addons/common/fnc_filterLoadout.sqf b/addons/common/fnc_filterLoadout.sqf new file mode 100644 index 000000000..50569f506 --- /dev/null +++ b/addons/common/fnc_filterLoadout.sqf @@ -0,0 +1,25 @@ +#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 (GVAR(loadoutFilters) getVariable [_x, {}]); +} forEach allVariables GVAR(loadoutFilters); + +_loadout diff --git a/addons/common/fnc_getUnitLoadout.sqf b/addons/common/fnc_getUnitLoadout.sqf new file mode 100644 index 000000000..9bbf165ed --- /dev/null +++ b/addons/common/fnc_getUnitLoadout.sqf @@ -0,0 +1,23 @@ +#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..f78a08c9a --- /dev/null +++ b/addons/common/fnc_removeLoadoutFilter.sqf @@ -0,0 +1,24 @@ +#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: + Nothing +Examples: + (begin example) + _handle = [myLoadoutFilter] call CBA_fnc_addLoadoutFilter; + sleep 10; + [_handle] call CBA_fnc_removeLoadoutFilter; + (end) +Author: + SynixeBrett +---------------------------------------------------------------------------- */ + +params [["_handle", -1, [0]]]; + +if (_handle isEqualTo -1) exitWith {-1}; + +GVAR(loadoutFilters) setVariable [str _handle, nil]; diff --git a/addons/common/init_filteredLoadout.sqf b/addons/common/init_filteredLoadout.sqf new file mode 100644 index 000000000..5af59f125 --- /dev/null +++ b/addons/common/init_filteredLoadout.sqf @@ -0,0 +1,4 @@ +#include "script_component.hpp" + +GVAR(loadoutFilters) = []; +GVAR(loadoutFilterId) = 0; From 3c2c8aaa8327ab883275889e97d1472081142e18 Mon Sep 17 00:00:00 2001 From: Brett Date: Sun, 26 Apr 2020 23:41:00 -0600 Subject: [PATCH 2/3] mharis001 suggestions --- addons/common/CfgFunctions.hpp | 2 -- addons/common/fnc_addLoadoutFilter.sqf | 12 ++++-------- addons/common/fnc_filterLoadout.sqf | 4 ++-- addons/common/fnc_getUnitLoadout.sqf | 23 ---------------------- addons/common/fnc_removeLoadoutFilter.sqf | 24 ----------------------- addons/common/init_filteredLoadout.sqf | 1 - 6 files changed, 6 insertions(+), 60 deletions(-) delete mode 100644 addons/common/fnc_getUnitLoadout.sqf delete mode 100644 addons/common/fnc_removeLoadoutFilter.sqf diff --git a/addons/common/CfgFunctions.hpp b/addons/common/CfgFunctions.hpp index 2dc436a2b..bfc7671dc 100644 --- a/addons/common/CfgFunctions.hpp +++ b/addons/common/CfgFunctions.hpp @@ -78,10 +78,8 @@ 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/fnc_addLoadoutFilter.sqf b/addons/common/fnc_addLoadoutFilter.sqf index 80567294d..2fb7f1a7c 100644 --- a/addons/common/fnc_addLoadoutFilter.sqf +++ b/addons/common/fnc_addLoadoutFilter.sqf @@ -8,14 +8,13 @@ Parameters: 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 filter. + Nothing. Examples: Remove the radio from loadouts (begin example) - _handle = [{ - params ["_loadout", "_handle"]; + [{ + params ["_loadout"]; if ((_loadout select 9) select 2 == "ItemRadio") then { (_loadout select 9) set [2, ""]; }; @@ -30,7 +29,4 @@ params [["_function", {}, [{}]]]; if (_function isEqualTo {}) exitWith {-1}; -GVAR(loadoutFilterId) = GVAR(loadoutFilterId) + 1; -GVAR(loadoutFilters) setVariable [str GVAR(loadoutFilterId), _function]; - -GVAR(loadoutFilterId) +GVAR(loadoutFilters) pushBack [ _function]; diff --git a/addons/common/fnc_filterLoadout.sqf b/addons/common/fnc_filterLoadout.sqf index 50569f506..90d8ad6bd 100644 --- a/addons/common/fnc_filterLoadout.sqf +++ b/addons/common/fnc_filterLoadout.sqf @@ -19,7 +19,7 @@ SCRIPT(filterLoadout); params [["_loadout", [], [[]]]]; { - _loadout = [_loadout] call (GVAR(loadoutFilters) getVariable [_x, {}]); -} forEach allVariables GVAR(loadoutFilters); + _loadout = [_loadout] call _x; +} forEach GVAR(loadoutFilters); _loadout diff --git a/addons/common/fnc_getUnitLoadout.sqf b/addons/common/fnc_getUnitLoadout.sqf deleted file mode 100644 index 9bbf165ed..000000000 --- a/addons/common/fnc_getUnitLoadout.sqf +++ /dev/null @@ -1,23 +0,0 @@ -#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 deleted file mode 100644 index f78a08c9a..000000000 --- a/addons/common/fnc_removeLoadoutFilter.sqf +++ /dev/null @@ -1,24 +0,0 @@ -#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: - Nothing -Examples: - (begin example) - _handle = [myLoadoutFilter] call CBA_fnc_addLoadoutFilter; - sleep 10; - [_handle] call CBA_fnc_removeLoadoutFilter; - (end) -Author: - SynixeBrett ----------------------------------------------------------------------------- */ - -params [["_handle", -1, [0]]]; - -if (_handle isEqualTo -1) exitWith {-1}; - -GVAR(loadoutFilters) setVariable [str _handle, nil]; diff --git a/addons/common/init_filteredLoadout.sqf b/addons/common/init_filteredLoadout.sqf index 5af59f125..522df5e39 100644 --- a/addons/common/init_filteredLoadout.sqf +++ b/addons/common/init_filteredLoadout.sqf @@ -1,4 +1,3 @@ #include "script_component.hpp" GVAR(loadoutFilters) = []; -GVAR(loadoutFilterId) = 0; From f4c78a1d3832c19275be316ed21c233107543519 Mon Sep 17 00:00:00 2001 From: Brett Date: Sun, 26 Apr 2020 23:41:44 -0600 Subject: [PATCH 3/3] remove space --- addons/common/fnc_addLoadoutFilter.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/common/fnc_addLoadoutFilter.sqf b/addons/common/fnc_addLoadoutFilter.sqf index 2fb7f1a7c..ffd53451f 100644 --- a/addons/common/fnc_addLoadoutFilter.sqf +++ b/addons/common/fnc_addLoadoutFilter.sqf @@ -29,4 +29,4 @@ params [["_function", {}, [{}]]]; if (_function isEqualTo {}) exitWith {-1}; -GVAR(loadoutFilters) pushBack [ _function]; +GVAR(loadoutFilters) pushBack [_function];