Prevent dead cleanup and script fix

1. Using "_units = blck_liveMissionAI select (_i - 1);" could cause undefined behaviour if removing entries from array inside this loop.
So always deleteat 0, but pushback if delete is not wanted / needed
2. Check first, if the AI is dead. If so, skip cleanup, so players can loot the corpse
This commit is contained in:
He-Man 2018-11-27 17:23:29 +01:00 committed by GitHub
parent 6ed84e53bd
commit 86d55ef119
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -37,31 +37,24 @@ for "_i" from 1 to (count blck_liveMissionAI) do
{ {
if ((_i) <= count blck_liveMissionAI) then if ((_i) <= count blck_liveMissionAI) then
{ {
_units = blck_liveMissionAI select (_i - 1); _units = blck_liveMissionAI deleteat 0;
//diag_log format["_fnc_cleanupAliveAI:: (34) evaluating with delete time = %2 and diag_tickTime %1", diag_tickTime, _units select 1]; _units params ["_unitsarr","_timer"];
if (diag_tickTime > (_units select 1) ) then if (diag_tickTime > _timer) then {
{
//diag_log format["_fnc_cleanupAliveAI:: cleaning up AI group %1",_units];
{ {
if (alive _x) then {
//diag_log format["_fnc_cleanupAliveAI:: deleting unit %1",_x]; if (!isNull objectParent _x) then {
//diag_log format["_fnc_cleanupAliveAI:: vehicle _x = %1",vehicle _x]; [objectParent _x] call blck_fnc_deleteAIvehicle;
//diag_log format["_fnc_cleanupAliveAI:: objectParent _x = %1",objectParent _x]; };
[_x] call blck_fnc_deleteAI;
if ((alive _x) && !(isNull objectParent _x)) then // mark the vehicle for deletion
{
//diag_log format["_fnc_cleanupAliveAI: deleteing objectParent %1 [%3] for unit %2",objectParent _x, _x, typeName (objectParent _x), typeOf (objectParent _x)];
[objectParent _x] call blck_fnc_deleteAIvehicle;
}; };
[_x] call blck_fnc_deleteAI; } forEach _unitsarr;
}forEach (_units select 0);
uiSleep 0.1; uiSleep 0.1;
blck_liveMissionAI set[(_i - 1), -1];
blck_liveMissionAI = blck_liveMissionAI - [-1]; // Remove that list of live AI from the list.
#ifdef blck_debugMode #ifdef blck_debugMode
if (blck_debugLevel > 1) then {diag_log format["_fnc_mainTread:: blck_liveMissionAI updated to %1",blck_liveMissionAI];}; if (blck_debugLevel > 1) then {diag_log format["_fnc_mainTread:: blck_liveMissionAI updated to %1",blck_liveMissionAI];};
#endif #endif
}
else {
blck_liveMissionAI pushback _units;
}; };
}; };
}; };