diff --git a/addons/medical/dev/watchVariable.sqf b/addons/medical/dev/watchVariable.sqf
index 05966d907a..1fa8157fd4 100644
--- a/addons/medical/dev/watchVariable.sqf
+++ b/addons/medical/dev/watchVariable.sqf
@@ -19,12 +19,16 @@
_return pushBack "";
// State:
- private _hasStableVitals = [_unit] call EFUNC(medical_status,hasStableVitals);
private _targetState = [_unit, EGVAR(medical,STATE_MACHINE)] call CBA_statemachine_fnc_getCurrentState;
if (!local _unit) then {_targetState = "NotLocal";};
private _color = switch (_targetState) do {case "Default": {"33FF33"}; case "Injured": {"FF3333"}; case "Unconscious": {"FF8833"}; case "CardiacArrest": {"FF33AA"}; default {"555555"}};
- private _unconcFlag = if IS_UNCONSCIOUS(_unit) then {"[U]"} else {""};
- _return pushBack format ["State: %2 [StableVitals: %3] %4", _color, _targetState, _hasStableVitals, _unconcFlag];
+ _return pushBack format ["State: %2", _color, _targetState];
+ private _hasStableVitals = ["N", "Y"] select ([_unit] call EFUNC(medical_status,hasStableVitals));
+ private _hasStableCondition = ["N", "Y"] select ([_unit] call EFUNC(medical_status,isInStableCondition));
+ private _unconcFlag = if IS_UNCONSCIOUS(_unit) then {"[U]"} else {""};
+ private _timeLeft = _unit getVariable [QEGVAR(medical_statemachine,cardiacArrestTimeLeft), -1];
+ private _cardiactArrestFlag = if IN_CRDC_ARRST(_unit) then {format ["[CA %1]", _timeLeft toFixed 1]} else {""};
+ _return pushBack format ["[StableVitals: %1] [StableCon: %2] %3 %4", _hasStableVitals, _hasStableCondition, _unconcFlag, _cardiactArrestFlag];
// Blood:
private _bloodVolume = GET_BLOOD_VOLUME(_unit);
diff --git a/addons/medical_gui/functions/fnc_onMenuClose.sqf b/addons/medical_gui/functions/fnc_onMenuClose.sqf
index bc65e975fd..a531eca4e8 100644
--- a/addons/medical_gui/functions/fnc_onMenuClose.sqf
+++ b/addons/medical_gui/functions/fnc_onMenuClose.sqf
@@ -18,5 +18,6 @@
if (EGVAR(interact_menu,menuBackground) == 1) then {[QGVAR(id), false] call EFUNC(common,blurScreen)};
if (EGVAR(interact_menu,menuBackground) == 2) then {(uiNamespace getVariable [QEGVAR(interact_menu,menuBackground), displayNull]) closeDisplay 0};
+GVAR(pendingReopen) = false;
GVAR(menuPFH) call CBA_fnc_removePerFrameHandler;
GVAR(menuPFH) = -1;
diff --git a/addons/medical_statemachine/Statemachine.hpp b/addons/medical_statemachine/Statemachine.hpp
index 12a5a01779..8c3e83d5d9 100644
--- a/addons/medical_statemachine/Statemachine.hpp
+++ b/addons/medical_statemachine/Statemachine.hpp
@@ -86,6 +86,7 @@ class ACE_Medical_StateMachine {
};
};
class CardiacArrest {
+ onState = QFUNC(handleStateCardiacArrest);
onStateEntered = QFUNC(enteredStateCardiacArrest);
onStateLeaving = QFUNC(leftStateCardiacArrest);
class DeathAI {
diff --git a/addons/medical_statemachine/XEH_PREP.hpp b/addons/medical_statemachine/XEH_PREP.hpp
index 26595cfb62..8e2725d3da 100644
--- a/addons/medical_statemachine/XEH_PREP.hpp
+++ b/addons/medical_statemachine/XEH_PREP.hpp
@@ -3,6 +3,7 @@ PREP(conditionExecutionDeath);
PREP(enteredStateCardiacArrest);
PREP(enteredStateDeath);
PREP(enteredStateFatalInjury);
+PREP(handleStateCardiacArrest);
PREP(handleStateDefault);
PREP(handleStateInjured);
PREP(handleStateUnconscious);
diff --git a/addons/medical_statemachine/functions/fnc_conditionCardiacArrestTimer.sqf b/addons/medical_statemachine/functions/fnc_conditionCardiacArrestTimer.sqf
index df29c592a1..b28459db53 100644
--- a/addons/medical_statemachine/functions/fnc_conditionCardiacArrestTimer.sqf
+++ b/addons/medical_statemachine/functions/fnc_conditionCardiacArrestTimer.sqf
@@ -17,7 +17,4 @@
params ["_unit"];
-private _startTime = _unit getVariable [QGVAR(cardiacArrestStart), CBA_missionTime];
-private _lifeTime = _unit getVariable [QGVAR(cardiacArrestTime), GVAR(cardiacArrestTime)];
-
-(CBA_missionTime - _startTime) > _lifeTime
+(_unit getVariable [QGVAR(cardiacArrestTimeLeft), -1]) <= 0
diff --git a/addons/medical_statemachine/functions/fnc_enteredStateCardiacArrest.sqf b/addons/medical_statemachine/functions/fnc_enteredStateCardiacArrest.sqf
index f418e38b84..0c5e184029 100644
--- a/addons/medical_statemachine/functions/fnc_enteredStateCardiacArrest.sqf
+++ b/addons/medical_statemachine/functions/fnc_enteredStateCardiacArrest.sqf
@@ -20,10 +20,12 @@ params ["_unit"];
// 10% possible variance in cardiac arrest time
private _time = GVAR(cardiacArrestTime);
-_time = _time + random [_time*-0.1, 0, _time*0.1];
+_time = _time + _time * random [-0.1, 0, 0.1];
-_unit setVariable [QGVAR(cardiacArrestTime), _time];
-_unit setVariable [QGVAR(cardiacArrestStart), CBA_missionTime];
+_unit setVariable [QGVAR(cardiacArrestTimeLeft), _time];
+_unit setVariable [QGVAR(cardiacArrestTimeLastUpdate), CBA_missionTime];
+
+TRACE_3("enteredStateCardiacArrest",_unit,_time,CBA_missionTime);
// Update the unit status to reflect cardiac arrest
[_unit, true] call EFUNC(medical_status,setCardiacArrest);
diff --git a/addons/medical_statemachine/functions/fnc_handleStateCardiacArrest.sqf b/addons/medical_statemachine/functions/fnc_handleStateCardiacArrest.sqf
new file mode 100644
index 0000000000..b9e49adfe3
--- /dev/null
+++ b/addons/medical_statemachine/functions/fnc_handleStateCardiacArrest.sqf
@@ -0,0 +1,37 @@
+#include "script_component.hpp"
+/*
+ * Author: BaerMitUmlaut
+ * Handles the unconscious state
+ *
+ * Arguments:
+ * 0: The Unit