Skip to content

Commit

Permalink
SOG Compat - Fix remote punji traps not causing damage (#8755)
Browse files Browse the repository at this point in the history
* 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 <pabstmirror@gmail.com>
  • Loading branch information
LinkIsGrim and PabstMirror authored Mar 7, 2022
1 parent b1451d7 commit 3b62af6
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 10 deletions.
4 changes: 2 additions & 2 deletions optionals/compat_sog/CfgAmmo/explosives.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};
};
};
Expand All @@ -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));
};
};
};
6 changes: 6 additions & 0 deletions optionals/compat_sog/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions optionals/compat_sog/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
PREP(disableCookoff);
PREP(handlePunjiTrapDamage);
PREP(handlePunjiTrapTrigger);
1 change: 1 addition & 0 deletions optionals/compat_sog/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[QGVAR(handlePunjiTrapDamage), LINKFUNC(handlePunjiTrapDamage)] call CBA_fnc_addEventHandler;
11 changes: 3 additions & 8 deletions optionals/compat_sog/functions/fnc_handlePunjiTrapDamage.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*
* Arguments:
* 0: Punji trap <OBJECT>
* 1: Affected units <ARRAY of OBJECT>
*
* Return Value:
* None
Expand All @@ -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;

Expand All @@ -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
25 changes: 25 additions & 0 deletions optionals/compat_sog/functions/fnc_handlePunjiTrapTrigger.sqf
Original file line number Diff line number Diff line change
@@ -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 <OBJECT>
*
* 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;

0 comments on commit 3b62af6

Please sign in to comment.