Cette fonction fait patrouiller un groupe.
La patrouille peut être effectuée par :
call compile preprocessFile "r3f_fnct_patrol.sqf";
//start_fnct_patrol.sqf private ["_group","_rayon"]; _group = _this select 0; _rayon = _this select 1; sleep 0.1; [_group, _rayon] spawn R3F_FNCT_Patrol;
Et que l'on va lancer, avec la ligne de commande dans l'init de l'unité sous l'éditeur de mission, en passant les paramètres nécessaires, this (ou nom de l'unité) et le rayon (ici ex: 200) :
null = [this,200] execVM "start_fnct_patrol.sqf";
R3F_FNCT_Patrol = { private ["_group","_radius","_center","_wp","_near_roads"]; _group = _this select 0; if (typeName _group != "GROUP") exitWith {}; _radius = _this select 1; _center = getPos (leader _group); _wp = _group addWaypoint [_center,_radius]; _wp setWaypointCompletionRadius 30; if (side _group == civilian) then {_wp setWaypointBehaviour "CARELESS";} else {_wp setWaypointBehaviour "SAFE";}; _wp setWaypointType "MOVE"; _wp setWaypointSpeed "LIMITED"; if ({vehicle _x != _x} count units _group > 0) then { _wp setWaypointFormation "FILE"; _wp setWaypointTimeout [0,0,0]; } else { _wp setWaypointFormation "COLUMN"; _wp setWaypointTimeout [0,15,30]; }; _near_roads = _center nearRoads _radius; _group setVariable ["WP_POS",_center,true]; _group setVariable ["WP_RADIUS",_radius,true]; _group setVariable ["WP_ROADS",_near_roads,true]; _wp setWaypointStatements ["true"," [this] call R3F_FNCT_WPFindPos; [this] spawn { private [""_wp"",""_group"",""_driver"",""_vehicle"",""_damage""]; _wp = _this select 0; _group = group _wp; { _vehicle = vehicle _x; if (_vehicle != _x) then { _damage = damage _vehicle; sleep 15; if (alive _vehicle) then { _vehicle setDamage _damage; if (fuel _vehicle < 0.25) then { _vehicle setFuel 0.25; }; }; }; } forEach units _group; }; "]; }; R3F_FNCT_WPFindPos = { private ["_wp","_group","_center","_radius","_near_roads","_nb_roads","_vehicle","_pos"]; _wp = _this select 0; _group = group _wp; _center = _group GetVariable "WP_POS"; _radius = _group GetVariable "WP_RADIUS"; _near_roads = _group GetVariable "WP_ROADS"; _nb_roads = count _near_roads; _vehicle = false; { if (vehicle _x != _x) then { _vehicle = true; }; } forEach units _group; if ((_vehicle) && (_nb_roads > 5) && (_radius > 200)) then { _pos = getpos (_near_roads select (floor (random _nb_roads))); } else { _pos = [_center,10,_radius,5,0,60 * (pi/180),0] call BIS_fnc_findSafePos; if ((!_vehicle) && (random 1 > 0.2)) then { private ["_array","_count","_i"]; _array = [_pos,50] call R3F_FNCT_BuildingPos; _count = count _array; if (_count > 0) then { _i = floor (random _count); _pos = _array select _i; }; }; }; if (!(isNull _group)) then { [_group, 1] setWaypointPosition [_pos, 0]; true; }; }; R3F_FNCT_BuildingPos = { private ["_pos","_radius","_array_pos","_array","_p","_inside_pos"]; _pos = _this select 0; _radius = _this select 1; _array_pos = []; _array = nearestObjects [_pos,["house"],_radius]; if (count _array > 0) then { { _p = 0; while {_inside_pos = _x buildingPos _p; format ["%1",_inside_pos] != "[0,0,0]"} do { _array_pos set [count _array_pos,_inside_pos]; _p = _p + 1; }; } forEach _array; }; _array_pos };
—- Original : Clint Modification : BeTeP/Mapoule