From 3b62af6131293bd37a53a287a0655291fc38359c Mon Sep 17 00:00:00 2001 From: GhostIsSpooky <69561145+Salluci@users.noreply.github.com> Date: Mon, 7 Mar 2022 15:25:55 -0300 Subject: [PATCH] SOG Compat - Fix remote punji traps not causing damage (#8755) * Initial commit * derp * fix derp * fix derp again * don't code without coffee * damage locality is weird, bi pls fix * Update fnc_handlePunjiTrapTrigger.sqf Co-authored-by: PabstMirror --- optionals/compat_sog/CfgAmmo/explosives.hpp | 4 +-- optionals/compat_sog/CfgEventHandlers.hpp | 6 +++++ optionals/compat_sog/XEH_PREP.hpp | 1 + optionals/compat_sog/XEH_postInit.sqf | 1 + .../functions/fnc_handlePunjiTrapDamage.sqf | 11 +++----- .../functions/fnc_handlePunjiTrapTrigger.sqf | 25 +++++++++++++++++++ 6 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 optionals/compat_sog/XEH_postInit.sqf create mode 100644 optionals/compat_sog/functions/fnc_handlePunjiTrapTrigger.sqf diff --git a/optionals/compat_sog/CfgAmmo/explosives.hpp b/optionals/compat_sog/CfgAmmo/explosives.hpp index e2a71e4ae1..44cb68fc13 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 ad6f4e3740..fc6d80fc5f 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 0b86f42702..e71665db09 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 0000000000..fbbbe73d9f --- /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 241fdd8adf..3ccc1bf47f 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 0000000000..1e891ee5b8 --- /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;