Skip to content

Commit

Permalink
Medical Engine - Fix unit instakill on vehicle explosion (acemod#10542)
Browse files Browse the repository at this point in the history
* Medical Engine - Fix unit instakill on vehicle explosion

* format, missing ;

* use unit itself as blocker

Co-authored-by: PabstMirror <[email protected]>

* fix condition

* actually fix it

* shoot me! right in the face!

---------

Co-authored-by: PabstMirror <[email protected]>
  • Loading branch information
LinkIsGrim and PabstMirror authored Dec 20, 2024
1 parent c3c32e0 commit a2e3e68
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions addons/medical_engine/functions/fnc_handleDamage.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
*
* Public: No
*/

#define INSTAKILL_BLOCKED(unit) (unit isEqualTo (unit getVariable [QGVAR(blockInstaKill), objNull]))

params ["_unit", "_selection", "_damage", "_shooter", "_ammo", "_hitPointIndex", "_instigator", "_hitpoint", "_directHit", "_context"];

// HD sometimes triggers for remote units - ignore.
Expand All @@ -35,13 +38,25 @@ if !(isDamageAllowed _unit && {_unit getVariable [QEGVAR(medical,allowDamage), t
// Killing units via End key is an edge case (#10375)
// This didn't matter pre-Arma 3 2.18 but now this goes through the event handler
// TODO: Structural fire damage >= 1 in a single damage event could still be caught here and we don't want that, but we haven't found a better way to catch this, fire damage should be small most of the time anyway
// Also triggers for catastrophic vehicle explosions which would kill crew outright, check for blocking
private _newDamage = _damage - _oldDamage;
if (_structuralDamage && {(abs (_newDamage - 1)) < 0.001 && _ammo == "" && isNull _shooter && isNull _instigator}) exitWith {_damage};
if (_structuralDamage && {(abs (_newDamage - 1)) < 0.001 && _ammo == "" && isNull _shooter && isNull _instigator} && {!INSTAKILL_BLOCKED(_unit)}) exitWith {
TRACE_1("unit killed by curator or engine",_unit);

_damage
};

// _newDamage == 0 happens occasionally for vehiclehit events (see line 80 onwards), just exit early to save some frametime
// context 4 is engine "bleeding". For us, it's just a duplicate event for #structural which we can ignore without any issues
// Leverage this to block insta-kills on the same frame (see above)
if (_context != 2 && {_context == 4 || _newDamage == 0}) exitWith {
TRACE_4("Skipping engine bleeding or zero damage",_ammo,_newDamage,_directHit,_context);
TRACE_4("Skipping engine bleeding or zero damage, blocking insta kills until next frame",_ammo,_newDamage,_directHit,_context);

if (!INSTAKILL_BLOCKED(_unit)) then {
_unit setVariable [QGVAR(blockInstaKill), _unit];
[{_this setVariable [QGVAR(blockInstaKill), nil]}, _unit] call CBA_fnc_execNextFrame;
};

_oldDamage
};

Expand Down

0 comments on commit a2e3e68

Please sign in to comment.