2015-01-18 21:16:35 +00:00
/**
* fn_setCardiacArrest.sqf
* @Descr: Triggers a unit into the Cardiac Arrest state from CMS. Will put the unit in an unconscious state and run a countdown timer until unit dies. <br />Timer is a random value between 120 and 720 seconds.
* @Author: Glowbal
*
* @Arguments: [unit OBJECT (The unit that will be put in cardiac arrest state)]
* @Return: void
* @PublicAPI: true
*/
#include "script_component.hpp"
private ["_unit", "_modifier","_timer","_counter", "_heartRate"];
_unit = _this select 0;
if (_unit getvariable [QGVAR(inCardiacArrest),false]) exitwith {};
[format["%1 is put into cardiac arrest",_unit]] call EFUNC(common,debug);
_unit setvariable [QGVAR(inCardiacArrest), true,true];
[_unit,QGVAR(heartRate), 0] call EFUNC(common,setDefinedVariable);
["Medical_onEnteredCardiacArrest", [_unit]] call ace_common_fnc_localEvent;
2015-01-25 15:40:47 +00:00
[_unit] call FUNC(setUnconsciousState);
2015-01-18 21:16:35 +00:00
_counter = 120 + round(random(600));
_timer = 0;
2015-01-25 14:41:29 +00:00
[{
2015-01-25 15:40:47 +00:00
private ["_args","_unit","_timer","_counter","_heartRate"];
2015-01-25 14:41:29 +00:00
_args = _this select 0;
_unit = _args select 0;
_timer = _args select 1;
_counter = _args select 2;
2015-01-18 21:16:35 +00:00
_heartRate = [_unit,QGVAR(heartRate)] call EFUNC(common,getDefinedVariable);
2015-01-25 14:41:29 +00:00
if (_heartRate > 0 || !alive _unit) exitwith {
2015-01-18 21:16:35 +00:00
_unit setvariable [QGVAR(inCardiacArrest), nil,true];
2015-01-25 14:41:29 +00:00
[(_this select 1)] call cba_fnc_removePerFrameHandler;
2015-01-18 21:16:35 +00:00
};
if (_counter - _timer < 1) exitwith {
2015-01-25 15:40:47 +00:00
2015-01-18 21:16:35 +00:00
[_unit] call FUNC(setDead);
2015-01-25 14:41:29 +00:00
[(_this select 1)] call cba_fnc_removePerFrameHandler;
_unit setvariable [QGVAR(inCardiacArrest), nil,true];
2015-01-18 21:16:35 +00:00
};
2015-01-25 14:41:29 +00:00
_args set[1, _timer + 1];
}, 1, [_unit, _timer, _counter] ] call CBA_fnc_addPerFrameHandler;
2015-01-18 21:16:35 +00:00