ACE3/addons/medical_status/functions/fnc_setUnconsciousState.sqf
johnb432 682ae05f59
Medical Status - Remove status effects upon death/featureCamera (#9301)
* Update fnc_handleKilled.sqf

* move to function

* Removed skipSetHidden

* Revert "Removed skipSetHidden"

This reverts commit 452c5216a7.

* Update addons/medical_status/XEH_postInit.sqf

* add comment, force git to run actions

---------

Co-authored-by: LinkIsGrim <salluci.lovi@gmail.com>
Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com>
2023-08-18 13:16:20 -04:00

74 lines
2.5 KiB
Plaintext

#include "script_component.hpp"
/*
* Author: Glowbal
* Sets a unit in the unconscious state.
* For Internal Use: Called from the state machine.
*
* Arguments:
* 0: The unit that will be put in an unconscious state <OBJECT>
* 1: Set unconscious <BOOL>
*
* Return Value:
* None
*
* Example:
* [player, true] call ace_medical_status_fnc_setUnconsciousState
*
* Public: No
*/
params ["_unit", "_active"];
TRACE_2("setUnconsciousState",_unit,_active);
// No change to make
if (_active isEqualTo IS_UNCONSCIOUS(_unit) || {!alive _unit}) exitWith { TRACE_2("no change",_active,IS_UNCONSCIOUS(_unit)); };
_unit setVariable [VAR_UNCON, _active, true];
// Toggle unit ragdoll state
[_unit, _active] call EFUNC(medical_engine,setUnconsciousAnim);
// Handle hiding from AI and talking blocks.
[_unit, _active] call FUNC(setStatusEffects);
if (_active) then {
// Don't bother setting this if not used
if (EGVAR(medical,spontaneousWakeUpChance) > 0) then {
private _lastWakeUpCheck = _unit getVariable [QEGVAR(medical,lastWakeUpCheck), 0]; // could be set higher from ace_medical_fnc_setUnconscious
TRACE_2("setting lastWakeUpCheck to max of",_lastWakeUpCheck,CBA_missionTime);
_unit setVariable [QEGVAR(medical,lastWakeUpCheck), _lastWakeUpCheck max CBA_missionTime];
};
if (_unit == ACE_player) then {
if (visibleMap) then {openMap false};
while {dialog} do {
closeDialog 0;
};
};
// Unlock controls for copilot if unit is pilot of aircraft
if (vehicle _unit isKindOf "Air" && {_unit == driver vehicle _unit}) then {
TRACE_1("pilot of air vehicle - unlocking controls",vehicle _unit);
// Do "Unlock controls" user action, co-pilot will then have to do the "Take Controls" actions
_unit action ["UnlockVehicleControl", vehicle _unit];
};
// Disable AI aiming
if (!isPlayer _unit && {_unit checkAIFeature "WEAPONAIM"}) then {
_unit disableAI "WEAPONAIM";
_unit setVariable [QGVAR(reenableWeaponAim), true, true];
};
} else {
// Unit has woken up, no longer need to track this
_unit setVariable [QEGVAR(medical,lastWakeUpCheck), nil];
// Reenable AI aiming
if (_unit getVariable [QGVAR(reenableWeaponAim), false]) then {
_unit enableAI "WEAPONAIM";
};
};
// This event doesn't correspond to unconscious in statemachine
// It's for any time a unit changes consciousness (including cardiac arrest)
["ace_unconscious", [_unit, _active]] call CBA_fnc_globalEvent;