diff --git a/addons/magazinerepack/CfgEventHandlers.hpp b/addons/magazinerepack/CfgEventHandlers.hpp index be284a9d70..0d3301d6e0 100644 --- a/addons/magazinerepack/CfgEventHandlers.hpp +++ b/addons/magazinerepack/CfgEventHandlers.hpp @@ -1,4 +1,3 @@ - class Extended_PreStart_EventHandlers { class ADDON { init = QUOTE(call COMPILE_FILE(XEH_preStart)); @@ -10,3 +9,9 @@ class Extended_PreInit_EventHandlers { init = QUOTE(call COMPILE_FILE(XEH_preInit)); }; }; + +class Extended_PostInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_postInit)); + }; +}; diff --git a/addons/magazinerepack/XEH_PREP.hpp b/addons/magazinerepack/XEH_PREP.hpp index fc1861dc3d..ba58d49d52 100644 --- a/addons/magazinerepack/XEH_PREP.hpp +++ b/addons/magazinerepack/XEH_PREP.hpp @@ -1,4 +1,4 @@ - +PREP(canRepackMagazine); PREP(getMagazineChildren); PREP(magazineRepackFinish); PREP(magazineRepackProgress); diff --git a/addons/magazinerepack/XEH_postInit.sqf b/addons/magazinerepack/XEH_postInit.sqf new file mode 100644 index 0000000000..8a1cf07ca6 --- /dev/null +++ b/addons/magazinerepack/XEH_postInit.sqf @@ -0,0 +1,23 @@ +#include "script_component.hpp" + +// Inventory context menu action to repack magazines +[ + "#Magazine", + ["CONTAINER", "MAGAZINE"], + LSTRING(RepackMagazines), + [], + QPATHTOEF(common,UI\repack_ca.paa), + [ + {true}, + { + params ["_unit", "", "_magazine"]; + + [_unit, _magazine] call FUNC(canRepackMagazine) + } + ], + { + params ["_unit", "", "_magazine"]; + + [_unit, _unit, _magazine] call FUNC(startRepackingMagazine); + } +] call CBA_fnc_addItemContextMenuOption; diff --git a/addons/magazinerepack/functions/fnc_canRepackMagazine.sqf b/addons/magazinerepack/functions/fnc_canRepackMagazine.sqf new file mode 100644 index 0000000000..034de578be --- /dev/null +++ b/addons/magazinerepack/functions/fnc_canRepackMagazine.sqf @@ -0,0 +1,29 @@ +#include "script_component.hpp" +/* + * Author: mharis001 + * Checks if the given unit can repack magazines of the given type. + * + * Arguments: + * 0: Unit + * 1: Magazine + * + * Return Value: + * Can Repack Magazine + * + * Example: + * [_unit, _magazine] call ace_magazinerepack_fnc_canRepackMagazine + * + * Public: No + */ + +params ["_unit", "_magazine"]; + +private _maxAmmoCount = getNumber (configFile >> "CfgMagazines" >> _magazine >> "count"); + +{ + _x params ["_magazineType", "_ammoCount", "_isLoaded"]; + + _magazineType == _magazine // Magazine is of given type + && {_ammoCount > 0 && {_ammoCount < _maxAmmoCount}} // Is a partial magazine + && {!_isLoaded || {_unit canAdd _magazineType}} // In inventory or can be moved into it +} count magazinesAmmoFull _unit > 1