DMS_Exile/@ExileServer/addons/a3_dms/scripts/fn_TargetsKilled.sqf
2016-01-06 18:38:55 -06:00

56 lines
1.3 KiB
Plaintext

/*
DMS_fnc_TargetsKilled
Created by eraser1
Usage:
[
_unit,
_group,
_object
] call DMS_fnc_TargetsKilled;
Will accept non-array argument of group, unit, or object.
*/
if (_this isEqualTo []) exitWith
{
diag_log "DMS ERROR :: Calling DMS_TargetsKilled with empty array!";
};
private "_killed";
_killed = false;
try
{
{
private ["_lastDistanceCheckTime", "_spawnPos"];
_lastDistanceCheckTime = _x getVariable ["DMS_LastAIDistanceCheck",time];
_pos = getPosWorld _x;
_spawnPos = _x getVariable ["DMS_AISpawnPos",_pos];
if ((DMS_MaxAIDistance>0) && {((time - _lastDistanceCheckTime)>DMS_AIDistanceCheckFrequency) && {(_pos distance2D _spawnPos)>DMS_MaxAIDistance}}) then
{
_x setDamage 1;
diag_log format ["Killed a runaway unit! |%1| was more than %2m away from its spawn position %3!",_x,DMS_MaxAIDistance,_spawnPos];
}
else
{
_x setVariable ["DMS_LastAIDistanceCheck",time];
throw _x;
};
} forEach (_this call DMS_fnc_GetAllUnits); // DMS_fnc_GetAllUnits will return living AI unit objects only, so we only need to check for runaway units
_killed = true;
}
catch
{
if (DMS_DEBUG) then
{
(format ["TargetsKilled :: %1 is still alive! All of %2 are not yet killed!",_exception,_this]) call DMS_fnc_DebugLog;
};
};
_killed;