From a2e3e6822fa7905ca031b1ea4dfb241ab4133411 Mon Sep 17 00:00:00 2001 From: Grim <69561145+LinkIsGrim@users.noreply.github.com> Date: Fri, 20 Dec 2024 01:44:55 -0300 Subject: [PATCH] Medical Engine - Fix unit instakill on vehicle explosion (#10542) * Medical Engine - Fix unit instakill on vehicle explosion * format, missing ; * use unit itself as blocker Co-authored-by: PabstMirror * fix condition * actually fix it * shoot me! right in the face! --------- Co-authored-by: PabstMirror --- .../functions/fnc_handleDamage.sqf | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/addons/medical_engine/functions/fnc_handleDamage.sqf b/addons/medical_engine/functions/fnc_handleDamage.sqf index cf891f5e532..7a037bd979e 100644 --- a/addons/medical_engine/functions/fnc_handleDamage.sqf +++ b/addons/medical_engine/functions/fnc_handleDamage.sqf @@ -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. @@ -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 };