ACE3/addons/medical_statemachine/functions/fnc_handleStateCardiacArrest.sqf
GhostIsSpooky 9209fedcf7
Medical Statemachine - Improve edge case death handling (#8788)
* fix #8772

* add WARNING for dead/null units

* fix macro

* improve warnings

* handle scripted death without warnings

Co-authored-by: PabstMirror <pabstmirror@gmail.com>

Co-authored-by: PabstMirror <pabstmirror@gmail.com>
2022-03-07 12:28:51 -06:00

36 lines
1.1 KiB
Plaintext

#include "script_component.hpp"
/*
* Author: BaerMitUmlaut
* Handles the unconscious state
*
* Arguments:
* 0: The Unit <OBJECT>
*
* Return Value:
* None
*
* Example:
* [player] call ace_medical_statemachine_fnc_handleStateCardiacArrest
*
* Public: No
*/
params ["_unit"];
// If the unit died the loop is finished
if (!alive _unit || {!local _unit}) exitWith {};
[_unit] call EFUNC(medical_vitals,handleUnitVitals);
private _timeDiff = CBA_missionTime - (_unit getVariable [QGVAR(cardiacArrestTimeLastUpdate), 0]);
if (_timeDiff >= 1) then {
_timeDiff = _timeDiff min 10;
_unit setVariable [QGVAR(cardiacArrestTimeLastUpdate), CBA_missionTime];
private _recieveingCPR = alive (_unit getVariable [QEGVAR(medical,CPR_provider), objNull]);
private _timeLeft = _unit getVariable [QGVAR(cardiacArrestTimeLeft), -1];
TRACE_3("cardiac arrest life tick",_unit,_recieveingCPR,_timeDiff);
if (_recieveingCPR) then { _timeDiff = _timeDiff * 0.5; }; // if being cpr'ed, then time decrease is reduced
_timeLeft = _timeLeft - _timeDiff; // negative values are fine
_unit setVariable [QGVAR(cardiacArrestTimeLeft), _timeLeft];
};