Search the Community
Showing results for tags 'for a while'.
Found 1 result
-
Ideas for a script to remove AI units when they've been stuck for a while
Crazy_Man posted a topic in ARMA 3 - MISSION EDITING & SCRIPTING
Hi all, I'm interested in a script that would detect AI units that get stuck for a while and are not in combat. If you have good ideas on the subject, don't hesitate to post them. I am creating a mission where, once a city is taken, reinforcements are spawned at random and secure positions and must reach the city. So I don't want to be bothered by vehicles stuck on the way slowing the reinforcements, I prefer to delete them if they are not in combat. for the moment, I've this: if (!isServer) exitWith {}; timeIdle = 60*10; // 10 minutes //timeIdle = 30; // TEST !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! mission_fnc_idle = { params ["_gr"]; //{_x disableAI "PATH"} forEach units _gr; // TEST !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! _distToDelete = 5; // Get all group's vehicle(s) _vehs = [_gr, true] call BIS_fnc_groupVehicles; // initialize vars {if (alive _x) then {_x setVariable ["idlePos", position _x]}} forEach units _gr; _timeOut = time + timeIdle; // MAIN LOOP while {{alive _x} count units _gr > 0} do { sleep 5; if (isNil "_gr" or {{alive _x} count units _gr < 1}) exitWith {}; // CHECK IDLE UNITS if ({alive _x} count units _gr > 0 and _timeOut < time) then { _units = []; _unitsToDelete = []; _vehsToDelete = []; // get all units near their idle position {if (alive _x and _x distance (_x getVariable "idlePos") < _distToDelete) then {_units pushBackUnique _x}} forEach units _gr; { // if unit in vehicle if (vehicle _x != _x) then { _veh = vehicle _x; if (!((crew _veh) call mission_fnc_isEngaging)) then { {_unitsToDelete pushBackUnique _x} forEach crew _veh; _vehsToDelete = _vehsToDelete + [_veh]; }; }; // if unit not in vehicle if (vehicle _x == _x and !(_x call mission_fnc_isEngaging)) then { _unitsToDelete pushBackUnique _x; }; } forEach _units; // delete idle units and vehicles {deleteVehicle _x} forEach _unitsToDelete + _vehsToDelete; // reset vars {if (alive _x) then {_x setVariable ["idlePos", position _x]}} forEach units _gr; _timeOut = time + timeIdle; }; }; }; // Thanks to rübe mission_fnc_isEngaging = { /* Author: rübe Description: returns true if anybody of the given unit(s)/group is engaging Parameter(s): _this: unit(s)/group (unit, array of units or group) Returns: boolean */ private ["_units", "_engaging"]; _units = []; _engaging = false; switch (true) do { case ((typeName _this) == "ARRAY"): { _units = _this; }; case ((typeName _this) == "GROUP"): { _units = units _this; }; default { _units = [_this]; }; }; { if ((currentCommand _x) in ["ATTACK", "ATTACKFIRE", "FIRE"]) exitWith { _engaging = true; }; } forEach _units; // return status _engaging };