Move the dead body cleanup PFH to a loop using waitAndExecute

This commit is contained in:
esteldunedain 2016-02-28 23:33:51 -03:00
parent 90a54397ae
commit 9e682253f3
3 changed files with 34 additions and 17 deletions

View File

@ -18,6 +18,7 @@ PREP(addUnconsciousCondition);
PREP(addUnloadPatientActions);
PREP(addVitalLoop);
PREP(adjustPainLevel);
PREP(bodyCleanupLoop);
PREP(canAccessMedicalEquipment);
PREP(canTreat);
PREP(canTreatCached);

View File

@ -0,0 +1,30 @@
/*
* Author: Glowbal, esteldunedain
* Loop that cleans up litter
*
* Arguments:
* None
*
* ReturnValue:
* None
*
* Public: No
*/
#include "script_component.hpp"
{
TRACE_2("body",_x,isPlayer _x);
if ((!isNull _x) && {!isPlayer _x}) then {deleteVehicle _x};
} forEach GVAR(bodiesToDelete);
// deleteVehicle doesn't have instant results so it won't usualy be filtered until next run
GVAR(bodiesToDelete) = GVAR(bodiesToDelete) - [objNull];
// If no more bodies remain, exit the loop
if (GVAR(bodiesToDelete) isEqualTo []) exitWith {
TRACE_1("array emptied - rem PFEH",GVAR(bodiesToDelete));
};
// Schedule the loop to be executed again 20 sec later
[DFUNC(bodyCleanupLoop), [], 20] call EFUNC(common,waitAndExecute);

View File

@ -26,23 +26,9 @@ TRACE_2("",_target,isPlayer _target);
if (isNil QGVAR(bodiesToDelete)) then {GVAR(bodiesToDelete) = [];};
GVAR(bodiesToDelete) pushBack _target;
//Start up PFEH to wait for bodies to be free to delete
if ((count GVAR(bodiesToDelete)) == 1) then {
TRACE_1("starting PFEH",GVAR(bodiesToDelete));
[{
{
TRACE_2("body",_x,isPlayer _x);
if ((!isNull _x) && {!isPlayer _x}) then {deleteVehicle _x};
} forEach GVAR(bodiesToDelete);
//deleteVehicle doesn't have instant results so it won't usualy be filtered until next run
GVAR(bodiesToDelete) = GVAR(bodiesToDelete) - [objNull];
if (GVAR(bodiesToDelete) isEqualTo []) then {
TRACE_1("array emptied - rem PFEH",GVAR(bodiesToDelete));
[_this select 1] call CBA_fnc_removePerFrameHandler;
};
}, 20, []] call CBA_fnc_addPerFrameHandler;
// Start up a loop to wait for bodies to be free to delete
if ((count GVAR(bodiesToDelete)) > 0) then {
[] call FUNC(bodyCleanupLoop);
};
nil