2015-02-08 12:18:08 +00:00
|
|
|
/*
|
|
|
|
* 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>
|
2015-11-21 17:11:13 +00:00
|
|
|
* 1: Force Dead (ignore revive setting) <BOOL>
|
|
|
|
* 1: Delay setDamage for a frame <BOOL>
|
2015-02-08 12:18:08 +00:00
|
|
|
*
|
|
|
|
* ReturnValue:
|
2015-11-21 17:11:13 +00:00
|
|
|
* Did he died? <BOOL>
|
2015-02-08 12:18:08 +00:00
|
|
|
*
|
|
|
|
* Public: yes
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-11-21 17:11:13 +00:00
|
|
|
private ["_reviveVal", "_lifesLeft"];
|
|
|
|
params ["_unit", ["_force", false], ["_delaySetDamage", false]];
|
2015-02-08 12:18:08 +00:00
|
|
|
|
2015-11-21 17:11:13 +00:00
|
|
|
if ((!alive _unit) || {_unit getVariable ["ACE_isDead", false]}) exitWith {true};
|
2015-02-08 12:18:08 +00:00
|
|
|
if (!local _unit) exitwith {
|
2015-02-28 12:17:17 +00:00
|
|
|
[[_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-02-08 12:18:08 +00:00
|
|
|
};
|
|
|
|
|
2015-04-29 20:04:46 +00:00
|
|
|
_reviveVal = _unit getVariable [QGVAR(enableRevive), GVAR(enableRevive)];
|
|
|
|
if (((_reviveVal == 1 && {[_unit] call EFUNC(common,isPlayer)} || _reviveVal == 2)) && !_force) exitwith {
|
2015-04-03 21:56:32 +00:00
|
|
|
if (_unit getvariable [QGVAR(inReviveState), false]) exitwith {
|
|
|
|
if (GVAR(amountOfReviveLives) > 0) then {
|
|
|
|
_lifesLeft = _unit getvariable[QGVAR(amountOfReviveLives), GVAR(amountOfReviveLives)];
|
|
|
|
if (_lifesLeft == 0) then {
|
|
|
|
[_unit, true] call FUNC(setDead);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
false;
|
|
|
|
};
|
|
|
|
|
2015-03-09 21:27:01 +00:00
|
|
|
_unit setvariable [QGVAR(inReviveState), true, true];
|
2015-05-21 16:42:44 +00:00
|
|
|
_unit setvariable [QGVAR(reviveStartTime), ACE_time];
|
2015-04-03 19:49:46 +00:00
|
|
|
[_unit, true] call FUNC(setUnconscious);
|
2015-03-09 21:27:01 +00:00
|
|
|
|
|
|
|
[{
|
2015-08-22 17:47:23 +00:00
|
|
|
private "_startTime";
|
|
|
|
params ["_args", "_idPFH"];
|
|
|
|
_args params ["_unit"];
|
2015-04-03 19:49:46 +00:00
|
|
|
_startTime = _unit getvariable [QGVAR(reviveStartTime), 0];
|
2015-03-09 21:27:01 +00:00
|
|
|
|
2015-07-09 11:02:48 +00:00
|
|
|
if (GVAR(maxReviveTime) > 0 && {ACE_time - _startTime > GVAR(maxReviveTime)}) exitwith {
|
2015-08-22 17:47:23 +00:00
|
|
|
[_idPFH] call CBA_fnc_removePerFrameHandler;
|
2015-03-09 21:27:01 +00:00
|
|
|
_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 21:56:32 +00:00
|
|
|
// revived without dieing, so in case we have lifes, remove one.
|
|
|
|
if (GVAR(amountOfReviveLives) > 0) then {
|
|
|
|
_lifesLeft = _unit getvariable[QGVAR(amountOfReviveLives), GVAR(amountOfReviveLives)];
|
|
|
|
_unit setvariable [QGVAR(amountOfReviveLives), _lifesLeft - 1, true];
|
|
|
|
};
|
|
|
|
|
2015-04-03 19:49:46 +00:00
|
|
|
_unit setvariable [QGVAR(reviveStartTime), nil];
|
2015-08-22 17:47:23 +00:00
|
|
|
[_idPFH] call CBA_fnc_removePerFrameHandler;
|
2015-03-09 21:27:01 +00:00
|
|
|
};
|
2015-06-20 10:44:29 +00:00
|
|
|
if (GVAR(level) >= 2) then {
|
|
|
|
if (_unit getvariable [QGVAR(heartRate), 60] > 0) then {
|
|
|
|
_unit setvariable [QGVAR(heartRate), 0];
|
|
|
|
};
|
|
|
|
};
|
2015-04-03 19:49:46 +00:00
|
|
|
}, 1, [_unit] ] call CBA_fnc_addPerFrameHandler;
|
|
|
|
false;
|
2015-02-08 12:18:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
_unit setvariable ["ACE_isDead", true, true];
|
|
|
|
if (isPLayer _unit) then {
|
|
|
|
_unit setvariable ["isDeadPlayer", true, true];
|
|
|
|
};
|
2015-06-06 02:03:27 +00:00
|
|
|
|
2015-06-07 21:52:42 +00:00
|
|
|
["medical_onSetDead", [_unit]] call EFUNC(common,localEvent);
|
2015-06-06 02:03:27 +00:00
|
|
|
|
2015-11-21 17:11:13 +00:00
|
|
|
//Delay a frame before killing the unit via scripted damage
|
|
|
|
//to avoid triggering the "Killed" Event twice (and having the wrong killer)
|
|
|
|
|
|
|
|
if (!_delaySetDamage) then {
|
|
|
|
[_unit, 1] call FUNC(setStructuralDamage);
|
|
|
|
} else {
|
|
|
|
[FUNC(setStructuralDamage), [_unit, 1]] call EFUNC(common,execNextFrame);
|
|
|
|
};
|
|
|
|
|
2015-04-03 19:49:46 +00:00
|
|
|
true;
|