From 5f8a00a45f78aca54db0b668204c3cce8c7603d0 Mon Sep 17 00:00:00 2001 From: Thomas Kooi Date: Sun, 25 Jan 2015 15:41:29 +0100 Subject: [PATCH] Removed last remaining spawns and sleeps in medical. --- ...handleTreatment_Action_MedicationLocal.sqf | 33 ++++++++++++------- .../functions/fnc_setCardiacArrest.sqf | 20 +++++++---- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/addons/medical/functions/fnc_handleTreatment_Action_MedicationLocal.sqf b/addons/medical/functions/fnc_handleTreatment_Action_MedicationLocal.sqf index 4b0010f513..d10bce389a 100644 --- a/addons/medical/functions/fnc_handleTreatment_Action_MedicationLocal.sqf +++ b/addons/medical/functions/fnc_handleTreatment_Action_MedicationLocal.sqf @@ -72,24 +72,35 @@ if (count _attributes > 1) then { if (_totalUsed > 10) then { [_target] call EFUNC(common,setDead); }; + _wearOff = _wearOff + (round(random(30))); + + [{ + _target = _this select 0; + _wearOff = _this select 1; + _var = _this select 2; - [_target,_wearOff,_var] spawn { - sleep ((_this select 1) + (round(random(30)))); _amountDecreased = 0; _usedMed = [_this select 0, _this select 2] call EFUNC(common,getDefinedVariable); if (typeName _usedMed != typeName 0) then { _usedMed = 0; }; - while {(_usedMed > 0.000000 && _amountDecreased < 1.000000)} do { - _usedMed = ([_this select 0, _this select 2] call EFUNC(common,getDefinedVariable)); - if ( typeName _usedMed != typeName 0) then { - _usedMed = 0; - }; - [_this select 0, _this select 2,_usedMed - 0.001] call EFUNC(common,setDefinedVariable); - _amountDecreased = _amountDecreased + 0.001; - sleep 1; + + if (_usedMed > 0) then { + [{ + _args = _this select 0; + _amountDecreased = _args select 3; + _usedMed = ([_args select 0, _args select 2] call EFUNC(common,getDefinedVariable)); + [_args select 0, _args select 2,_usedMed - 0.001] call EFUNC(common,setDefinedVariable); + _amountDecreased = _amountDecreased + 0.001; + + if (_amountDecreased >= 1 || (_usedMed - 0.001 <= 0)) then { + [(_this select 1)] call cba_fnc_removePerFrameHandler; + }; + _args set [3, _amountDecreased]; + }, 1, [_target, _wearOff,_var, 0] ] call CBA_fnc_addPerFrameHandler; }; - }; + }, [_target, _wearOff, _var], _wearOff, _wearOff] call EFUNC(common,waitAndExecute); + }; private ["_heartRate","_pain"]; diff --git a/addons/medical/functions/fnc_setCardiacArrest.sqf b/addons/medical/functions/fnc_setCardiacArrest.sqf index e0e4df20c3..6cc7787c76 100644 --- a/addons/medical/functions/fnc_setCardiacArrest.sqf +++ b/addons/medical/functions/fnc_setCardiacArrest.sqf @@ -23,17 +23,23 @@ _unit setvariable [QGVAR(inCardiacArrest), true,true]; [_unit] call EFUNC(common,setUnconsciousState); _counter = 120 + round(random(600)); _timer = 0; -while {(_timer < _counter && alive _unit)} do { + +[{ + _args = _this select 0; + _unit = _args select 0; + _timer = _args select 1; + _counter = _args select 2; + _heartRate = [_unit,QGVAR(heartRate)] call EFUNC(common,getDefinedVariable); - if (_heartRate > 0) exitwith { - [format["%1 is moved out of cardiac: %2",_unit, _heartRate]] call EFUNC(common,debug); + if (_heartRate > 0 || !alive _unit) exitwith { _unit setvariable [QGVAR(inCardiacArrest), nil,true]; + [(_this select 1)] call cba_fnc_removePerFrameHandler; }; if (_counter - _timer < 1) exitwith { [_unit] call FUNC(setDead); + [(_this select 1)] call cba_fnc_removePerFrameHandler; + _unit setvariable [QGVAR(inCardiacArrest), nil,true]; }; - sleep 1; - _timer = _timer + 1; -}; + _args set[1, _timer + 1]; +}, 1, [_unit, _timer, _counter] ] call CBA_fnc_addPerFrameHandler; -_unit setvariable [QGVAR(inCardiacArrest), nil,true]; \ No newline at end of file