diff --git a/optionals/compat_sog/CfgAmmo/explosives.hpp b/optionals/compat_sog/CfgAmmo/explosives.hpp index e2a71e4ae16..44cb68fc130 100644 --- a/optionals/compat_sog/CfgAmmo/explosives.hpp +++ b/optionals/compat_sog/CfgAmmo/explosives.hpp @@ -42,7 +42,7 @@ class vn_mine_punji_01_ammo: APERSBoundingMine_Range_Ammo { class EventHandlers { class ADDON { - AmmoHit = QUOTE(call FUNC(handlePunjiTrapDamage)); + AmmoHit = QUOTE(call FUNC(handlePunjiTrapTrigger)); }; }; }; @@ -57,7 +57,7 @@ class vn_mine_punji_03_ammo: vn_mine_punji_01_ammo { class EventHandlers { class ADDON { - AmmoHit = QUOTE(call FUNC(handlePunjiTrapDamage)); + AmmoHit = QUOTE(call FUNC(handlePunjiTrapTrigger)); }; }; }; diff --git a/optionals/compat_sog/CfgEventHandlers.hpp b/optionals/compat_sog/CfgEventHandlers.hpp index ad6f4e3740e..fc6d80fc5f9 100644 --- a/optionals/compat_sog/CfgEventHandlers.hpp +++ b/optionals/compat_sog/CfgEventHandlers.hpp @@ -10,6 +10,12 @@ class Extended_PreInit_EventHandlers { }; }; +class Extended_PostInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_SCRIPT(XEH_postInit)); + }; +}; + class Extended_InitPost_EventHandlers { class GVAR(spiderhole_01_nogeo) { class ADDON { diff --git a/optionals/compat_sog/XEH_PREP.hpp b/optionals/compat_sog/XEH_PREP.hpp index 0b86f427020..e71665db093 100644 --- a/optionals/compat_sog/XEH_PREP.hpp +++ b/optionals/compat_sog/XEH_PREP.hpp @@ -1,2 +1,3 @@ PREP(disableCookoff); PREP(handlePunjiTrapDamage); +PREP(handlePunjiTrapTrigger); diff --git a/optionals/compat_sog/XEH_postInit.sqf b/optionals/compat_sog/XEH_postInit.sqf new file mode 100644 index 00000000000..fbbbe73d9fb --- /dev/null +++ b/optionals/compat_sog/XEH_postInit.sqf @@ -0,0 +1 @@ +[QGVAR(handlePunjiTrapDamage), LINKFUNC(handlePunjiTrapDamage)] call CBA_fnc_addEventHandler; diff --git a/optionals/compat_sog/functions/fnc_handlePunjiTrapDamage.sqf b/optionals/compat_sog/functions/fnc_handlePunjiTrapDamage.sqf index 241fdd8adfa..3ccc1bf47f0 100644 --- a/optionals/compat_sog/functions/fnc_handlePunjiTrapDamage.sqf +++ b/optionals/compat_sog/functions/fnc_handlePunjiTrapDamage.sqf @@ -5,6 +5,7 @@ * * Arguments: * 0: Punji trap + * 1: Affected units * * Return Value: * None @@ -14,16 +15,10 @@ * * Public: No */ -params ["_trap"]; +params ["_trap", "_affectedUnits"]; -if (!(["ACE_Medical"] call EFUNC(common,isModLoaded))) exitWith {}; - -private _radius = getNumber (configOf _trap >> "indirectHitRange"); -private _affectedUnits = (_trap nearEntities ["CAManBase", _radius]) select {local _x} select {isDamageAllowed _x}; (getShotParents _trap) params ["", "_instigator"]; -if (_affectedUnits isEqualTo []) exitWith {}; - private _bodyParts = []; private _stabCount = 0; @@ -49,4 +44,4 @@ switch (typeOf _trap select [0, 16]) do { for "_i" from 0 to _stabCount do { [_x, random [1, 2, 3], selectRandom _bodyParts, "stab", _instigator] call EFUNC(medical,addDamageToUnit); }; -} forEach _affectedUnits; +} forEach _affectedUnits select {isDamageAllowed _x}; // isDamageAllowed already does local check diff --git a/optionals/compat_sog/functions/fnc_handlePunjiTrapTrigger.sqf b/optionals/compat_sog/functions/fnc_handlePunjiTrapTrigger.sqf new file mode 100644 index 00000000000..1e891ee5b8f --- /dev/null +++ b/optionals/compat_sog/functions/fnc_handlePunjiTrapTrigger.sqf @@ -0,0 +1,25 @@ +#include "script_component.hpp" +/* + * Author: GhostIsSpooky + * Handler for 'detonation' of a local punji trap. Workaround for local-only ammo hit event. + * + * Arguments: + * 0: Punji trap + * + * Return Value: + * None + * + * Example: + * [trap] call ace_compat_sog_fnc_handlePunjiTrapTrigger + * + * Public: No + */ +params ["_trap"]; +if (!(["ACE_Medical"] call EFUNC(common,isModLoaded))) exitWith {}; + +private _radius = getNumber (configOf _trap >> "indirectHitRange"); +private _affectedUnits = (_trap nearEntities ["CAManBase", _radius]); + +if (_affectedUnits isEqualTo []) exitWith {}; + +[QGVAR(handlePunjiTrapDamage), [_trap, _affectedUnits], _affectedUnits] call CBA_fnc_targetEvent;