ACE3/addons/medical/functions/fnc_setDead.sqf

63 lines
1.8 KiB
Plaintext
Raw Normal View History

/*
* Author: Glowbal
* Either kills a unit or puts the unit in a revivable state, depending on the settings.
*
* Arguments:
* 0: The unit that will be killed <OBJECT>
*
* ReturnValue:
* <NIL>
*
* Public: yes
*/
#include "script_component.hpp"
2015-04-03 19:49:46 +00:00
private ["_unit", "_force"];
_unit = _this select 0;
_force = false;
if (count _this >= 2) then {
_force = _this select 1;
};
2015-04-03 19:49:46 +00:00
if (!alive _unit) exitwith{true};
if (!local _unit) exitwith {
[[_unit, _force], QUOTE(DFUNC(setDead)), _unit, false] call EFUNC(common,execRemoteFnc); /* TODO Replace by event system */
2015-04-03 19:49:46 +00:00
false;
};
2015-04-03 19:49:46 +00:00
if ((_unit getVariable [QGVAR(preventDeath), GVAR(preventInstaDeath)]) && !_force) exitwith {
if (_unit getvariable [QGVAR(inReviveState), false]) exitwith {false}; // already in revive state
2015-03-09 21:27:01 +00:00
_unit setvariable [QGVAR(inReviveState), true, true];
2015-04-03 19:49:46 +00:00
_unit setvariable [QGVAR(reviveStartTime), time];
[_unit, true] call FUNC(setUnconscious);
2015-03-09 21:27:01 +00:00
[{
private ["_args","_unit","_startTime"];
_args = _this select 0;
_unit = _args select 0;
2015-04-03 19:49:46 +00:00
_startTime = _unit getvariable [QGVAR(reviveStartTime), 0];
2015-03-09 21:27:01 +00:00
if (time - _startTime > GVAR(maxReviveTime)) exitwith {
[(_this select 1)] call cba_fnc_removePerFrameHandler;
_unit setvariable [QGVAR(inReviveState), nil, true];
2015-04-03 19:49:46 +00:00
_unit setvariable [QGVAR(reviveStartTime), nil];
[_unit, true] call FUNC(setDead);
2015-03-09 21:27:01 +00:00
};
if !(_unit getvariable [QGVAR(inReviveState), false]) exitwith {
2015-04-03 19:49:46 +00:00
_unit setvariable [QGVAR(reviveStartTime), nil];
2015-03-09 21:27:01 +00:00
[(_this select 1)] call cba_fnc_removePerFrameHandler;
};
2015-04-03 19:49:46 +00:00
}, 1, [_unit] ] call CBA_fnc_addPerFrameHandler;
false;
};
_unit setvariable ["ACE_isDead", true, true];
if (isPLayer _unit) then {
_unit setvariable ["isDeadPlayer", true, true];
};
_unit setdamage 1;
2015-04-03 19:49:46 +00:00
true;