Changed setDead to no longer use spawn.

This commit is contained in:
Thomas Kooi 2015-01-17 13:35:15 +01:00
parent d42b83947d
commit a8e257f7ab
2 changed files with 62 additions and 71 deletions

View File

@ -136,7 +136,7 @@ GVAR(OldPlayerTurret) = [ACE_player] call FUNC(getTurretIndex);
}, 0, []] call cba_fnc_addPerFrameHandler;
[QGVAR(ENABLE_REVIVE_COUNTER), 0, false, QGVAR(ADDON)] call FUNC(defineVariable);
[QGVAR(reviveCounter_f), 0, false, QGVAR(ADDON)] call FUNC(defineVariable);
[QGVAR(inReviveState), false, true, QGVAR(ADDON)] call FUNC(defineVariable);
[QGVAR(isDead),false,true,QUOTE(ADDON)] call FUNC(defineVariable);
[QGVAR(isDeadPlayer), false, true, QUOTE(ADDON)] call FUNC(defineVariable);
@ -147,4 +147,9 @@ GVAR(OldPlayerTurret) = [ACE_player] call FUNC(getTurretIndex);
if (isNil QGVAR(ENABLE_REVIVE_F)) then {
GVAR(ENABLE_REVIVE_F) = 0;
};
};
[
{((_this select 0) getvariable [QGVAR(inReviveState), false])}
] call EFUNC(common,registerUnconsciousCondition);

View File

@ -10,6 +10,8 @@
#include "script_component.hpp"
#define TIME_BETWEEN_REVIVE_RUNS 0.5
private ["_unit"];
_unit = _this select 0;
_force = false;
@ -20,83 +22,67 @@ if (count _this >= 2) then {
if (!alive _unit) exitwith{};
if (!local _unit) exitwith {
[[_unit, _force], QUOTE(FUNC(setDead)), _unit, false] call BIS_fnc_MP;
diag_log format["WARNING: ace_common_fnc_setDead triggered on non local unit %1", _unit];
};
if (isnil QGVAR(ENABLE_REVIVE_F)) then {
GVAR(ENABLE_REVIVE_F) = 0;
};
_name = _unit getvariable QGVAR(name);
if (isnil "_name") then {
_unit setvariable [QGVAR(name), name _unit, true];
};
if (((GVAR(ENABLE_REVIVE_F) == 1 && isPlayer _unit) || (GVAR(ENABLE_REVIVE_F) == 2)) && !_force) then {
[format["GVAR(ENABLE_REVIVE_F) %1",_unit]] call FUNC(debug);
_unit spawn {
private ["_unit","_counter"];
_unit = _this;
_playerDead = isPlayer _unit;
if (((GVAR(ENABLE_REVIVE_F) == 1 && isPlayer _unit) || (GVAR(ENABLE_REVIVE_F) == 2)) && !_force && (alive (vehicle _unit))) exitwith {
// enter revive state
_unit setvariable [QGVAR(inReviveState), true, true];
if ((_unit getvariable[QGVAR(ENABLE_REVIVE_SETDEAD_F),0]) > 0) exitwith {
_unit setvariable[QGVAR(ENABLE_REVIVE_SETDEAD_F),(_unit getvariable[QGVAR(ENABLE_REVIVE_SETDEAD_F),0]) + 1];
};
_unit setvariable[QGVAR(ENABLE_REVIVE_SETDEAD_F),1];
[_unit] call FUNC(setUnconsciousState);
if (isnil QGVAR(REVIVE_TIMER_F)) then {
GVAR(REVIVE_TIMER_F) = 10;
};
if (isnil QGVAR(REVIVE_NUMBER_MAX_F)) then {
GVAR(REVIVE_NUMBER_MAX_F) = -1;
};
waituntil {([_unit] call FUNC(isUnconscious))};
_counter = 0;
if (alive (vehicle _unit)) then {
_unit setvariable [QGVAR(inReviveState), true, true];
while {([_unit] call FUNC(isUnconscious))} do {
_counter = _unit getvariable [QGVAR(ENABLE_REVIVE_COUNTER),_counter];
if (_counter > GVAR(REVIVE_TIMER_F) || (((_unit getvariable[QGVAR(ENABLE_REVIVE_SETDEAD_F),0]) > GVAR(REVIVE_NUMBER_MAX_F)) && (GVAR(REVIVE_NUMBER_MAX_F) > 0))) exitwith{
if (_counter > GVAR(REVIVE_TIMER_F)) then {
[format["Timer ran out for %1",_unit]] call FUNC(debug);
};
if (((_unit getvariable[QGVAR(ENABLE_REVIVE_SETDEAD_F),0]) > GVAR(REVIVE_NUMBER_MAX_F)) && (GVAR(REVIVE_TIMER_F) > 0)) then {
[format["amount of calls for setDead ran out for %1",_unit]] call FUNC(debug);
};
if (isPlayer _unit) then {
titleText ["You died..","PLAIN DOWN"];
};
[format["ace_isDead %1",_unit]] call FUNC(debug);
[_unit,QGVAR(isDead),true,true] call FUNC(setDefinedVariable);
if (_playerDead) then {
[_unit,QGVAR(isDeadPlayer),true,true] call FUNC(setDefinedVariable);
};
_unit setdamage 1;
[[_unit, true],"killed"] call FUNC(raiseScriptedEvent_f);
};
sleep 1;
_unit setvariable [QGVAR(ENABLE_REVIVE_COUNTER),_counter + 1];
_counter = _counter + 1;
};
// Remain unconscious while in revive state
[_unit] call FUNC(setUnconsciousState);
// setting the revive default values
if (isnil QGVAR(REVIVE_TIMER_F)) then {
GVAR(REVIVE_TIMER_F) = 10;
};
if (isnil QGVAR(REVIVE_NUMBER_MAX_F)) then {
GVAR(REVIVE_NUMBER_MAX_F) = -1;
};
[{
private ["_unit","_playerDead","_counter"];
_unit = (_this select 0) select 0;
_playerDead = (_this select 0) select 1;
// Check if a unit woke up or was already killed
if (!([_unit] call FUNC(isUnconscious)) || !alive _unit) exitwith {
[(_this select 1)] call cba_fnc_removePerFrameHandler;
// Cleaning up the variables, as we no longer need them.
_unit setvariable [QGVAR(reviveCounter_f), nil];
_unit setvariable [QGVAR(inReviveState), nil, true];
[format["no longer unconscious %1",_unit]] call FUNC(debug);
} else {
};
_counter = _unit getvariable [QGVAR(reviveCounter_f), 0];
if (_counter >= GVAR(REVIVE_TIMER_F)) exitwith{
if (isPlayer _unit) then {
titleText ["You died..","PLAIN DOWN"];
};
[_unit,QGVAR(isDead),true,true] call FUNC(setDefinedVariable);
_unit setdamage 1;
[[_unit, false],"killed"] call FUNC(raiseScriptedEvent_f);
};
};
} else {
[format["INSTANT KILL %1",_unit]] call FUNC(debug);
if (isPlayer _unit) then {
titleText ["You died..","PLAIN DOWN"];
};
if (isPLayer _unit) then {
[_unit,QGVAR(isDeadPlayer),true,true] call FUNC(setDefinedVariable);
};
_unit setdamage 1;
[_unit,QGVAR(isDead),true,true] call FUNC(setDefinedVariable);
[_unit,QGVAR(isDead), true, true] call FUNC(setDefinedVariable);
if (_playerDead) then {
[_unit,QGVAR(isDeadPlayer),true,true] call FUNC(setDefinedVariable);
};
[[_unit, false],"killed"] call FUNC(raiseScriptedEvent_f);
};
_unit setdamage 1; // killing a unit will automatically clean up all variables.
[[_unit, true],"killed"] call FUNC(raiseScriptedEvent_f);
[(_this select 1)] call cba_fnc_removePerFrameHandler;
};
_unit setvariable [QGVAR(reviveCounter_f),_counter + TIME_BETWEEN_REVIVE_RUNS];
}, TIME_BETWEEN_REVIVE_RUNS, [_unit, isPlayer _unit] ] call CBA_fnc_addPerFrameHandler;
};
[_unit,QGVAR(isDead),true,true] call FUNC(setDefinedVariable);
if (isPLayer _unit) then {
[_unit,QGVAR(isDeadPlayer),true,true] call FUNC(setDefinedVariable);
};
_unit setdamage 1;
[[_unit, false],"killed"] call FUNC(raiseScriptedEvent_f);