From 663b9d258f47a98d9cb28d184057dd0d4dbc2e92 Mon Sep 17 00:00:00 2001 From: Brett Date: Mon, 20 Sep 2021 12:10:21 -0600 Subject: [PATCH 01/12] extended loadout --- addons/loadout/$PBOPREFIX$ | 1 + addons/loadout/CfgEventHandlers.hpp | 11 +++++ addons/loadout/CfgFunctions.hpp | 11 +++++ addons/loadout/XEH_PREP.sqf | 0 addons/loadout/XEH_postInit.sqf | 0 addons/loadout/XEH_preInit.sqf | 10 +++++ addons/loadout/XEH_preStart.sqf | 3 ++ addons/loadout/config.cpp | 17 ++++++++ addons/loadout/fnc_addLoadoutGetHandler.sqf | 33 +++++++++++++++ addons/loadout/fnc_addLoadoutSetHandler.sqf | 42 +++++++++++++++++++ addons/loadout/fnc_getLoadout.sqf | 37 ++++++++++++++++ .../loadout/fnc_removeLoadoutSetHandler.sqf | 39 +++++++++++++++++ addons/loadout/fnc_setLoadout.sqf | 42 +++++++++++++++++++ addons/loadout/script_component.hpp | 12 ++++++ 14 files changed, 258 insertions(+) create mode 100644 addons/loadout/$PBOPREFIX$ create mode 100644 addons/loadout/CfgEventHandlers.hpp create mode 100644 addons/loadout/CfgFunctions.hpp create mode 100644 addons/loadout/XEH_PREP.sqf create mode 100644 addons/loadout/XEH_postInit.sqf create mode 100644 addons/loadout/XEH_preInit.sqf create mode 100644 addons/loadout/XEH_preStart.sqf create mode 100644 addons/loadout/config.cpp create mode 100644 addons/loadout/fnc_addLoadoutGetHandler.sqf create mode 100644 addons/loadout/fnc_addLoadoutSetHandler.sqf create mode 100644 addons/loadout/fnc_getLoadout.sqf create mode 100644 addons/loadout/fnc_removeLoadoutSetHandler.sqf create mode 100644 addons/loadout/fnc_setLoadout.sqf create mode 100644 addons/loadout/script_component.hpp diff --git a/addons/loadout/$PBOPREFIX$ b/addons/loadout/$PBOPREFIX$ new file mode 100644 index 0000000000..4716d08806 --- /dev/null +++ b/addons/loadout/$PBOPREFIX$ @@ -0,0 +1 @@ +x\cba\addons\loadout diff --git a/addons/loadout/CfgEventHandlers.hpp b/addons/loadout/CfgEventHandlers.hpp new file mode 100644 index 0000000000..865276cfba --- /dev/null +++ b/addons/loadout/CfgEventHandlers.hpp @@ -0,0 +1,11 @@ +class Extended_PreStart_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_SCRIPT(XEH_preStart)); + }; +}; + +class Extended_PreInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_SCRIPT(XEH_preInit)); + }; +}; diff --git a/addons/loadout/CfgFunctions.hpp b/addons/loadout/CfgFunctions.hpp new file mode 100644 index 0000000000..680dbcf609 --- /dev/null +++ b/addons/loadout/CfgFunctions.hpp @@ -0,0 +1,11 @@ +class CfgFunctions { + class CBA { + class Loadout { + PATHTO_FNC(addLoadoutGetHandler); + PATHTO_FNC(addLoadoutSetHandler); + PATHTO_FNC(removeLoadoutSetHandler); + PATHTO_FNC(getLoadout); + PATHTO_FNC(setLoadout); + }; + }; +}; diff --git a/addons/loadout/XEH_PREP.sqf b/addons/loadout/XEH_PREP.sqf new file mode 100644 index 0000000000..e69de29bb2 diff --git a/addons/loadout/XEH_postInit.sqf b/addons/loadout/XEH_postInit.sqf new file mode 100644 index 0000000000..e69de29bb2 diff --git a/addons/loadout/XEH_preInit.sqf b/addons/loadout/XEH_preInit.sqf new file mode 100644 index 0000000000..9942d3a19d --- /dev/null +++ b/addons/loadout/XEH_preInit.sqf @@ -0,0 +1,10 @@ +#include "script_component.hpp" + +ADDON = false; + +#include "XEH_PREP.sqf" + +GVAR(getHandlers) = createHashMap; +GVAR(setHandlers) = createHashMap; + +ADDON = true; diff --git a/addons/loadout/XEH_preStart.sqf b/addons/loadout/XEH_preStart.sqf new file mode 100644 index 0000000000..43f1adee32 --- /dev/null +++ b/addons/loadout/XEH_preStart.sqf @@ -0,0 +1,3 @@ +#include "script_component.hpp" + +#include "XEH_PREP.sqf" diff --git a/addons/loadout/config.cpp b/addons/loadout/config.cpp new file mode 100644 index 0000000000..3877bc307e --- /dev/null +++ b/addons/loadout/config.cpp @@ -0,0 +1,17 @@ +#include "script_component.hpp" + +class CfgPatches { + class ADDON { + name = CSTRING(component); + units[] = {}; + requiredVersion = REQUIRED_VERSION; + requiredAddons[] = {"cba_common", "cba_events"}; + author = "$STR_CBA_Author"; + authors[] = {"Brett Mayson"}; + url = "$STR_CBA_URL"; + VERSION_CONFIG; + }; +}; + +#include "CfgEventHandlers.hpp" +#include "CfgFunctions.hpp" diff --git a/addons/loadout/fnc_addLoadoutGetHandler.sqf b/addons/loadout/fnc_addLoadoutGetHandler.sqf new file mode 100644 index 0000000000..f34fa6c3b8 --- /dev/null +++ b/addons/loadout/fnc_addLoadoutGetHandler.sqf @@ -0,0 +1,33 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_addLoadoutGetHandler +Description: + Add a handler for CBA_fnc_setLoadout. +Parameters: + _id - The id of the handler. + _function - The function you wish to execute. +Passed Arguments: + _this + 0: _unit - The unit to set the loadout on. + 1: _loadout - The unit's loadout +Returns: + true if a previous handler existed, false otherwise. +Examples: + (begin example) + ["earplugs", { + params ["_unit"]; + [_unit] call my_earplug_mod_fnc_hasEarplugs; + }] call CBA_fnc_addLoadoutGetHandler; + (end) +Author: + Brett Mayson +---------------------------------------------------------------------------- */ + +params [ + ["_id", "", [""]], + ["_function", {}, [{}]] +]; + +if (_id isEqualTo "") exitWith {-1}; + +GVAR(getHandlers) set [_id, _function]; diff --git a/addons/loadout/fnc_addLoadoutSetHandler.sqf b/addons/loadout/fnc_addLoadoutSetHandler.sqf new file mode 100644 index 0000000000..ff840f6b87 --- /dev/null +++ b/addons/loadout/fnc_addLoadoutSetHandler.sqf @@ -0,0 +1,42 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_addLoadoutSetHandler +Description: + Add a handler for CBA_fnc_setUnitLoadout. +Parameters: + _id - The id of the handler. + _function - The function you wish to execute. +Passed Arguments: + _this + 0: _unit - The unit to set the loadout on. + 1: _params - The parameters stored by CBA_fnc_getLoadout. +Returns: + Nothing. +Examples: + (begin example) + ["earplugs", { + params ["_unit", "_state"]; + if (_state) then { + [_unit] call my_earplug_mod_fnc_giveEarplugs; + } else { + [_unit] call my_earplug_mod_fnc_removeEarplugs; + }; + }] call CBA_fnc_addLoadoutSetHandler; + (end) +Author: + Brett Mayson +---------------------------------------------------------------------------- */ + +params [ + ["_id", "", [""]], + ["_function", {}, [{}]], + "_default" +]; + +if (_id isEqualTo "") exitWith {-1}; + +if !(_id in (GVAR(setHandlers))) then { + GVAR(setHandlers) set [_id, []]; +}; + +(GVAR(setHandlers) get _id) pushBack [_function, _default]; diff --git a/addons/loadout/fnc_getLoadout.sqf b/addons/loadout/fnc_getLoadout.sqf new file mode 100644 index 0000000000..ffbb6381a6 --- /dev/null +++ b/addons/loadout/fnc_getLoadout.sqf @@ -0,0 +1,37 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_getLoadout +Description: + Get a unit's extended loadout +Parameters: + _unit - The unit to set the loadout on. +Returns: + Extended Loadout +Examples: + (begin example) + [player] call CBA_fnc_getLoadout + (end) +Author: + Brett Mayson +---------------------------------------------------------------------------- */ + +params [ + ["_unit", objNull, [objNull]] +]; + +if (_unit isEqualTo objNull) exitWith {[]}; + +private _loadout = getUnitLoadout _unit; +private _extendedInfo = createHashMap; + +{ + private _info = [_unit, _loadout] call _y; + if !(isNil "_info") then { + _extendedInfo set [_x, _info]; + }; +} forEach GVAR(getHandlers); + +[ + _loadout, + _extendedInfo +] diff --git a/addons/loadout/fnc_removeLoadoutSetHandler.sqf b/addons/loadout/fnc_removeLoadoutSetHandler.sqf new file mode 100644 index 0000000000..8c7274687e --- /dev/null +++ b/addons/loadout/fnc_removeLoadoutSetHandler.sqf @@ -0,0 +1,39 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_removeLoadoutSetHandler +Description: + Remove a handler for CBA_fnc_setUnitLoadout. +Parameters: + _id - The id of the handler. + _index - The index of the handler. +Returns: + Nothing. +Examples: + (begin example) + MY_HANDLER = ["earplugs", { + params ["_unit", "_state"]; + if (_state) then { + [_unit] call my_earplug_mod_fnc_giveEarplugs; + } else { + [_unit] call my_earplug_mod_fnc_removeEarplugs; + }; + ["earplugs", MY_HANDLER] call CBA_fnc_removeLoadoutSetHandler; + }] call CBA_fnc_removeLoadoutSetHandler; + (end) +Author: + Brett Mayson +---------------------------------------------------------------------------- */ + +params [ + ["_id", "", [""]], + ["_index", -1, [0]] +]; + +if (_id isEqualTo "") exitWith {false}; +if (_index isEqualTo -1) exitWith {false}; + +if !(_id in (GVAR(setHandlers))) exitWith {false}; + +(GVAR(setHandlers) get _id) set [_index, {}]; + +true diff --git a/addons/loadout/fnc_setLoadout.sqf b/addons/loadout/fnc_setLoadout.sqf new file mode 100644 index 0000000000..dfd6762ee3 --- /dev/null +++ b/addons/loadout/fnc_setLoadout.sqf @@ -0,0 +1,42 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_setLoadout +Description: + Set a unit's extended loadout +Parameters: + _unit - The unit to set the loadout on. + _loadout - The extended loadout to set. + _fullMagazines - Partially emptied magazines will be refilled when the loadout is applied. +Returns: + Nothing +Examples: + (begin example) + [player] call CBA_fnc_setLoadout + (end) +Author: + Brett Mayson +---------------------------------------------------------------------------- */ + +params [ + ["_unit", objNull, [objNull]], + ["_loadout", [], [[]]], + ["_fullMagazines", false, [false]] +]; + +if (_unit isEqualTo objNull) exitWith {}; + +_unit setUnitLoadout [_loadout select 0, _fullMagazines]; + +private _extendedInfo = createHashMapFromArray (_loadout select 1); + +{ + private _id = _x; + { + _x params ["_function", "_default"]; + if (_id in _extendedInfo) then { + [_unit, _extendedInfo get _id] call _function; + } else { + [_unit, _default] call _function; + }; + } forEach (GVAR(setHandlers) get _id); +} forEach (keys GVAR(setHandlers)); diff --git a/addons/loadout/script_component.hpp b/addons/loadout/script_component.hpp new file mode 100644 index 0000000000..d1b041eb8a --- /dev/null +++ b/addons/loadout/script_component.hpp @@ -0,0 +1,12 @@ +#define COMPONENT loadout +#include "\x\cba\addons\main\script_mod.hpp" + +#ifdef DEBUG_ENABLED_LOADOUT + #define DEBUG_MODE_FULL +#endif + +#ifdef DEBUG_SETTINGS_LOADOUT + #define DEBUG_SETTINGS DEBUG_SETTINGS_LOADOUT +#endif + +#include "\x\cba\addons\main\script_macros.hpp" From ecfdf6a923f57404f8d14b5ba877b8e6cb376998 Mon Sep 17 00:00:00 2001 From: Brett Date: Mon, 20 Sep 2021 12:14:39 -0600 Subject: [PATCH 02/12] remove empty files --- addons/loadout/CfgEventHandlers.hpp | 6 ------ addons/loadout/XEH_PREP.sqf | 0 addons/loadout/XEH_postInit.sqf | 0 addons/loadout/XEH_preInit.sqf | 2 -- addons/loadout/XEH_preStart.sqf | 3 --- 5 files changed, 11 deletions(-) delete mode 100644 addons/loadout/XEH_PREP.sqf delete mode 100644 addons/loadout/XEH_postInit.sqf delete mode 100644 addons/loadout/XEH_preStart.sqf diff --git a/addons/loadout/CfgEventHandlers.hpp b/addons/loadout/CfgEventHandlers.hpp index 865276cfba..9b160c1600 100644 --- a/addons/loadout/CfgEventHandlers.hpp +++ b/addons/loadout/CfgEventHandlers.hpp @@ -1,9 +1,3 @@ -class Extended_PreStart_EventHandlers { - class ADDON { - init = QUOTE(call COMPILE_SCRIPT(XEH_preStart)); - }; -}; - class Extended_PreInit_EventHandlers { class ADDON { init = QUOTE(call COMPILE_SCRIPT(XEH_preInit)); diff --git a/addons/loadout/XEH_PREP.sqf b/addons/loadout/XEH_PREP.sqf deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/addons/loadout/XEH_postInit.sqf b/addons/loadout/XEH_postInit.sqf deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/addons/loadout/XEH_preInit.sqf b/addons/loadout/XEH_preInit.sqf index 9942d3a19d..ab2deab1ff 100644 --- a/addons/loadout/XEH_preInit.sqf +++ b/addons/loadout/XEH_preInit.sqf @@ -2,8 +2,6 @@ ADDON = false; -#include "XEH_PREP.sqf" - GVAR(getHandlers) = createHashMap; GVAR(setHandlers) = createHashMap; diff --git a/addons/loadout/XEH_preStart.sqf b/addons/loadout/XEH_preStart.sqf deleted file mode 100644 index 43f1adee32..0000000000 --- a/addons/loadout/XEH_preStart.sqf +++ /dev/null @@ -1,3 +0,0 @@ -#include "script_component.hpp" - -#include "XEH_PREP.sqf" From 7ca27d247715638d65f2ad92bdfd4c5420b0b614 Mon Sep 17 00:00:00 2001 From: Brett Mayson Date: Sat, 2 Oct 2021 20:09:16 +0000 Subject: [PATCH 03/12] review changes --- addons/loadout/fnc_addLoadoutSetHandler.sqf | 1 + addons/loadout/fnc_setLoadout.sqf | 12 ++++-------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/addons/loadout/fnc_addLoadoutSetHandler.sqf b/addons/loadout/fnc_addLoadoutSetHandler.sqf index ff840f6b87..2d1fbf667a 100644 --- a/addons/loadout/fnc_addLoadoutSetHandler.sqf +++ b/addons/loadout/fnc_addLoadoutSetHandler.sqf @@ -6,6 +6,7 @@ Description: Parameters: _id - The id of the handler. _function - The function you wish to execute. + _default - The default value when the get handler return nil Passed Arguments: _this 0: _unit - The unit to set the loadout on. diff --git a/addons/loadout/fnc_setLoadout.sqf b/addons/loadout/fnc_setLoadout.sqf index dfd6762ee3..be073bdda9 100644 --- a/addons/loadout/fnc_setLoadout.sqf +++ b/addons/loadout/fnc_setLoadout.sqf @@ -23,7 +23,7 @@ params [ ["_fullMagazines", false, [false]] ]; -if (_unit isEqualTo objNull) exitWith {}; +if (isNull _unit) exitWith {}; _unit setUnitLoadout [_loadout select 0, _fullMagazines]; @@ -33,10 +33,6 @@ private _extendedInfo = createHashMapFromArray (_loadout select 1); private _id = _x; { _x params ["_function", "_default"]; - if (_id in _extendedInfo) then { - [_unit, _extendedInfo get _id] call _function; - } else { - [_unit, _default] call _function; - }; - } forEach (GVAR(setHandlers) get _id); -} forEach (keys GVAR(setHandlers)); + [_unit, _extendedInfo getOrDefault [_id, _default] call _function; + } forEach _y; +} forEach GVAR(setHandlers); From 278928ba1c3b3e8bfa7911f0feef179818aec8e4 Mon Sep 17 00:00:00 2001 From: Brett Date: Mon, 24 Jan 2022 10:24:57 -0600 Subject: [PATCH 04/12] Update fnc_removeLoadoutSetHandler.sqf --- addons/loadout/fnc_removeLoadoutSetHandler.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/loadout/fnc_removeLoadoutSetHandler.sqf b/addons/loadout/fnc_removeLoadoutSetHandler.sqf index 8c7274687e..3d9d33cd9a 100644 --- a/addons/loadout/fnc_removeLoadoutSetHandler.sqf +++ b/addons/loadout/fnc_removeLoadoutSetHandler.sqf @@ -18,7 +18,7 @@ Examples: [_unit] call my_earplug_mod_fnc_removeEarplugs; }; ["earplugs", MY_HANDLER] call CBA_fnc_removeLoadoutSetHandler; - }] call CBA_fnc_removeLoadoutSetHandler; + }] call CBA_fnc_addLoadoutSetHandler; (end) Author: Brett Mayson From 33e735152f194cac69bfde94f83057950be9d849 Mon Sep 17 00:00:00 2001 From: Brett Date: Tue, 25 Jan 2022 09:58:40 -0600 Subject: [PATCH 05/12] Update fnc_setLoadout.sqf --- addons/loadout/fnc_setLoadout.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/loadout/fnc_setLoadout.sqf b/addons/loadout/fnc_setLoadout.sqf index be073bdda9..3d53a55486 100644 --- a/addons/loadout/fnc_setLoadout.sqf +++ b/addons/loadout/fnc_setLoadout.sqf @@ -33,6 +33,6 @@ private _extendedInfo = createHashMapFromArray (_loadout select 1); private _id = _x; { _x params ["_function", "_default"]; - [_unit, _extendedInfo getOrDefault [_id, _default] call _function; + [_unit, _extendedInfo getOrDefault [_id, _default]] call _function; } forEach _y; } forEach GVAR(setHandlers); From 93ad2009433e31190e978e36a18fdabd55036cbb Mon Sep 17 00:00:00 2001 From: Brett Date: Wed, 9 Mar 2022 19:32:39 -0600 Subject: [PATCH 06/12] handle vanialla loadouts --- addons/loadout/fnc_setLoadout.sqf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/addons/loadout/fnc_setLoadout.sqf b/addons/loadout/fnc_setLoadout.sqf index 3d53a55486..f45fbb6afa 100644 --- a/addons/loadout/fnc_setLoadout.sqf +++ b/addons/loadout/fnc_setLoadout.sqf @@ -25,6 +25,10 @@ params [ if (isNull _unit) exitWith {}; +if (count _loadout == 10) exitWith { + _unit setUnitLoadout [_loadout, _fullMagazines]; +}; + _unit setUnitLoadout [_loadout select 0, _fullMagazines]; private _extendedInfo = createHashMapFromArray (_loadout select 1); From 7a1ccd1e3851866f5797115136e70932b86ce2c4 Mon Sep 17 00:00:00 2001 From: Brett Date: Sun, 1 May 2022 01:29:04 -0600 Subject: [PATCH 07/12] use events --- addons/loadout/CfgFunctions.hpp | 3 -- addons/loadout/XEH_preInit.sqf | 5 --- addons/loadout/fnc_addLoadoutGetHandler.sqf | 33 -------------- addons/loadout/fnc_addLoadoutSetHandler.sqf | 43 ------------------- addons/loadout/fnc_getLoadout.sqf | 7 +-- .../loadout/fnc_removeLoadoutSetHandler.sqf | 39 ----------------- addons/loadout/fnc_setLoadout.sqf | 9 +--- 7 files changed, 3 insertions(+), 136 deletions(-) delete mode 100644 addons/loadout/fnc_addLoadoutGetHandler.sqf delete mode 100644 addons/loadout/fnc_addLoadoutSetHandler.sqf delete mode 100644 addons/loadout/fnc_removeLoadoutSetHandler.sqf diff --git a/addons/loadout/CfgFunctions.hpp b/addons/loadout/CfgFunctions.hpp index 680dbcf609..e46a149c07 100644 --- a/addons/loadout/CfgFunctions.hpp +++ b/addons/loadout/CfgFunctions.hpp @@ -1,9 +1,6 @@ class CfgFunctions { class CBA { class Loadout { - PATHTO_FNC(addLoadoutGetHandler); - PATHTO_FNC(addLoadoutSetHandler); - PATHTO_FNC(removeLoadoutSetHandler); PATHTO_FNC(getLoadout); PATHTO_FNC(setLoadout); }; diff --git a/addons/loadout/XEH_preInit.sqf b/addons/loadout/XEH_preInit.sqf index ab2deab1ff..19f1494f29 100644 --- a/addons/loadout/XEH_preInit.sqf +++ b/addons/loadout/XEH_preInit.sqf @@ -1,8 +1,3 @@ #include "script_component.hpp" -ADDON = false; - -GVAR(getHandlers) = createHashMap; -GVAR(setHandlers) = createHashMap; - ADDON = true; diff --git a/addons/loadout/fnc_addLoadoutGetHandler.sqf b/addons/loadout/fnc_addLoadoutGetHandler.sqf deleted file mode 100644 index f34fa6c3b8..0000000000 --- a/addons/loadout/fnc_addLoadoutGetHandler.sqf +++ /dev/null @@ -1,33 +0,0 @@ -#include "script_component.hpp" -/* ---------------------------------------------------------------------------- -Function: CBA_fnc_addLoadoutGetHandler -Description: - Add a handler for CBA_fnc_setLoadout. -Parameters: - _id - The id of the handler. - _function - The function you wish to execute. -Passed Arguments: - _this - 0: _unit - The unit to set the loadout on. - 1: _loadout - The unit's loadout -Returns: - true if a previous handler existed, false otherwise. -Examples: - (begin example) - ["earplugs", { - params ["_unit"]; - [_unit] call my_earplug_mod_fnc_hasEarplugs; - }] call CBA_fnc_addLoadoutGetHandler; - (end) -Author: - Brett Mayson ----------------------------------------------------------------------------- */ - -params [ - ["_id", "", [""]], - ["_function", {}, [{}]] -]; - -if (_id isEqualTo "") exitWith {-1}; - -GVAR(getHandlers) set [_id, _function]; diff --git a/addons/loadout/fnc_addLoadoutSetHandler.sqf b/addons/loadout/fnc_addLoadoutSetHandler.sqf deleted file mode 100644 index 2d1fbf667a..0000000000 --- a/addons/loadout/fnc_addLoadoutSetHandler.sqf +++ /dev/null @@ -1,43 +0,0 @@ -#include "script_component.hpp" -/* ---------------------------------------------------------------------------- -Function: CBA_fnc_addLoadoutSetHandler -Description: - Add a handler for CBA_fnc_setUnitLoadout. -Parameters: - _id - The id of the handler. - _function - The function you wish to execute. - _default - The default value when the get handler return nil -Passed Arguments: - _this - 0: _unit - The unit to set the loadout on. - 1: _params - The parameters stored by CBA_fnc_getLoadout. -Returns: - Nothing. -Examples: - (begin example) - ["earplugs", { - params ["_unit", "_state"]; - if (_state) then { - [_unit] call my_earplug_mod_fnc_giveEarplugs; - } else { - [_unit] call my_earplug_mod_fnc_removeEarplugs; - }; - }] call CBA_fnc_addLoadoutSetHandler; - (end) -Author: - Brett Mayson ----------------------------------------------------------------------------- */ - -params [ - ["_id", "", [""]], - ["_function", {}, [{}]], - "_default" -]; - -if (_id isEqualTo "") exitWith {-1}; - -if !(_id in (GVAR(setHandlers))) then { - GVAR(setHandlers) set [_id, []]; -}; - -(GVAR(setHandlers) get _id) pushBack [_function, _default]; diff --git a/addons/loadout/fnc_getLoadout.sqf b/addons/loadout/fnc_getLoadout.sqf index ffbb6381a6..431407d202 100644 --- a/addons/loadout/fnc_getLoadout.sqf +++ b/addons/loadout/fnc_getLoadout.sqf @@ -24,12 +24,7 @@ if (_unit isEqualTo objNull) exitWith {[]}; private _loadout = getUnitLoadout _unit; private _extendedInfo = createHashMap; -{ - private _info = [_unit, _loadout] call _y; - if !(isNil "_info") then { - _extendedInfo set [_x, _info]; - }; -} forEach GVAR(getHandlers); +["CBA_loadoutGet", [_unit, _loadout, _extendedInfo]] call CBA_fnc_localEvent; [ _loadout, diff --git a/addons/loadout/fnc_removeLoadoutSetHandler.sqf b/addons/loadout/fnc_removeLoadoutSetHandler.sqf deleted file mode 100644 index 3d9d33cd9a..0000000000 --- a/addons/loadout/fnc_removeLoadoutSetHandler.sqf +++ /dev/null @@ -1,39 +0,0 @@ -#include "script_component.hpp" -/* ---------------------------------------------------------------------------- -Function: CBA_fnc_removeLoadoutSetHandler -Description: - Remove a handler for CBA_fnc_setUnitLoadout. -Parameters: - _id - The id of the handler. - _index - The index of the handler. -Returns: - Nothing. -Examples: - (begin example) - MY_HANDLER = ["earplugs", { - params ["_unit", "_state"]; - if (_state) then { - [_unit] call my_earplug_mod_fnc_giveEarplugs; - } else { - [_unit] call my_earplug_mod_fnc_removeEarplugs; - }; - ["earplugs", MY_HANDLER] call CBA_fnc_removeLoadoutSetHandler; - }] call CBA_fnc_addLoadoutSetHandler; - (end) -Author: - Brett Mayson ----------------------------------------------------------------------------- */ - -params [ - ["_id", "", [""]], - ["_index", -1, [0]] -]; - -if (_id isEqualTo "") exitWith {false}; -if (_index isEqualTo -1) exitWith {false}; - -if !(_id in (GVAR(setHandlers))) exitWith {false}; - -(GVAR(setHandlers) get _id) set [_index, {}]; - -true diff --git a/addons/loadout/fnc_setLoadout.sqf b/addons/loadout/fnc_setLoadout.sqf index f45fbb6afa..7518a906d9 100644 --- a/addons/loadout/fnc_setLoadout.sqf +++ b/addons/loadout/fnc_setLoadout.sqf @@ -25,6 +25,7 @@ params [ if (isNull _unit) exitWith {}; +// A regular loadout array was passed in if (count _loadout == 10) exitWith { _unit setUnitLoadout [_loadout, _fullMagazines]; }; @@ -33,10 +34,4 @@ _unit setUnitLoadout [_loadout select 0, _fullMagazines]; private _extendedInfo = createHashMapFromArray (_loadout select 1); -{ - private _id = _x; - { - _x params ["_function", "_default"]; - [_unit, _extendedInfo getOrDefault [_id, _default]] call _function; - } forEach _y; -} forEach GVAR(setHandlers); +["CBA_loadoutSet", [_unit, _loadout, _extendedInfo]] call CBA_fnc_localEvent; From 3fa9059f76ba3aab410c38022acc137ab832675e Mon Sep 17 00:00:00 2001 From: Brett Date: Fri, 13 May 2022 17:57:06 -0600 Subject: [PATCH 08/12] Update addons/loadout/config.cpp Co-authored-by: PabstMirror --- addons/loadout/config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/loadout/config.cpp b/addons/loadout/config.cpp index 3877bc307e..da3b5e7da5 100644 --- a/addons/loadout/config.cpp +++ b/addons/loadout/config.cpp @@ -2,7 +2,7 @@ class CfgPatches { class ADDON { - name = CSTRING(component); + name = "Community Base Addons - Loadout Framework" units[] = {}; requiredVersion = REQUIRED_VERSION; requiredAddons[] = {"cba_common", "cba_events"}; From 54d977e6eed96d5ba4a69fb41baa3c8c24b83338 Mon Sep 17 00:00:00 2001 From: Brett Date: Fri, 13 May 2022 17:58:20 -0600 Subject: [PATCH 09/12] Update addons/loadout/fnc_setLoadout.sqf Co-authored-by: PabstMirror --- addons/loadout/fnc_setLoadout.sqf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/loadout/fnc_setLoadout.sqf b/addons/loadout/fnc_setLoadout.sqf index 7518a906d9..5b162e56c4 100644 --- a/addons/loadout/fnc_setLoadout.sqf +++ b/addons/loadout/fnc_setLoadout.sqf @@ -32,6 +32,7 @@ if (count _loadout == 10) exitWith { _unit setUnitLoadout [_loadout select 0, _fullMagazines]; -private _extendedInfo = createHashMapFromArray (_loadout select 1); +private _extendedInfo = _loadout select 1; +if (_extendedInfo isEqualType []) then { _extendedInfo = createHashMapFromArray _extendedInfo; }; ["CBA_loadoutSet", [_unit, _loadout, _extendedInfo]] call CBA_fnc_localEvent; From 6619b6045fc5742478c7ca35106906050757c218 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Fri, 13 May 2022 19:55:35 -0500 Subject: [PATCH 10/12] Update addons/loadout/config.cpp --- addons/loadout/config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/loadout/config.cpp b/addons/loadout/config.cpp index da3b5e7da5..10af0c1d27 100644 --- a/addons/loadout/config.cpp +++ b/addons/loadout/config.cpp @@ -2,7 +2,7 @@ class CfgPatches { class ADDON { - name = "Community Base Addons - Loadout Framework" + name = "Community Base Addons - Loadout Framework"; units[] = {}; requiredVersion = REQUIRED_VERSION; requiredAddons[] = {"cba_common", "cba_events"}; From 31c0ee357f7e6e4a92ce102b2ed9239df345111f Mon Sep 17 00:00:00 2001 From: Brett Date: Sat, 14 May 2022 00:24:00 -0600 Subject: [PATCH 11/12] Update fnc_setLoadout.sqf --- addons/loadout/fnc_setLoadout.sqf | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/loadout/fnc_setLoadout.sqf b/addons/loadout/fnc_setLoadout.sqf index 5b162e56c4..70cfcd9d95 100644 --- a/addons/loadout/fnc_setLoadout.sqf +++ b/addons/loadout/fnc_setLoadout.sqf @@ -30,9 +30,10 @@ if (count _loadout == 10) exitWith { _unit setUnitLoadout [_loadout, _fullMagazines]; }; -_unit setUnitLoadout [_loadout select 0, _fullMagazines]; +_loadout params ["_loadoutArray", "extendedInfo"]; + +_unit setUnitLoadout [_loadoutArray, _fullMagazines]; -private _extendedInfo = _loadout select 1; if (_extendedInfo isEqualType []) then { _extendedInfo = createHashMapFromArray _extendedInfo; }; ["CBA_loadoutSet", [_unit, _loadout, _extendedInfo]] call CBA_fnc_localEvent; From db40acd55a19cd51908ada20c4bc53a6ba86e68e Mon Sep 17 00:00:00 2001 From: Brett Date: Sat, 14 May 2022 00:24:33 -0600 Subject: [PATCH 12/12] Update fnc_setLoadout.sqf --- addons/loadout/fnc_setLoadout.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/loadout/fnc_setLoadout.sqf b/addons/loadout/fnc_setLoadout.sqf index 70cfcd9d95..1d61a44505 100644 --- a/addons/loadout/fnc_setLoadout.sqf +++ b/addons/loadout/fnc_setLoadout.sqf @@ -30,7 +30,7 @@ if (count _loadout == 10) exitWith { _unit setUnitLoadout [_loadout, _fullMagazines]; }; -_loadout params ["_loadoutArray", "extendedInfo"]; +_loadout params ["_loadoutArray", "_extendedInfo"]; _unit setUnitLoadout [_loadoutArray, _fullMagazines];