Jump to content
Sign in to follow this  
clydefrog

Spawning vehicles that will perform a random patrol

Recommended Posts

Hi, I already have a script that I use to spawn an infantry group on a marker through a trigger, it uses the CBA task patrol function to give the created infantry group some waypoints and sets the combat mode etc. I am looking for basically the same thing but for vehicles, so I could spawn say 3 vehicles that will start randomly patrolling an area.

Here is the infantry one I use cut down to show you what I mean:

if (!isServer) exitWith {};
_spawnPos = markerPos (_this select 0);

_group1 = createGroup EAST;
_unit1 = _group1 createUnit ["GUE_Commander", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "FORM"]; sleep 0.2;
_unit2 = _group1 createUnit ["ACE_GUE_Soldier_RPG", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "FORM"]; sleep 0.2;

[_group1, _spawnPos, 150, 7, "MOVE", "SAFE", "YELLOW", "LIMITED", "WEDGE", "", [3,6,9]] call CBA_fnc_taskPatrol;

So basically that will create a group of 2 units that will have 7 "move" waypoints and will move up to 150m away from the marker they are spawned on. I have tried modifying the script to create vehicles instead but this doesn't work. I've also tried using BIS fnc spawnvehicle and the CBA task patrol together as well as a couple of other things and I cannot get vehicles to spawn then use the CBA taskpatrol script. Does anybody know of a way to get this working or know of any existing scripts?

The ideal requirements would be:

- spawns a group of vehicles with crew inside or adds crew to them upon spawning

- able to give the group waypoints, movement and formation types e.g. "MOVE", "AWARE" and "COLUMN"

- their movement will be random so they will drive in different directions each time, just like the infantry do in the script posted above

Please let me know if you know of anything suitable or have any ideas of how to get this working, thanks.

Share this post


Link to post
Share on other sites
Hi Check this out:

AI vehicle respawn patrol area using UPS

http://www.armaholic.com/page.php?id=6543

I use it in alot of my missions past and present, very easy to implement.

That's funny because this is already my backup plan and I've already tried to make sure it works. I did it in the test so I spawn a vehicle in a trigger, then a driver, then link the vehicle to the script so it looks like this:

car = "MtvrReammo" createVehicle (getMarkerPos "carspawn"); driver1 moveindriver car; nul = [car, 10, 10, "WS1","WP_scripts\WP1.sqf"] execVM "AIvcl_respawn_WP\AIvcl_respawn_WP_init.sqf"; car setbehaviour "SAFE";

The only real problem with it is that the patrol won't be random as you plot waypoint markers on the map for the vehicle to follow. Also the vehicles wouldn't be in a group but that's not as big a concern, it would be nice though so I could keep them in formation.

Edited by clydefrog

Share this post


Link to post
Share on other sites

I have here adapted and compiled into one "Random Vehicle Patrol Generator" several functions, that I used in my past projects. It is highly customizable and slightly tested:

Demo

Functions code in VehPatrol_fnc.sqf:

RYD_RandomAround = 
{
private ["_pos","_posX","_posY","_posZ","_radius"];

_pos = _this select 0;
_radius = _this select 1;

_posX = (_pos select 0) + (2 * (random _radius)) - _radius;
_posY = (_pos select 1) + (2 * (random _radius)) - _radius;
_posZ = 0;
if ((count _pos) == 3) then {_posZ = (_pos select 2) + (random _radius) - (_radius/2)};

while {([_posX,_posY,_posZ] distance _pos) > _radius} do
	{
	_posX = (_pos select 0) + (2 * (random _radius)) - _radius;
	_posY = (_pos select 1) + (2 * (random _radius)) - _radius;
	if ((count _pos) == 3) then {_posZ = (_pos select 2) + (2 * (random _radius)) - _radius};
	};

_pos = [_posX,_posY,_posZ];

_pos	
};

RYD_NearestCross = 
{
private ["_crosses","_pos","_chosen","_dist","_distC"];
_crosses = _this select 0;
_pos = _this select 1;

_chosen = _crosses select 0;
_distC = (getPosASL _chosen) distance _pos;

	{
	_dist = (getPosASL _x) distance _pos;
	if (_dist <_distC) then {_chosen = _x;_distC = _dist} 
	}
foreach _crosses;

_chosen
};

RYD_CrossroadsNear = 
{
private ["_pos","_radius","_roads","_cross"];

_pos = _this select 0;
_radius = _this select 1;

_roads = _pos nearRoads _radius;
_cross = [];

	{
	if (count (roadsConnectedTo _x) > 2) then {_cross set [(count _cross),_x]};
	}
foreach _roads;

_cross
};

RYD_SummonV = 	
{
private ["_types","_type","_specific","_mono","_side","_place","_nbr","_state","_lock","_cType","_westC","_eastC","_resC","_HQ","_SummonedGrp","_veh","_ifOA160",
"_frPos","_crew0","_crew1","_crew2","_dir","_cargoN","_sets","_Cgrp","_ldr","_uCg","_kind","_crewClass","_spd","_plZ","_mpl"];

_specific = _this select 0;
_side = _this select 1;
_place = _this select 2;
_nbr = _this select 3;
_state = _this select 4;
_lock = _this select 5;
_kind = _this select 6;
_crewClass = "";
if ((count _this) > 7) then {_crewClass = _this select 7};

_cType = _crewClass;
_westC = _crewClass;
_eastC = _crewClass;
_resC = _crewClass;

if (_crewClass == "") then
	{
	switch (_kind) do
		{
		case ("AIR") : {_westC = "USMC_Soldier_Pilot";_eastC = "RU_Soldier_Pilot";_resC = "GUE_Soldier_Pilot"};
		case ("TANK") : {_westC = "USMC_Soldier_Crew";_eastC = "RU_Soldier_Crew";_resC = "GUE_Soldier_Crew"};
		case ("LIGHT") : {_westC = "USMC_Soldier";_eastC = "RU_Soldier";_resC = "GUE_Soldier_1"};
		default {_westC = "USMC_Soldier_Crew";_eastC = "RU_Soldier_Crew";_resC = "GUE_Soldier_Crew"}
		}
	};

switch (_side) do
	{
	case (west) : {_cType = _westC};
	case (east) : {_cType = _eastC};
	default {_cType = _resC};
	};

_type = "";

_HQ = createCenter _side;
_SummonedGrp = createGroup _side;
while {(_nbr > 0)} do
	{
	if not ((count _specific) == 0) then {_type = _specific select (floor (random (count _specific)))};
	_veh = createVehicle [_type, _place, [], 0, _state];
	_ifOA160 = Alldead;
	if not (isNil ("_ifOA160")) then {_veh allowCrewInImmobile true};

	_frPos = _veh emptyPositions "commander";
	if (_frPos > 0) then 
		{
		_crew0 = _SummonedGrp createUnit [_cType, _place, [], 0, "NONE"];
		_crew0 assignAsCommander _veh;
		_crew0 moveInCommander _veh;
		_crew0 setSkill (0.4 + (random 0.2) + (random 0.2))
		};

	_frPos = _veh emptyPositions "driver";
	if (_frPos > 0) then 
		{
		_crew1 = _SummonedGrp createUnit [_cType, _place, [], 0, "NONE"];
		_crew1 assignAsDriver _veh;
		_crew1 moveInDriver _veh;
		_crew1 setSkill (0.1 + (random 0.25) + (random 0.25))
		};

	_frPos = _veh emptyPositions "gunner";
	if (_frPos > 0) then 
		{
		_crew2 = _SummonedGrp createUnit [_cType, _place, [], 0, "NONE"];
		_crew2 assignAsGunner _veh;
		_crew2 moveInGunner _veh;
		_crew1 setSkill (0.1 + (random 0.25) + (random 0.25))
		};

	_nbr = _nbr - 1;

	_plZ = 0;
	_mpl = 1;

	if (_lock) then {_veh lock true};

	if (_state == "FLY") then 
		{
		_dir = direction _veh;
		_spd = (getNumber (configFile>>"cfgvehicles">>_type>>"maxspeed") + getNumber (configFile>>"cfgvehicles">>_type>>"landingSpeed")) / 7.2;
		_veh setVelocity [(sin _dir) * _spd,(cos _dir) * _spd,0];
		_mpl = 2;
		_plZ = (_place select 2) + 25 * _mpl;
		};

	_place = [(_place select 0) + 25 * _mpl,(_place select 1) + 25 * _mpl,_plZ];
	};

_SummonedGrp
};

RYD_PatrolPointsAround = 
{
private ["_sourceP","_radiusMin","_radiusMax","_min","_above","_points","_minPC","_point","_posX","_posY","_pos","_ct","_isFlat"];
_sourceP = [];

if ((typename (_this select 0)) == 'OBJECT') then 
	{
	_sourceP = getPosASL (_this select 0);
	} 
else 
	{
	_sourceP = _this select 0;
	};

_radiusMin = _this select 1;
_radiusMax = _this select 2;
_min = _this select 3;
_above = _this select 4;

_points = [];
_minPC = _min + (round (random _above));
while {((count _points) < _minPC)} do
	{
	_point = [_sourceP,_radiusMax] call RYD_RandomAround;
	_posX = _point select 0;
	_posY = _point select 1;
	_pos = [_posX,_posY];
	_ct = 0;

	_isFlat = _pos isFlatEmpty [5,0,1,5,0,false,objNull];

	while {((((_pos distance _sourceP) < _radiusMin) or not ((count _isFlat) == 0)) and (_ct < 500))} do
		{
		_point = [_sourceP,_radiusMax] call RYD_RandomAround;
		_posX = _point select 0;
		_posY = _point select 1;
		_pos = [_posX,_posY];
		_isFlat = _pos isFlatEmpty [5,0,1,5,0,false,objNull];
		_ct = _ct + 1;
		};

	_points set [(count _points),_pos];
	};

_points
};

RYD_PatrolWP = 
{
private ["_unit","_uG","_protected","_type","_beh","_CM","_speed","_form","_stat","_cyclic","_rMin","_rMax","_acc","_minA","_maxA","_deleteAll","_nE","_points","_points2","_WPs","_wp","_i"];
_unit = ObjNull;
_uG = GrpNull;

if ((typename (_this select 0)) == "OBJECT") then 
	{
	_unit = _this select 0;
	_uG = group _unit;
	} 
else 
	{
	_uG = _this select 0;
	_unit = leader (_uG)
	};

_protected = _this select 1;

if ((typename (_this select 1)) == "OBJECT") then
	{
	_protected = getPosATL _protected
	}
else
	{
	if ((typename (_this select 1)) == "STRING") then
		{
		_protected = getMarkerPos _protected
		}
	};

_type  = "MOVE";
if ((count _this) > 2) then {_type = _this select 2};
_beh = "AWARE";
if ((count _this) > 3) then {_beh = _this select 3};
_CM = "YELLOW";
if ((count _this) > 4) then {_CM = _this select 4};
_speed = "NORMAL";
if ((count _this) > 5) then {_speed = _this select 5};
_form = "COLUMN";
if ((count _this) > 6) then {_form = _this select 6};
_stat = ["true",""];
if ((count _this) > 7) then {_stat = _this select 7};
_cyclic = true;
if ((count _this) > 8) then {_cyclic = _this select 8};
_rMin = 300;
if ((count _this) > 9) then {_rMin = _this select 9};
_rMax = 600;
if ((count _this) > 10) then {_rMax = _this select 10};
_acc = 0;
if ((count _this) > 11) then {_acc = _this select 11};
_minA = 2;
if ((count _this) > 12) then {_minA = _this select 12};
_maxA = 5;
if ((count _this) > 13) then {_maxA = _this select 13};
_deleteAll = true;
if ((count _this) > 14) then {_deleteAll = _this select 14};

if (_deleteAll) then 
	{
	while {((count (waypoints _uG)) > 0)} do
		{
		deleteWaypoint ((waypoints _uG) select (count (waypoints _uG) - 1));
		}
	}
else
	{
	deleteWaypoint ((waypoints _uG) select 0);
	};

_points = [_protected];
_points2 = [_unit,_rMin,_rMax,_minA,_maxA] call RYD_PatrolPointsAround;
_points = _points + _points2;
_WPs = [];

	{
	_wp = _uG addWaypoint [_x, _acc];
	_wp setWaypointType _type;
	_wp setWaypointBehaviour _beh;
	_wp setWaypointCombatMode _CM;
	_wp setWaypointSpeed _speed;
	_wp setWaypointFormation _form;
	_wp setWaypointStatements _stat;

	_WPs set [(count _WPs),_wp];
	}
foreach _points;

if (_cyclic) then 
	{
	_wp = _uG addWaypoint [(_points select 0), _acc];
	_wp setWaypointType "CYCLE";
	_wp setWaypointBehaviour _beh;
	_wp setWaypointCombatMode _CM;
	_wp setWaypointSpeed _speed;
	_wp setWaypointFormation _form;
	_wp setWaypointStatements _stat;

	_WPs set [(count _WPs),_wp];
	};

_uG setCurrentWaypoint (_WPs select 0);

_WPs
};

RYD_RoadPatrol = 
{
private ["_uG","_type","_beh","_CM","_speed","_form","_stat","_cyclic","_radius","_minTO","_addTO","_deleteAll","_Centrum","_nC","_points","_cross","_pos","_WPs","_points2","_next","_wp"];
_uG = _this select 0;

_type  = "GETOUT";
if ((count _this) > 1) then {_type = _this select 1};
_beh = "SAFE";
if ((count _this) > 2) then {_beh = _this select 2};
_CM = "YELLOW";
if ((count _this) > 3) then {_CM = _this select 3};
_speed = "LIMITED";
if ((count _this) > 4) then {_speed = _this select 4};
_form = "COLUMN";
if ((count _this) > 5) then {_form = _this select 5};
_stat = ["true","(units (group this)) orderGetIn true;if not (isPlayer this) then {(assignedVehicle this) setFuel 1}"];
if ((count _this) > 6) then {_stat = _this select 6};
_cyclic = true;
if ((count _this) > 7) then {_cyclic = _this select 7};
_radius = 5000;
if ((count _this) > 8) then {_radius = _this select 8};
_minTO = 60;
if ((count _this) > 9) then {_minTO = _this select 9};
_addTO = 360;
if ((count _this) > 10) then {_minTO = _this select 10};
_deleteAll = true;
if ((count _this) > 11) then {_deleteAll = _this select 11};

if (_deleteAll) then 
	{
	while {((count (waypoints _uG)) > 0)} do
		{
		deleteWaypoint ((waypoints _uG) select (count (waypoints _uG) - 1));
		}
	}
else
	{
	deleteWaypoint ((waypoints _uG) select 0);
	};

_Centrum = position (vehicle (leader _uG));

_WPs = [];

_nC = nearestLocations [_Centrum, ["NameVillage","NameCity","NameCityCapital"], _radius];

if ((count _nC) > 0) then
	{
	_points = [];

		{
		_cross = [[(position _x),500] call RYD_CrossroadsNear,(position _x)] call RYD_NearestCross;
		_pos = position _x;
		if not (isNull _cross) then {_pos = position _cross};
		_points set [(count _points),_pos]
		}
	foreach _nC;

	_points2 = _points;

		{
		_next = _points select (floor (random (count _points)));
		_points = _points - [_next];
		_wp = _uG addWaypoint [_next, 0];
		_wp setWaypointType _type;
		_wp setWaypointBehaviour _beh;
		_wp setWaypointCombatMode _CM;
		_wp setWaypointSpeed _speed;
		_wp setWaypointFormation _form;
		_wp setWaypointStatements _stat;
		_wp setWaypointTimeout [_minTO,(_minTO +_addTO)/2, _addTO];

		_WPs set [(count _WPs),_wp];

		_wp = _uG addWaypoint [_next, 0];
		_wp setWaypointType "GETIN";
		_wp setWaypointBehaviour _beh;
		_wp setWaypointCombatMode _CM;
		_wp setWaypointSpeed _speed;
		_wp setWaypointFormation _form;
		_wp setWaypointTimeout [5,5,5];

		_WPs set [(count _WPs),_wp];
		}
	foreach _points2;

	if (_cyclic) then 
		{
		_wp = _uG addWaypoint [(_points select 0), 0];
		_wp setWaypointType "CYCLE";
		_wp setWaypointBehaviour _beh;
		_wp setWaypointCombatMode _CM;
		_wp setWaypointSpeed _speed;
		_wp setWaypointFormation _form;
		_wp setWaypointStatements _stat;

		_WPs set [(count _WPs),_wp];
		};

	_uG setCurrentWaypoint (_WPs select 0)
	};

_WPs
};

/////////////////
//MAIN FUNCTION//
/////////////////

RYD_Patrol = 
{
private ["_types","_side","_place","_nbr","_state","_lock","_kind","_crewClass","_grp","_WPs","_onRoads","_radius",
"_type","_beh","_CM","_speed","_form","_stat","_cyclic","_rMin","_rMax","_acc","_minA","_maxA","_deleteWP","_minTO","_addTO"];

//spawning config

_types = _this select 0;//array of vehicle classes to random choose from
_side = _this select 1;//side of patrol
_place = _this select 2;//point of spawn
_nbr = _this select 3;//vehicles amount
_state = _this select 4;//"CAN_COLLIDE","FORM","NONE" or "FLY"
_lock = _this select 5;//if is locked
_kind = _this select 6;//"LIGHT","TANK" or "AIR". Matters, when crew class is not defined
_crewClass = "";
if ((count _this) > 7) then {_crewClass = _this select 7};//optional - class of crew members, set as empty string if not used

//patrol config

_type  = "MOVE";
if ((count _this) > 8) then {_type = _this select 8};//optional. Type of waypoints. Default: "MOVE"
_beh = "SAFE";
if ((count _this) > 9) then {_beh = _this select 9};//optional. Behavior of waypoints. Default: "SAFE" (recommended for "onRoads" mode)
_CM = "YELLOW";
if ((count _this) > 10) then {_CM = _this select 10};//optional.Combat mode of waypoints. Default: "YELLOW"
_speed = "NORMAL";
if ((count _this) > 11) then {_speed = _this select 11};//optional. Speed of waypoints. Default: "NORMAL"
_form = "COLUMN";
if ((count _this) > 12) then {_form = _this select 12};//optional. Type of waypoints. Default: "COLUMN"
_stat = ["true",""];
if ((count _this) > 13) then {_stat = _this select 13};//optional. Type of waypoints. Default: ["true",""]
_cyclic = true;
if ((count _this) > 14) then {_cyclic = _this select 14};//optional. If patrol should be looped. Default: true
_deleteWP = true;
if ((count _this) > 15) then {_deleteWP = _this select 15};//optional. If should be deleted initially added to that group waypoint(s). Default: true
_onRoads = false;
if ((count _this) > 16) then {_onRoads = _this select 16};//optional. If patrol should move from nearby town to town using roads. Default: false
_rMin = 100;
if ((count _this) > 17) then {_rMin = _this select 17};//optional. Matters only, when patrol is not in "onRoads" mode. Minimum distance of each waypoint from starting point. Default: 100
_rMax = 2000;
if ((count _this) > 18) then {_rMin = _this select 18};//optional. Matters only, when patrol is not in "onRoads" mode. Maximum distance of each waypoint from starting point. Default: 2000
_acc = 0;
if ((count _this) > 19) then {_acc = _this select 19};//optional. Matters only, when patrol is not in "onRoads" mode. Random placement radius for each waypoint. Default: 0
_minA = 3;
if ((count _this) > 20) then {_minA = _this select 20};//optional. Matters only, when patrol is not in "onRoads" mode. Minimum number of waypoints (excluding start and cycle at end if looped). Default: 3
_maxA = 10;
if ((count _this) > 21) then {_maxA = _this select 21};//optional. Matters only, when patrol is not in "onRoads" mode. From this value is randomized number of additional (above minimum) number of waypoints. Set to 0 to achieve exact, minimal number of waypoints each time. Default: 10
_radius = 5000;
if ((count _this) > 22) then {_radius = _this select 22};//optional. Matters only, when patrol is in "onRoads" mode. Radius for towns search (maximum patrol checkpoints radius). Default: 5000
_minTO = 0;
if ((count _this) > 23) then {_minTO = _this select 23};//optional. Matters only, when patrol is in "onRoads" mode. Minimum pause time in seconds at each waypoint. Default: 0
_addTO = 0;
if ((count _this) > 24) then {_minTO = _this select 24};//optional. Matters only, when patrol is in "onRoads" mode. Maximum pause time in seconds at each waypoint (in each town). Default: 0

_WPs = [];

_grp = [_types,_side,_place,_nbr,_state,_lock,_kind,_crewClass] call RYD_SummonV;

if not (_onRoads) then
	{
	_WPs = [_grp,_place,_type,_beh,_CM,_speed,_form,_stat,_cyclic,_rMin,_rMax,_acc,_minA,_maxA,_deleteWP] call RYD_PatrolWP
	}
else
	{
	_WPs = [_grp,_type,_beh,_CM,_speed,_form,_stat,_cyclic,_radius,_minTO,_addTO,_deleteWP] call RYD_RoadPatrol;
	};

[_grp,_WPs]
};

Initialization (init.sqf):

Example 1 (full):

call compile preprocessfile "VehPatrol_fnc.sqf";

_config = 
[
["UAZ_CDF","Ural_ZU23_CDF"],	//array of vehicle classes to random choose from
west,					//side of patrol
(position Start),			//point of spawn
3,					//vehicles amount
"NONE",			//"CAN_COLLIDE","FORM","NONE" or "FLY"
true,					//if is locked
"",					//"LIGHT","TANK" or "AIR". Matters, when crew class is not defined. Determines kind of crew units
"CDF_Soldier",			//optional - class of crew members, set as empty string if not used

"GETOUT",				//optional. Type of waypoints. Default: "MOVE"
"SAFE",				//optional. Behavior of waypoints. Default: "SAFE" (recommended for "onRoads" mode)
"YELLOW",				//optional.Combat mode of waypoints. Default: "YELLOW"
"NORMAL",				//optional. Speed of waypoints. Default: "NORMAL"
"COLUMN",				//optional. Type of waypoints. Default: "COLUMN"
["true","(units (group this)) orderGetIn true;if not (isPlayer this) then {(assignedVehicle this) setFuel 1}"],			//optional. Type of waypoints. Default: ["true",""];
true,					//optional. If patrol should be looped. Default: true
true,					//optional. If should be deleted initially added to that group waypoint(s). Default: true
false,				//optional. If patrol should move from nearby town to town using roads. Default: false
250,					//optional. Matters only, when patrol is not in "onRoads" mode. Minimum distance of each waypoint from starting point. Default: 100
1000,					//optional. Matters only, when patrol is not in "onRoads" mode. Maximum distance of each waypoint from starting point. Default: 2000
100,					//optional. Matters only, when patrol is not in "onRoads" mode. Random placement radius for each waypoint. Default: 0
3,					//optional. Matters only, when patrol is not in "onRoads" mode. Minimum number of waypoints (excluding start and cycle at end if looped). Default: 3
5,					//optional. Matters only, when patrol is not in "onRoads" mode. From this value is randomized number of additional (above minimum) number of waypoints. Set to 0 to achieve exact, minimal number of waypoints each time. Default: 10
5000,					//optional. Matters only, when patrol is in "onRoads" mode. Radius for towns search (maximum patrol checkpoints radius). Default: 5000
0,					//optional. Matters only, when patrol is in "onRoads" mode. Minimum pause time in seconds at each waypoint. Default: 0
0,					//optional. Matters only, when patrol is in "onRoads" mode. Maximum pause time in seconds at each waypoint (in each town). Default: 0
];

_config call RYD_Patrol;

Example 2 (simply):

call compile preprocessfile "VehPatrol_fnc.sqf";

[["AH64D"],west,(position Start),6,"FLY",false,"AIR"] call RYD_Patrol;

After some modifications is possible, that vehicles will carry soldiers in cargo space, if needed, currently only crew is present. Works in two modes: simple random, default, and "onRoads", where group is looking for several towns in given radius and will patrol from town to town. I hope, that this will help.

Edited by Rydygier
Forgot to add one function...

Share this post


Link to post
Share on other sites
I have here adapted and compiled into one "Random Vehicle Patrol Generator" several functions, that I used in my past projects. It is highly customizable and slightly tested:

Demo

Functions code in VehPatrol_fnc.sqf:

RYD_RandomAround = 
{
private ["_pos","_posX","_posY","_posZ","_radius"];

_pos = _this select 0;
_radius = _this select 1;

_posX = (_pos select 0) + (2 * (random _radius)) - _radius;
_posY = (_pos select 1) + (2 * (random _radius)) - _radius;
_posZ = 0;
if ((count _pos) == 3) then {_posZ = (_pos select 2) + (random _radius) - (_radius/2)};

while {([_posX,_posY,_posZ] distance _pos) > _radius} do
	{
	_posX = (_pos select 0) + (2 * (random _radius)) - _radius;
	_posY = (_pos select 1) + (2 * (random _radius)) - _radius;
	if ((count _pos) == 3) then {_posZ = (_pos select 2) + (2 * (random _radius)) - _radius};
	};

_pos = [_posX,_posY,_posZ];

_pos	
};

RYD_NearestCross = 
{
private ["_crosses","_pos","_chosen","_dist","_distC"];
_crosses = _this select 0;
_pos = _this select 1;

_chosen = _crosses select 0;
_distC = (getPosASL _chosen) distance _pos;

	{
	_dist = (getPosASL _x) distance _pos;
	if (_dist <_distC) then {_chosen = _x;_distC = _dist} 
	}
foreach _crosses;

_chosen
};

RYD_CrossroadsNear = 
{
private ["_pos","_radius","_roads","_cross"];

_pos = _this select 0;
_radius = _this select 1;

_roads = _pos nearRoads _radius;
_cross = [];

	{
	if (count (roadsConnectedTo _x) > 2) then {_cross set [(count _cross),_x]};
	}
foreach _roads;

_cross
};

RYD_SummonV = 	
{
private ["_types","_type","_specific","_mono","_side","_place","_nbr","_state","_lock","_cType","_westC","_eastC","_resC","_HQ","_SummonedGrp","_veh","_ifOA160",
"_frPos","_crew0","_crew1","_crew2","_dir","_cargoN","_sets","_Cgrp","_ldr","_uCg","_kind","_crewClass","_spd","_plZ","_mpl"];

_specific = _this select 0;
_side = _this select 1;
_place = _this select 2;
_nbr = _this select 3;
_state = _this select 4;
_lock = _this select 5;
_kind = _this select 6;
_crewClass = "";
if ((count _this) > 7) then {_crewClass = _this select 7};

_cType = _crewClass;
_westC = _crewClass;
_eastC = _crewClass;
_resC = _crewClass;

if (_crewClass == "") then
	{
	switch (_kind) do
		{
		case ("AIR") : {_westC = "USMC_Soldier_Pilot";_eastC = "RU_Soldier_Pilot";_resC = "GUE_Soldier_Pilot"};
		case ("TANK") : {_westC = "USMC_Soldier_Crew";_eastC = "RU_Soldier_Crew";_resC = "GUE_Soldier_Crew"};
		case ("LIGHT") : {_westC = "USMC_Soldier";_eastC = "RU_Soldier";_resC = "GUE_Soldier_1"};
		default {_westC = "USMC_Soldier_Crew";_eastC = "RU_Soldier_Crew";_resC = "GUE_Soldier_Crew"}
		}
	};

switch (_side) do
	{
	case (west) : {_cType = _westC};
	case (east) : {_cType = _eastC};
	default {_cType = _resC};
	};

_type = "";

_HQ = createCenter _side;
_SummonedGrp = createGroup _side;
while {(_nbr > 0)} do
	{
	if not ((count _specific) == 0) then {_type = _specific select (floor (random (count _specific)))};
	_veh = createVehicle [_type, _place, [], 0, _state];
	_ifOA160 = Alldead;
	if not (isNil ("_ifOA160")) then {_veh allowCrewInImmobile true};

	_frPos = _veh emptyPositions "commander";
	if (_frPos > 0) then 
		{
		_crew0 = _SummonedGrp createUnit [_cType, _place, [], 0, "NONE"];
		_crew0 assignAsCommander _veh;
		_crew0 moveInCommander _veh;
		_crew0 setSkill (0.4 + (random 0.2) + (random 0.2))
		};

	_frPos = _veh emptyPositions "driver";
	if (_frPos > 0) then 
		{
		_crew1 = _SummonedGrp createUnit [_cType, _place, [], 0, "NONE"];
		_crew1 assignAsDriver _veh;
		_crew1 moveInDriver _veh;
		_crew1 setSkill (0.1 + (random 0.25) + (random 0.25))
		};

	_frPos = _veh emptyPositions "gunner";
	if (_frPos > 0) then 
		{
		_crew2 = _SummonedGrp createUnit [_cType, _place, [], 0, "NONE"];
		_crew2 assignAsGunner _veh;
		_crew2 moveInGunner _veh;
		_crew1 setSkill (0.1 + (random 0.25) + (random 0.25))
		};

	_nbr = _nbr - 1;

	_plZ = 0;
	_mpl = 1;

	if (_lock) then {_veh lock true};

	if (_state == "FLY") then 
		{
		_dir = direction _veh;
		_spd = (getNumber (configFile>>"cfgvehicles">>_type>>"maxspeed") + getNumber (configFile>>"cfgvehicles">>_type>>"landingSpeed")) / 7.2;
		_veh setVelocity [(sin _dir) * _spd,(cos _dir) * _spd,0];
		_mpl = 2;
		_plZ = (_place select 2) + 25 * _mpl;
		};

	_place = [(_place select 0) + 25 * _mpl,(_place select 1) + 25 * _mpl,_plZ];
	};

_SummonedGrp
};

RYD_PatrolPointsAround = 
{
private ["_sourceP","_radiusMin","_radiusMax","_min","_above","_points","_minPC","_point","_posX","_posY","_pos","_ct","_isFlat"];
_sourceP = [];

if ((typename (_this select 0)) == 'OBJECT') then 
	{
	_sourceP = getPosASL (_this select 0);
	} 
else 
	{
	_sourceP = _this select 0;
	};

_radiusMin = _this select 1;
_radiusMax = _this select 2;
_min = _this select 3;
_above = _this select 4;

_points = [];
_minPC = _min + (round (random _above));
while {((count _points) < _minPC)} do
	{
	_point = [_sourceP,_radiusMax] call RYD_RandomAround;
	_posX = _point select 0;
	_posY = _point select 1;
	_pos = [_posX,_posY];
	_ct = 0;

	_isFlat = _pos isFlatEmpty [5,0,1,5,0,false,objNull];

	while {((((_pos distance _sourceP) < _radiusMin) or not ((count _isFlat) == 0)) and (_ct < 500))} do
		{
		_point = [_sourceP,_radiusMax] call RYD_RandomAround;
		_posX = _point select 0;
		_posY = _point select 1;
		_pos = [_posX,_posY];
		_isFlat = _pos isFlatEmpty [5,0,1,5,0,false,objNull];
		_ct = _ct + 1;
		};

	_points set [(count _points),_pos];
	};

_points
};

RYD_PatrolWP = 
{
private ["_unit","_uG","_protected","_type","_beh","_CM","_speed","_form","_stat","_cyclic","_rMin","_rMax","_acc","_minA","_maxA","_deleteAll","_nE","_points","_points2","_WPs","_wp","_i"];
_unit = ObjNull;
_uG = GrpNull;

if ((typename (_this select 0)) == "OBJECT") then 
	{
	_unit = _this select 0;
	_uG = group _unit;
	} 
else 
	{
	_uG = _this select 0;
	_unit = leader (_uG)
	};

_protected = _this select 1;

if ((typename (_this select 1)) == "OBJECT") then
	{
	_protected = getPosATL _protected
	}
else
	{
	if ((typename (_this select 1)) == "STRING") then
		{
		_protected = getMarkerPos _protected
		}
	};

_type  = "MOVE";
if ((count _this) > 2) then {_type = _this select 2};
_beh = "AWARE";
if ((count _this) > 3) then {_beh = _this select 3};
_CM = "YELLOW";
if ((count _this) > 4) then {_CM = _this select 4};
_speed = "NORMAL";
if ((count _this) > 5) then {_speed = _this select 5};
_form = "COLUMN";
if ((count _this) > 6) then {_form = _this select 6};
_stat = ["true",""];
if ((count _this) > 7) then {_stat = _this select 7};
_cyclic = true;
if ((count _this) > 8) then {_cyclic = _this select 8};
_rMin = 300;
if ((count _this) > 9) then {_rMin = _this select 9};
_rMax = 600;
if ((count _this) > 10) then {_rMax = _this select 10};
_acc = 0;
if ((count _this) > 11) then {_acc = _this select 11};
_minA = 2;
if ((count _this) > 12) then {_minA = _this select 12};
_maxA = 5;
if ((count _this) > 13) then {_maxA = _this select 13};
_deleteAll = true;
if ((count _this) > 14) then {_deleteAll = _this select 14};

if (_deleteAll) then 
	{
	while {((count (waypoints _uG)) > 0)} do
		{
		deleteWaypoint ((waypoints _uG) select (count (waypoints _uG) - 1));
		}
	}
else
	{
	deleteWaypoint ((waypoints _uG) select 0);
	};

_points = [_protected];
_points2 = [_unit,_rMin,_rMax,_minA,_maxA] call RYD_PatrolPointsAround;
_points = _points + _points2;
_WPs = [];

	{
	_wp = _uG addWaypoint [_x, _acc];
	_wp setWaypointType _type;
	_wp setWaypointBehaviour _beh;
	_wp setWaypointCombatMode _CM;
	_wp setWaypointSpeed _speed;
	_wp setWaypointFormation _form;
	_wp setWaypointStatements _stat;

	_WPs set [(count _WPs),_wp];
	}
foreach _points;

if (_cyclic) then 
	{
	_wp = _uG addWaypoint [(_points select 0), _acc];
	_wp setWaypointType "CYCLE";
	_wp setWaypointBehaviour _beh;
	_wp setWaypointCombatMode _CM;
	_wp setWaypointSpeed _speed;
	_wp setWaypointFormation _form;
	_wp setWaypointStatements _stat;

	_WPs set [(count _WPs),_wp];
	};

_uG setCurrentWaypoint (_WPs select 0);

_WPs
};

RYD_RoadPatrol = 
{
private ["_uG","_type","_beh","_CM","_speed","_form","_stat","_cyclic","_radius","_minTO","_addTO","_deleteAll","_Centrum","_nC","_points","_cross","_pos","_WPs","_points2","_next","_wp"];
_uG = _this select 0;

_type  = "GETOUT";
if ((count _this) > 1) then {_type = _this select 1};
_beh = "SAFE";
if ((count _this) > 2) then {_beh = _this select 2};
_CM = "YELLOW";
if ((count _this) > 3) then {_CM = _this select 3};
_speed = "LIMITED";
if ((count _this) > 4) then {_speed = _this select 4};
_form = "COLUMN";
if ((count _this) > 5) then {_form = _this select 5};
_stat = ["true","(units (group this)) orderGetIn true;if not (isPlayer this) then {(assignedVehicle this) setFuel 1}"];
if ((count _this) > 6) then {_stat = _this select 6};
_cyclic = true;
if ((count _this) > 7) then {_cyclic = _this select 7};
_radius = 5000;
if ((count _this) > 8) then {_radius = _this select 8};
_minTO = 60;
if ((count _this) > 9) then {_minTO = _this select 9};
_addTO = 360;
if ((count _this) > 10) then {_minTO = _this select 10};
_deleteAll = true;
if ((count _this) > 11) then {_deleteAll = _this select 11};

if (_deleteAll) then 
	{
	while {((count (waypoints _uG)) > 0)} do
		{
		deleteWaypoint ((waypoints _uG) select (count (waypoints _uG) - 1));
		}
	}
else
	{
	deleteWaypoint ((waypoints _uG) select 0);
	};

_Centrum = position (vehicle (leader _uG));

_WPs = [];

_nC = nearestLocations [_Centrum, ["NameVillage","NameCity","NameCityCapital"], _radius];

if ((count _nC) > 0) then
	{
	_points = [];

		{
		_cross = [[(position _x),500] call RYD_CrossroadsNear,(position _x)] call RYD_NearestCross;
		_pos = position _x;
		if not (isNull _cross) then {_pos = position _cross};
		_points set [(count _points),_pos]
		}
	foreach _nC;

	_points2 = _points;

		{
		_next = _points select (floor (random (count _points)));
		_points = _points - [_next];
		_wp = _uG addWaypoint [_next, 0];
		_wp setWaypointType _type;
		_wp setWaypointBehaviour _beh;
		_wp setWaypointCombatMode _CM;
		_wp setWaypointSpeed _speed;
		_wp setWaypointFormation _form;
		_wp setWaypointStatements _stat;
		_wp setWaypointTimeout [_minTO,(_minTO +_addTO)/2, _addTO];

		_WPs set [(count _WPs),_wp];

		_wp = _uG addWaypoint [_next, 0];
		_wp setWaypointType "GETIN";
		_wp setWaypointBehaviour _beh;
		_wp setWaypointCombatMode _CM;
		_wp setWaypointSpeed _speed;
		_wp setWaypointFormation _form;
		_wp setWaypointTimeout [5,5,5];

		_WPs set [(count _WPs),_wp];
		}
	foreach _points2;

	if (_cyclic) then 
		{
		_wp = _uG addWaypoint [(_points select 0), 0];
		_wp setWaypointType "CYCLE";
		_wp setWaypointBehaviour _beh;
		_wp setWaypointCombatMode _CM;
		_wp setWaypointSpeed _speed;
		_wp setWaypointFormation _form;
		_wp setWaypointStatements _stat;

		_WPs set [(count _WPs),_wp];
		};

	_uG setCurrentWaypoint (_WPs select 0)
	};

_WPs
};

/////////////////
//MAIN FUNCTION//
/////////////////

RYD_Patrol = 
{
private ["_types","_side","_place","_nbr","_state","_lock","_kind","_crewClass","_grp","_WPs","_onRoads","_radius",
"_type","_beh","_CM","_speed","_form","_stat","_cyclic","_rMin","_rMax","_acc","_minA","_maxA","_deleteWP","_minTO","_addTO"];

//spawning config

_types = _this select 0;//array of vehicle classes to random choose from
_side = _this select 1;//side of patrol
_place = _this select 2;//point of spawn
_nbr = _this select 3;//vehicles amount
_state = _this select 4;//"CAN_COLLIDE","FORM","NONE" or "FLY"
_lock = _this select 5;//if is locked
_kind = _this select 6;//"LIGHT","TANK" or "AIR". Matters, when crew class is not defined
_crewClass = "";
if ((count _this) > 7) then {_crewClass = _this select 7};//optional - class of crew members, set as empty string if not used

//patrol config

_type  = "MOVE";
if ((count _this) > 8) then {_type = _this select 8};//optional. Type of waypoints. Default: "MOVE"
_beh = "SAFE";
if ((count _this) > 9) then {_beh = _this select 9};//optional. Behavior of waypoints. Default: "SAFE" (recommended for "onRoads" mode)
_CM = "YELLOW";
if ((count _this) > 10) then {_CM = _this select 10};//optional.Combat mode of waypoints. Default: "YELLOW"
_speed = "NORMAL";
if ((count _this) > 11) then {_speed = _this select 11};//optional. Speed of waypoints. Default: "NORMAL"
_form = "COLUMN";
if ((count _this) > 12) then {_form = _this select 12};//optional. Type of waypoints. Default: "COLUMN"
_stat = ["true",""];
if ((count _this) > 13) then {_stat = _this select 13};//optional. Type of waypoints. Default: ["true",""]
_cyclic = true;
if ((count _this) > 14) then {_cyclic = _this select 14};//optional. If patrol should be looped. Default: true
_deleteWP = true;
if ((count _this) > 15) then {_deleteWP = _this select 15};//optional. If should be deleted initially added to that group waypoint(s). Default: true
_onRoads = false;
if ((count _this) > 16) then {_onRoads = _this select 16};//optional. If patrol should move from nearby town to town using roads. Default: false
_rMin = 100;
if ((count _this) > 17) then {_rMin = _this select 17};//optional. Matters only, when patrol is not in "onRoads" mode. Minimum distance of each waypoint from starting point. Default: 100
_rMax = 2000;
if ((count _this) > 18) then {_rMin = _this select 18};//optional. Matters only, when patrol is not in "onRoads" mode. Maximum distance of each waypoint from starting point. Default: 2000
_acc = 0;
if ((count _this) > 19) then {_acc = _this select 19};//optional. Matters only, when patrol is not in "onRoads" mode. Random placement radius for each waypoint. Default: 0
_minA = 3;
if ((count _this) > 20) then {_minA = _this select 20};//optional. Matters only, when patrol is not in "onRoads" mode. Minimum number of waypoints (excluding start and cycle at end if looped). Default: 3
_maxA = 10;
if ((count _this) > 21) then {_maxA = _this select 21};//optional. Matters only, when patrol is not in "onRoads" mode. From this value is randomized number of additional (above minimum) number of waypoints. Set to 0 to achieve exact, minimal number of waypoints each time. Default: 10
_radius = 5000;
if ((count _this) > 22) then {_radius = _this select 22};//optional. Matters only, when patrol is in "onRoads" mode. Radius for towns search (maximum patrol checkpoints radius). Default: 5000
_minTO = 0;
if ((count _this) > 23) then {_minTO = _this select 23};//optional. Matters only, when patrol is in "onRoads" mode. Minimum pause time in seconds at each waypoint. Default: 0
_addTO = 0;
if ((count _this) > 24) then {_minTO = _this select 24};//optional. Matters only, when patrol is in "onRoads" mode. Maximum pause time in seconds at each waypoint (in each town). Default: 0

_WPs = [];

_grp = [_types,_side,_place,_nbr,_state,_lock,_kind,_crewClass] call RYD_SummonV;

if not (_onRoads) then
	{
	_WPs = [_grp,_place,_type,_beh,_CM,_speed,_form,_stat,_cyclic,_rMin,_rMax,_acc,_minA,_maxA,_deleteWP] call RYD_PatrolWP
	}
else
	{
	_WPs = [_grp,_type,_beh,_CM,_speed,_form,_stat,_cyclic,_radius,_minTO,_addTO,_deleteWP] call RYD_RoadPatrol;
	};

[_grp,_WPs]
};

Initialization (init.sqf):

Example 1 (full):

call compile preprocessfile "VehPatrol_fnc.sqf";

_config = 
[
["UAZ_CDF","Ural_ZU23_CDF"],	//array of vehicle classes to random choose from
west,					//side of patrol
(position Start),			//point of spawn
3,					//vehicles amount
"NONE",			//"CAN_COLLIDE","FORM","NONE" or "FLY"
true,					//if is locked
"",					//"LIGHT","TANK" or "AIR". Matters, when crew class is not defined. Determines kind of crew units
"CDF_Soldier",			//optional - class of crew members, set as empty string if not used

"GETOUT",				//optional. Type of waypoints. Default: "MOVE"
"SAFE",				//optional. Behavior of waypoints. Default: "SAFE" (recommended for "onRoads" mode)
"YELLOW",				//optional.Combat mode of waypoints. Default: "YELLOW"
"NORMAL",				//optional. Speed of waypoints. Default: "NORMAL"
"COLUMN",				//optional. Type of waypoints. Default: "COLUMN"
["true","(units (group this)) orderGetIn true;if not (isPlayer this) then {(assignedVehicle this) setFuel 1}"],			//optional. Type of waypoints. Default: ["true",""];
true,					//optional. If patrol should be looped. Default: true
true,					//optional. If should be deleted initially added to that group waypoint(s). Default: true
false,				//optional. If patrol should move from nearby town to town using roads. Default: false
250,					//optional. Matters only, when patrol is not in "onRoads" mode. Minimum distance of each waypoint from starting point. Default: 100
1000,					//optional. Matters only, when patrol is not in "onRoads" mode. Maximum distance of each waypoint from starting point. Default: 2000
100,					//optional. Matters only, when patrol is not in "onRoads" mode. Random placement radius for each waypoint. Default: 0
3,					//optional. Matters only, when patrol is not in "onRoads" mode. Minimum number of waypoints (excluding start and cycle at end if looped). Default: 3
5,					//optional. Matters only, when patrol is not in "onRoads" mode. From this value is randomized number of additional (above minimum) number of waypoints. Set to 0 to achieve exact, minimal number of waypoints each time. Default: 10
5000,					//optional. Matters only, when patrol is in "onRoads" mode. Radius for towns search (maximum patrol checkpoints radius). Default: 5000
0,					//optional. Matters only, when patrol is in "onRoads" mode. Minimum pause time in seconds at each waypoint. Default: 0
0,					//optional. Matters only, when patrol is in "onRoads" mode. Maximum pause time in seconds at each waypoint (in each town). Default: 0
];

_config call RYD_Patrol;

Example 2 (simply):

call compile preprocessfile "VehPatrol_fnc.sqf";

[["AH64D"],west,(position Start),6,"FLY",false,"AIR"] call RYD_Patrol;

After some modifications is possible, that vehicles will carry soldiers in cargo space, if needed, currently only crew is present. Works in two modes: simple random, default, and "onRoads", where group is looking for several towns in given radius and will patrol from town to town. I hope, that this will help.

Thanks, this could be useful. I'm trying it out at the moment but when I set the side of the spawned vehicles from "west" to "guer" they no longer spawn with crew, any ideas?

Here's the altered script:

call compile preprocessfile "VehPatrol_fnc.sqf";

SpawnPatrol = false;

while {true} do
{
waitUntil {sleep 0.1;SpawnPatrol};
SpawnPatrol = false;

//example 1 (full)


_config = 
	[
	["BMP2_Gue","T72_Gue","BRDM2_Gue"],	//array of vehicle classes to random choose from
	guer,					//side of patrol
	getmarkerpos "vehpatrol1",			//point of spawn
	3,					//vehicles amount
	"FORM",			//"CAN_COLLIDE","FORM","NONE" or "FLY"
	false,					//if is locked
	"TANK",					//"LIGHT","TANK" or "AIR". Matters, when crew class is not defined. Determines kind of crew units
	"GUE_Soldier_Crew",			//optional - class of crew members, set as empty string if not used

	"MOVE",				//optional. Type of waypoints. Default: "MOVE"
	"SAFE",				//optional. Behavior of waypoints. Default: "SAFE" (recommended for "onRoads" mode)
	"YELLOW",				//optional.Combat mode of waypoints. Default: "YELLOW"
	"NORMAL",				//optional. Speed of waypoints. Default: "NORMAL"
	"COLUMN",				//optional. Type of waypoints. Default: "COLUMN"
	["true","(units (group this)) orderGetIn true;if not (isPlayer this) then {(assignedVehicle this) setFuel 1}"],			//optional. Type of waypoints. Default: ["true",""];
	true,					//optional. If patrol should be looped. Default: true
	true,					//optional. If should be deleted initially added to that group waypoint(s). Default: true
	true,				//optional. If patrol should move from nearby town to town using roads. Default: false
	250,					//optional. Matters only, when patrol is not in "onRoads" mode. Minimum distance of each waypoint from starting point. Default: 100
	1000,					//optional. Matters only, when patrol is not in "onRoads" mode. Maximum distance of each waypoint from starting point. Default: 2000
	100,					//optional. Matters only, when patrol is not in "onRoads" mode. Random placement radius for each waypoint. Default: 0
	3,					//optional. Matters only, when patrol is not in "onRoads" mode. Minimum number of waypoints (excluding start and cycle at end if looped). Default: 3
	5,					//optional. Matters only, when patrol is not in "onRoads" mode. From this value is randomized number of additional (above minimum) number of waypoints. Set to 0 to achieve exact, minimal number of waypoints each time. Default: 10
	5000,					//optional. Matters only, when patrol is in "onRoads" mode. Radius for towns search (maximum patrol checkpoints radius). Default: 5000
	0,					//optional. Matters only, when patrol is in "onRoads" mode. Minimum pause time in seconds at each waypoint. Default: 0
	0					//optional. Matters only, when patrol is in "onRoads" mode. Maximum pause time in seconds at each waypoint (in each town). Default: 0
	];

_config call RYD_Patrol;

};
[/spoiler]

I've tried making them east and that works but guer doesn't. Also another 2 things, they don't stay on roads even though I set that value to true so they will, and also for some reason they won't shoot at me even though they are russian and my player is USMC.

Edited by clydefrog

Share this post


Link to post
Share on other sites

Use resistance instead guer (this probably also should work, but in string form: "GUER"). As for roads - not sure, why. This is only about vanilla vehicles AI - tendency to use roads if possible, especially in SAFE or CARELESS. And I saw vehicles spawned this way, that was patrolling on roads. Script does nothing special here, only chooses waypoints on crossroads inside towns (found in given radius), one per city/village. As for not attacking - try to put on map in editor russian/east unit anywhere, with 0% presence probability. This helped in my case, while scripted createCenter seems to be not sufficient.

Edited by Rydygier

Share this post


Link to post
Share on other sites
Use resistance instead guer (this probably also should work, but in string form: "GUER"). As for roads - not sure, why. This is only about vanilla vehicles AI - tendency to use roads if possible, especially in SAFE or CARELESS. And I saw vehicles spawned this way, that was patrolling on roads. Script does nothing special here, only chooses waypoints on crossroads inside towns (found in given radius), one per city/village. As for not attacking - try to put on map in editor russian/east unit anywhere, with 0% presence probability. This helped in my case, while scripted createCenter seems to be not sufficient.

Thanks for the reply. It's now working with guerilla units in the vehicles and they attack me so that's that solved. I have three more questions:

1. Is there a radius you can set from their spawn position so for example they can only go up to 1km from where they spawn in any direction?

2. Do you know if this should work properly in multiplayer, any known locality issues or anything?

3. Is it possible to name the vehicles or the group of vehicles? The reason I ask this is I'd like to have a task where you complete it by destroying the vehicles spawned in this script. If I had a group name I could say e.g. {alive _X} count (units tankgroup) < 1

Thanks.

Edited by clydefrog

Share this post


Link to post
Share on other sites

1. There is radius for points, but not for route (so all waypoints will be placed in chosen radius, but if vehicle will go outside this radius en route between two waypoints - this is not controlled). For default mode use these configs:

    250,                    //optional. Matters only, when patrol is not in "onRoads" mode. Minimum distance of each waypoint from starting point. Default: 100
   1000,                    //optional. Matters only, when patrol is not in "onRoads" mode. Maximum distance of each waypoint from starting point. Default: 2000

For "onRoads" is the line with default 5000 value for choosing radius of towns search.

2. I do not know. I'm incompetent as for MP scripting.

3. Main function, that you call from the init, returns an array in form [group,waypoints]. So to obtain group call it this way:

_group = (_config call RYD_Patrol) select 0;

Now, using _group variable, you can mess with:

assignedVehicle

Vehicle

setVehicleVarName

Edited by Rydygier

Share this post


Link to post
Share on other sites
3. Main function, that you call from the init, returns an array in form [group,waypoints]. So to obtain group call it this way:

_group = (_config call RYD_Patrol) select 0;

Sorry I don't understand, where would I put that line and into which script, and how would I give the group a name e.g. "tankgroup1"?

Edited by clydefrog

Share this post


Link to post
Share on other sites

Yours init may look like:

call compile preprocessfile "VehPatrol_fnc.sqf";

_config = 
[
["UAZ_CDF","Ural_ZU23_CDF"],	//array of vehicle classes to random choose from
west,					//side of patrol
(position Start),			//point of spawn
3,					//vehicles amount
"NONE",			//"CAN_COLLIDE","FORM","NONE" or "FLY"
true,					//if is locked
"",					//"LIGHT","TANK" or "AIR". Matters, when crew class is not defined. Determines kind of crew units
"CDF_Soldier",			//optional - class of crew members, set as empty string if not used

"GETOUT",				//optional. Type of waypoints. Default: "MOVE"
"SAFE",				//optional. Behavior of waypoints. Default: "SAFE" (recommended for "onRoads" mode)
"YELLOW",				//optional.Combat mode of waypoints. Default: "YELLOW"
"NORMAL",				//optional. Speed of waypoints. Default: "NORMAL"
"COLUMN",				//optional. Type of waypoints. Default: "COLUMN"
["true","(units (group this)) orderGetIn true;if not (isPlayer this) then {(assignedVehicle this) setFuel 1}"],			//optional. Type of waypoints. Default: ["true",""];
true,					//optional. If patrol should be looped. Default: true
true,					//optional. If should be deleted initially added to that group waypoint(s). Default: true
false,				//optional. If patrol should move from nearby town to town using roads. Default: false
250,					//optional. Matters only, when patrol is not in "onRoads" mode. Minimum distance of each waypoint from starting point. Default: 100
1000,					//optional. Matters only, when patrol is not in "onRoads" mode. Maximum distance of each waypoint from starting point. Default: 2000
100,					//optional. Matters only, when patrol is not in "onRoads" mode. Random placement radius for each waypoint. Default: 0
3,					//optional. Matters only, when patrol is not in "onRoads" mode. Minimum number of waypoints (excluding start and cycle at end if looped). Default: 3
5,					//optional. Matters only, when patrol is not in "onRoads" mode. From this value is randomized number of additional (above minimum) number of waypoints. Set to 0 to achieve exact, minimal number of waypoints each time. Default: 10
5000,					//optional. Matters only, when patrol is in "onRoads" mode. Radius for towns search (maximum patrol checkpoints radius). Default: 5000
0,					//optional. Matters only, when patrol is in "onRoads" mode. Minimum pause time in seconds at each waypoint. Default: 0
0,					//optional. Matters only, when patrol is in "onRoads" mode. Maximum pause time in seconds at each waypoint (in each town). Default: 0
];

_patrol = _config call RYD_Patrol;
tankgroup1 = _patrol select 0;

or just (instead last two lines, one):

tankgroup1 = (_config call RYD_Patrol) select 0;

Share this post


Link to post
Share on other sites
Yours init may look like:

call compile preprocessfile "VehPatrol_fnc.sqf";

_config = 
[
["UAZ_CDF","Ural_ZU23_CDF"],	//array of vehicle classes to random choose from
west,					//side of patrol
(position Start),			//point of spawn
3,					//vehicles amount
"NONE",			//"CAN_COLLIDE","FORM","NONE" or "FLY"
true,					//if is locked
"",					//"LIGHT","TANK" or "AIR". Matters, when crew class is not defined. Determines kind of crew units
"CDF_Soldier",			//optional - class of crew members, set as empty string if not used

"GETOUT",				//optional. Type of waypoints. Default: "MOVE"
"SAFE",				//optional. Behavior of waypoints. Default: "SAFE" (recommended for "onRoads" mode)
"YELLOW",				//optional.Combat mode of waypoints. Default: "YELLOW"
"NORMAL",				//optional. Speed of waypoints. Default: "NORMAL"
"COLUMN",				//optional. Type of waypoints. Default: "COLUMN"
["true","(units (group this)) orderGetIn true;if not (isPlayer this) then {(assignedVehicle this) setFuel 1}"],			//optional. Type of waypoints. Default: ["true",""];
true,					//optional. If patrol should be looped. Default: true
true,					//optional. If should be deleted initially added to that group waypoint(s). Default: true
false,				//optional. If patrol should move from nearby town to town using roads. Default: false
250,					//optional. Matters only, when patrol is not in "onRoads" mode. Minimum distance of each waypoint from starting point. Default: 100
1000,					//optional. Matters only, when patrol is not in "onRoads" mode. Maximum distance of each waypoint from starting point. Default: 2000
100,					//optional. Matters only, when patrol is not in "onRoads" mode. Random placement radius for each waypoint. Default: 0
3,					//optional. Matters only, when patrol is not in "onRoads" mode. Minimum number of waypoints (excluding start and cycle at end if looped). Default: 3
5,					//optional. Matters only, when patrol is not in "onRoads" mode. From this value is randomized number of additional (above minimum) number of waypoints. Set to 0 to achieve exact, minimal number of waypoints each time. Default: 10
5000,					//optional. Matters only, when patrol is in "onRoads" mode. Radius for towns search (maximum patrol checkpoints radius). Default: 5000
0,					//optional. Matters only, when patrol is in "onRoads" mode. Minimum pause time in seconds at each waypoint. Default: 0
0,					//optional. Matters only, when patrol is in "onRoads" mode. Maximum pause time in seconds at each waypoint (in each town). Default: 0
];

_patrol = _config call RYD_Patrol;
tankgroup1 = _patrol select 0;

or just (instead last two lines, one):

tankgroup1 = (_config call RYD_Patrol) select 0;

Thanks a lot, it works fine now.

It hopefully should be ok for multiplayer too, I added

if (!isServer) exitWith {};

at the start of the VehPatrol_fnc.sqf script to make sure the vehicles are only created for the server and not for each client. I've tested it local hosted with somebody else and it created the correct amount of vehicles, spawned the same way you did in your demo mission through the radio trigger. One thing though that doesn't really matter too much, I made another trigger and in the Condition I put:

({alive _x} count units tankgroup1) < 1

and in the onAct I just had:

 hint "convoy destroyed" 

But thye hint only showed for me (who spawned the vehicles). I guess if you don't deal with multiplayer stuff you might not know why this happened or how to fix it though.

Edited by clydefrog

Share this post


Link to post
Share on other sites
I guess if you don't deal with multiplayer stuff you might not know why this happened

Indeed. I don't know, what causes this. But I'm sure around is many MP-competent scripters, that may help with this stuff.

Share this post


Link to post
Share on other sites

One question about this script Rydygier, how do I modify the main script to get the vehicles to spawn closer together? As it is on the map I'm using they spawn way too far apart and get stuck in trees etc.

Share this post


Link to post
Share on other sites

Open VehPatrol_fnc.sqf, find function RYD_SummonV, go to the lines 150 (matters for air vehicles only):

			_plZ = (_place select 2) + 25 * _mpl;

and 152:

_place = [(_place select 0) + 25 * _mpl,(_place select 1) + 25 * _mpl,_plZ];

"25" number is a value, that you may change for yours purpose (set smaller, suitable value instead of each three 25's). It is position difference in meters for each axis separatelly.

BTW you may also want to fix small issue in line 134, where is:

_crew1 setSkill (0.1 + (random 0.25) + (random 0.25))

and should be:

_crew2 setSkill (0.1 + (random 0.25) + (random 0.25))

(affects only one of the crew memeber skill).

Share this post


Link to post
Share on other sites

That's great thanks, actually there was one other question I had about this script. I've been trying unsuccessfully to run it multiple times by executing the code that goes in the init.sqf from it's own separate script. I tried making 2 copies of the script and changed the variable names (SpawnPatrol1, SpawnPatrol2 etc.) for each one along with the marker name that they spawn on, but it wouldn't work. Any ideas?

Share this post


Link to post
Share on other sites

There is many possible ways. Here is one of them, where spawned are three patrols, one UAZ each and each for one position marked by trigger. Function is called (in foreach loop) from separate sqf by Juliet radio channel (0-0-0) (repeatable).

http://www66.zippyshare.com/v/36264493/file.html

Like I said, there is many ways. Eg you may use random spawn position each time instead of "hardcoded".

Share this post


Link to post
Share on other sites
There is many possible ways. Here is one of them, where spawned are three patrols, one UAZ each and each for one position marked by trigger. Function is called (in foreach loop) from separate sqf by Juliet radio channel (0-0-0) (repeatable).

http://www66.zippyshare.com/v/36264493/file.html

Like I said, there is many ways. Eg you may use random spawn position each time instead of "hardcoded".

Thanks this method worked, but what I was trying to do was spawn the vehicle groups at 2 or more different times in the mission. The way I tried this (which worked for me in the editor but for some reason on a server the first trigger didn't) was the following

- Copied the original code that goes in the init.sqf to 2 separate scripts and adjusted the variable names and the spawn marker name so they were as follows:

convoyspawn1.sqf

call compile preprocessfile "scripts\VehPatrol_fnc.sqf";

SpawnPatrol1 = false;

while {true} do
{
waitUntil {sleep 0.1;SpawnPatrol1};
SpawnPatrol1 = false;

//example 1 (full)


_config = 
	[
	["GAZ_Vodnik_HMG","RW_T90","KamazRefuel","ACE_UAZ_MG_RU"],	//array of vehicle classes to random choose from
	east,					//side of patrol
	getmarkerpos "vehpatrol1",			//point of spawn
	5,					//vehicles amount
	"FORM",			//"CAN_COLLIDE","FORM","NONE" or "FLY"
	false,					//if is locked
	"TANK",					//"LIGHT","TANK" or "AIR". Matters, when crew class is not defined. Determines kind of crew units
	"RU_Soldier_Crew",			//optional - class of crew members, set as empty string if not used

	"MOVE",				//optional. Type of waypoints. Default: "MOVE"
	"SAFE",				//optional. Behavior of waypoints. Default: "SAFE" (recommended for "onRoads" mode)
	"YELLOW",				//optional.Combat mode of waypoints. Default: "YELLOW"
	"NORMAL",				//optional. Speed of waypoints. Default: "NORMAL"
	"COLUMN",				//optional. Type of waypoints. Default: "COLUMN"
	["true","(units (group this)) orderGetIn true;if not (isPlayer this) then {(assignedVehicle this) setFuel 1}"],			//optional. Type of waypoints. Default: ["true",""];
	true,					//optional. If patrol should be looped. Default: true
	true,					//optional. If should be deleted initially added to that group waypoint(s). Default: true
	true,				//optional. If patrol should move from nearby town to town using roads. Default: false
	250,					//optional. Matters only, when patrol is not in "onRoads" mode. Minimum distance of each waypoint from starting point. Default: 100
	1000,					//optional. Matters only, when patrol is not in "onRoads" mode. Maximum distance of each waypoint from starting point. Default: 2000
	100,					//optional. Matters only, when patrol is not in "onRoads" mode. Random placement radius for each waypoint. Default: 0
	3,					//optional. Matters only, when patrol is not in "onRoads" mode. Minimum number of waypoints (excluding start and cycle at end if looped). Default: 3
	5,					//optional. Matters only, when patrol is not in "onRoads" mode. From this value is randomized number of additional (above minimum) number of waypoints. Set to 0 to achieve exact, minimal number of waypoints each time. Default: 10
	2000,					//optional. Matters only, when patrol is in "onRoads" mode. Radius for towns search (maximum patrol checkpoints radius). Default: 5000
	0,					//optional. Matters only, when patrol is in "onRoads" mode. Minimum pause time in seconds at each waypoint. Default: 0
	0					//optional. Matters only, when patrol is in "onRoads" mode. Maximum pause time in seconds at each waypoint (in each town). Default: 0
	];

tankgroup1 = (_config call RYD_Patrol) select 0;
[/spoiler]

convoyscript2.sqf

call compile preprocessfile "scripts\VehPatrol_fnc.sqf";

SpawnPatrol2 = false;

while {true} do
{
waitUntil {sleep 0.1;SpawnPatrol2};
SpawnPatrol2 = false;

//example 1 (full)


_config = 
	[
	["GAZ_Vodnik_HMG","RW_T90","KamazRefuel","ACE_UAZ_MG_RU"],	//array of vehicle classes to random choose from
	east,					//side of patrol
	getmarkerpos "vehpatrol2",			//point of spawn
	5,					//vehicles amount
	"FORM",			//"CAN_COLLIDE","FORM","NONE" or "FLY"
	false,					//if is locked
	"TANK",					//"LIGHT","TANK" or "AIR". Matters, when crew class is not defined. Determines kind of crew units
	"RU_Soldier_Crew",			//optional - class of crew members, set as empty string if not used

	"MOVE",				//optional. Type of waypoints. Default: "MOVE"
	"SAFE",				//optional. Behavior of waypoints. Default: "SAFE" (recommended for "onRoads" mode)
	"YELLOW",				//optional.Combat mode of waypoints. Default: "YELLOW"
	"NORMAL",				//optional. Speed of waypoints. Default: "NORMAL"
	"COLUMN",				//optional. Type of waypoints. Default: "COLUMN"
	["true","(units (group this)) orderGetIn true;if not (isPlayer this) then {(assignedVehicle this) setFuel 1}"],			//optional. Type of waypoints. Default: ["true",""];
	true,					//optional. If patrol should be looped. Default: true
	true,					//optional. If should be deleted initially added to that group waypoint(s). Default: true
	true,				//optional. If patrol should move from nearby town to town using roads. Default: false
	250,					//optional. Matters only, when patrol is not in "onRoads" mode. Minimum distance of each waypoint from starting point. Default: 100
	1000,					//optional. Matters only, when patrol is not in "onRoads" mode. Maximum distance of each waypoint from starting point. Default: 2000
	100,					//optional. Matters only, when patrol is not in "onRoads" mode. Random placement radius for each waypoint. Default: 0
	3,					//optional. Matters only, when patrol is not in "onRoads" mode. Minimum number of waypoints (excluding start and cycle at end if looped). Default: 3
	5,					//optional. Matters only, when patrol is not in "onRoads" mode. From this value is randomized number of additional (above minimum) number of waypoints. Set to 0 to achieve exact, minimal number of waypoints each time. Default: 10
	2000,					//optional. Matters only, when patrol is in "onRoads" mode. Radius for towns search (maximum patrol checkpoints radius). Default: 5000
	0,					//optional. Matters only, when patrol is in "onRoads" mode. Minimum pause time in seconds at each waypoint. Default: 0
	0					//optional. Matters only, when patrol is in "onRoads" mode. Maximum pause time in seconds at each waypoint (in each town). Default: 0
	];

tankgroup2 = (_config call RYD_Patrol) select 0;
[/spoiler]

- I then made a trigger named "convoyexec" that when an ammo box was destroyed the following code would be run in the onAct:

null = [] execVM "scripts\convoyspawn1.sqf"

and then in another trigger I put in the condition

triggeractivated convoyexec

and in the onAct

SpawnPatrol1 = true

I did that for 2 different ammo boxes, obviously the triggers for the other box called convoyspawn2.sqf and SpawnPatrol2 = true etc. but only one of the ammo boxes blowing triggered the vehicle patrol on the server.

Do you see anything wrong with this way of doing it? How would you go about doing it to run the script at different times in the mission (with different vehicle arrays and spawn positions each time)?

Edited by clydefrog

Share this post


Link to post
Share on other sites

I don't know much about servers and such, but both cited code has syntax error, at the end should be closing bracket - }

Anyway instead of using whole code from first demo's init.sqf better would be for example (not simpliest, but with minimal amount of changes):

init.sqf same, as in my last demo - only call compile etc. line.

patrol.sqf:

    

_spawnPos = _this select 0;

_config = 
       [
       ["GAZ_Vodnik_HMG","RW_T90","KamazRefuel","ACE_UAZ_MG_RU"],    //array of vehicle classes to random choose from
       east,                    //side of patrol
      _spawnPos,            //point of spawn
       5,                    //vehicles amount
       "FORM",            //"CAN_COLLIDE","FORM","NONE" or "FLY"
       false,                    //if is locked
       "TANK",                    //"LIGHT","TANK" or "AIR". Matters, when crew class is not defined. Determines kind of crew units
       "RU_Soldier_Crew",            //optional - class of crew members, set as empty string if not used

       "MOVE",                //optional. Type of waypoints. Default: "MOVE"
       "SAFE",                //optional. Behavior of waypoints. Default: "SAFE" (recommended for "onRoads" mode)
       "YELLOW",                //optional.Combat mode of waypoints. Default: "YELLOW"
       "NORMAL",                //optional. Speed of waypoints. Default: "NORMAL"
       "COLUMN",                //optional. Type of waypoints. Default: "COLUMN"
       ["true","(units (group this)) orderGetIn true;if not (isPlayer this) then {(assignedVehicle this) setFuel 1}"],            //optional. Type of waypoints. Default: ["true",""];
       true,                    //optional. If patrol should be looped. Default: true
       true,                    //optional. If should be deleted initially added to that group waypoint(s). Default: true
       true,                //optional. If patrol should move from nearby town to town using roads. Default: false
       250,                    //optional. Matters only, when patrol is not in "onRoads" mode. Minimum distance of each waypoint from starting point. Default: 100
       1000,                    //optional. Matters only, when patrol is not in "onRoads" mode. Maximum distance of each waypoint from starting point. Default: 2000
       100,                    //optional. Matters only, when patrol is not in "onRoads" mode. Random placement radius for each waypoint. Default: 0
       3,                    //optional. Matters only, when patrol is not in "onRoads" mode. Minimum number of waypoints (excluding start and cycle at end if looped). Default: 3
       5,                    //optional. Matters only, when patrol is not in "onRoads" mode. From this value is randomized number of additional (above minimum) number of waypoints. Set to 0 to achieve exact, minimal number of waypoints each time. Default: 10
       2000,                    //optional. Matters only, when patrol is in "onRoads" mode. Radius for towns search (maximum patrol checkpoints radius). Default: 5000
       0,                    //optional. Matters only, when patrol is in "onRoads" mode. Minimum pause time in seconds at each waypoint. Default: 0
       0                    //optional. Matters only, when patrol is in "onRoads" mode. Maximum pause time in seconds at each waypoint (in each town). Default: 0
       ];

   _patrol = _config call RYD_Patrol;  

then in triggers for both ammo boxes act field:

First trigger:

nul = [getmarkerpos "vehpatrol1"] execVM "patrol.sqf";

Second trigger:

nul = [getmarkerpos "vehpatrol2"] execVM "patrol.sqf";

That's it. No additional triggers needed. Still can't tell, how it will behave in MP.

Edited by Rydygier

Share this post


Link to post
Share on other sites
I don't know much about servers and such, but both cited code has syntax error, at the end should be closing bracket - }

Anyway instead of using whole code from first demo's init.sqf better would be for example (not simpliest, but with minimal amount of changes):

init.sqf same, as in my last demo - only call compile etc. line.

patrol.sqf:

    

_spawnPos = _this select 0;

_config = 
       [
       ["GAZ_Vodnik_HMG","RW_T90","KamazRefuel","ACE_UAZ_MG_RU"],    //array of vehicle classes to random choose from
       east,                    //side of patrol
      _spawnPos,            //point of spawn
       5,                    //vehicles amount
       "FORM",            //"CAN_COLLIDE","FORM","NONE" or "FLY"
       false,                    //if is locked
       "TANK",                    //"LIGHT","TANK" or "AIR". Matters, when crew class is not defined. Determines kind of crew units
       "RU_Soldier_Crew",            //optional - class of crew members, set as empty string if not used

       "MOVE",                //optional. Type of waypoints. Default: "MOVE"
       "SAFE",                //optional. Behavior of waypoints. Default: "SAFE" (recommended for "onRoads" mode)
       "YELLOW",                //optional.Combat mode of waypoints. Default: "YELLOW"
       "NORMAL",                //optional. Speed of waypoints. Default: "NORMAL"
       "COLUMN",                //optional. Type of waypoints. Default: "COLUMN"
       ["true","(units (group this)) orderGetIn true;if not (isPlayer this) then {(assignedVehicle this) setFuel 1}"],            //optional. Type of waypoints. Default: ["true",""];
       true,                    //optional. If patrol should be looped. Default: true
       true,                    //optional. If should be deleted initially added to that group waypoint(s). Default: true
       true,                //optional. If patrol should move from nearby town to town using roads. Default: false
       250,                    //optional. Matters only, when patrol is not in "onRoads" mode. Minimum distance of each waypoint from starting point. Default: 100
       1000,                    //optional. Matters only, when patrol is not in "onRoads" mode. Maximum distance of each waypoint from starting point. Default: 2000
       100,                    //optional. Matters only, when patrol is not in "onRoads" mode. Random placement radius for each waypoint. Default: 0
       3,                    //optional. Matters only, when patrol is not in "onRoads" mode. Minimum number of waypoints (excluding start and cycle at end if looped). Default: 3
       5,                    //optional. Matters only, when patrol is not in "onRoads" mode. From this value is randomized number of additional (above minimum) number of waypoints. Set to 0 to achieve exact, minimal number of waypoints each time. Default: 10
       2000,                    //optional. Matters only, when patrol is in "onRoads" mode. Radius for towns search (maximum patrol checkpoints radius). Default: 5000
       0,                    //optional. Matters only, when patrol is in "onRoads" mode. Minimum pause time in seconds at each waypoint. Default: 0
       0                    //optional. Matters only, when patrol is in "onRoads" mode. Maximum pause time in seconds at each waypoint (in each town). Default: 0
       ];

   _patrol = _config call RYD_Patrol;  

then in triggers for both ammo boxes act field:

First trigger:

nul = [getmarkerpos "vehpatrol1"] execVM "patrol.sqf";

Second trigger:

nul = [getmarkerpos "vehpatrol2"] execVM "patrol.sqf";

That's it. No additional triggers needed. Still can't tell, how it will behave in MP.

Ok, that will spawn the vehicles from the same array each time though. I guess I could just copy that script, edit the vehicle array then name it patrol2.sqf then run nul = [getmarkerpos "vehpatrol2"] execVM "patrol2.sqf"?

Also is "_patrol" in "_patrol = _config call RYD_Patrol;" the name of the group? I am currently using "tankgroup1 = (_config call RYD_Patrol) select 0;" to name the group as you showed me in a previous post.

It should be fine for MP by the way, simply adding "if (!isServer) exitWith {};" at the start of the VehPatrol_fnc.sqf makes sure that the vehicles and crew are only created for the server and not for clients.

Share this post


Link to post
Share on other sites
I guess I could just copy that script, edit the vehicle array then name it patrol2.sqf then run nul = [getmarkerpos "vehpatrol2"] execVM "patrol2.sqf"?

Yes. Or better, do same way, as is done with position.

nul = [getmarkerpos "vehpatrol1",[[i]classes here[/i]]] execVM "patrol.sqf";

and

nul = [getmarkerpos "vehpatrol2",[[i]classes2 here[/i]]] execVM "patrol.sqf";

where patrol.sqf looks like:

_spawnPos = _this select 0;
_classArr = _this select 1;

_config = 
       [
       classArr,    //array of vehicle classes to random choose from
       east,                    //side of patrol
      _spawnPos,            //point of spawn
       5,                    //vehicles amount
       "FORM",            //"CAN_COLLIDE","FORM","NONE" or "FLY"
       false,                    //if is locked
       "TANK",                    //"LIGHT","TANK" or "AIR". Matters, when crew class is not defined. Determines kind of crew units
       "RU_Soldier_Crew",            //optional - class of crew members, set as empty string if not used

       "MOVE",                //optional. Type of waypoints. Default: "MOVE"
       "SAFE",                //optional. Behavior of waypoints. Default: "SAFE" (recommended for "onRoads" mode)
       "YELLOW",                //optional.Combat mode of waypoints. Default: "YELLOW"
       "NORMAL",                //optional. Speed of waypoints. Default: "NORMAL"
       "COLUMN",                //optional. Type of waypoints. Default: "COLUMN"
       ["true","(units (group this)) orderGetIn true;if not (isPlayer this) then {(assignedVehicle this) setFuel 1}"],            //optional. Type of waypoints. Default: ["true",""];
       true,                    //optional. If patrol should be looped. Default: true
       true,                    //optional. If should be deleted initially added to that group waypoint(s). Default: true
       true,                //optional. If patrol should move from nearby town to town using roads. Default: false
       250,                    //optional. Matters only, when patrol is not in "onRoads" mode. Minimum distance of each waypoint from starting point. Default: 100
       1000,                    //optional. Matters only, when patrol is not in "onRoads" mode. Maximum distance of each waypoint from starting point. Default: 2000
       100,                    //optional. Matters only, when patrol is not in "onRoads" mode. Random placement radius for each waypoint. Default: 0
       3,                    //optional. Matters only, when patrol is not in "onRoads" mode. Minimum number of waypoints (excluding start and cycle at end if looped). Default: 3
       5,                    //optional. Matters only, when patrol is not in "onRoads" mode. From this value is randomized number of additional (above minimum) number of waypoints. Set to 0 to achieve exact, minimal number of waypoints each time. Default: 10
       2000,                    //optional. Matters only, when patrol is in "onRoads" mode. Radius for towns search (maximum patrol checkpoints radius). Default: 5000
       0,                    //optional. Matters only, when patrol is in "onRoads" mode. Minimum pause time in seconds at each waypoint. Default: 0
       0                    //optional. Matters only, when patrol is in "onRoads" mode. Maximum pause time in seconds at each waypoint (in each town). Default: 0
       ];

   _patrol = _config call RYD_Patrol;  

_patrol is the local variable that is an array contains both, group and its waypoints [group,waypoints]. To obtain group name use in the same file, after

_patrol = _config call RYD_Patrol;

such line:

_grp = _patrol select 0;

Things are more complicated, if you need to refer to the group name outside this file (do you? If not, this is not important). Global variable (without _) is sufficient, but, as same code is executed for both patrols, second patrol will ovwerwrite value of this global variable, so you must store first patrol group name in other variable before second patrol will be spawned, or use some setVariable technique, perhaps with array inside, that will contain each spawned group.

EDIT: you can then add such line in init.sqf:

MyPatrolGroups = [];

and use such code in last part of patrol.sqf:

_patrol = _config call RYD_Patrol;  

_grp = _patrol select 0;

MyPatrolGroups set [(count MyPatrolGroups),_grp];

MyPatrolGroups will contain as array all group names of spawned patrols, where first may be obtained as eg: _firstpatrol = MyPatrolGroups select 0; second as: _secondpatrol = MyPatrolGroups select 1; and so on...

Edited by Rydygier

Share this post


Link to post
Share on other sites
Yes. Or better, do same way, as is done with position.

nul = [getmarkerpos "vehpatrol1",[[i]classes here[/i]]] execVM "patrol.sqf";

and

nul = [getmarkerpos "vehpatrol2",[[i]classes2 here[/i]]] execVM "patrol.sqf";

where patrol.sqf looks like:

_spawnPos = _this select 0;
_classArr = _this select 1;

_config = 
       [
       classArr,    //array of vehicle classes to random choose from
       east,                    //side of patrol
      _spawnPos,            //point of spawn
       5,                    //vehicles amount
       "FORM",            //"CAN_COLLIDE","FORM","NONE" or "FLY"
       false,                    //if is locked
       "TANK",                    //"LIGHT","TANK" or "AIR". Matters, when crew class is not defined. Determines kind of crew units
       "RU_Soldier_Crew",            //optional - class of crew members, set as empty string if not used

       "MOVE",                //optional. Type of waypoints. Default: "MOVE"
       "SAFE",                //optional. Behavior of waypoints. Default: "SAFE" (recommended for "onRoads" mode)
       "YELLOW",                //optional.Combat mode of waypoints. Default: "YELLOW"
       "NORMAL",                //optional. Speed of waypoints. Default: "NORMAL"
       "COLUMN",                //optional. Type of waypoints. Default: "COLUMN"
       ["true","(units (group this)) orderGetIn true;if not (isPlayer this) then {(assignedVehicle this) setFuel 1}"],            //optional. Type of waypoints. Default: ["true",""];
       true,                    //optional. If patrol should be looped. Default: true
       true,                    //optional. If should be deleted initially added to that group waypoint(s). Default: true
       true,                //optional. If patrol should move from nearby town to town using roads. Default: false
       250,                    //optional. Matters only, when patrol is not in "onRoads" mode. Minimum distance of each waypoint from starting point. Default: 100
       1000,                    //optional. Matters only, when patrol is not in "onRoads" mode. Maximum distance of each waypoint from starting point. Default: 2000
       100,                    //optional. Matters only, when patrol is not in "onRoads" mode. Random placement radius for each waypoint. Default: 0
       3,                    //optional. Matters only, when patrol is not in "onRoads" mode. Minimum number of waypoints (excluding start and cycle at end if looped). Default: 3
       5,                    //optional. Matters only, when patrol is not in "onRoads" mode. From this value is randomized number of additional (above minimum) number of waypoints. Set to 0 to achieve exact, minimal number of waypoints each time. Default: 10
       2000,                    //optional. Matters only, when patrol is in "onRoads" mode. Radius for towns search (maximum patrol checkpoints radius). Default: 5000
       0,                    //optional. Matters only, when patrol is in "onRoads" mode. Minimum pause time in seconds at each waypoint. Default: 0
       0                    //optional. Matters only, when patrol is in "onRoads" mode. Maximum pause time in seconds at each waypoint (in each town). Default: 0
       ];

   _patrol = _config call RYD_Patrol;  

_patrol is the local variable that is an array contains both, group and its waypoints [group,waypoints]. To obtain group name use in the same file, after

_patrol = _config call RYD_Patrol;

such line:

_grp = _patrol select 0;

Things are more complicated, if you need to refer to the group name outside this file (do you? If not, this is not important). Global variable (without _) is sufficient, but, as same code is executed for both patrols, second patrol will ovwerwrite value of this global variable, so you must store first patrol group name in other variable before second patrol will be spawned, or use some setVariable technique, perhaps with array inside, that will contain each spawned group.

EDIT: you can then add such line in int.sqf:

MyPatrolGroups = [];

and use such code in last part of patrol.sqf:

_patrol = _config call RYD_Patrol;  

_grp = _patrol select 0;

MyPatrolGroups set [(count MyPatrolGroups),_grp];

MyPatrolGroups will contain as array all group names of spawned patrols, where first may be obtained as eg: _firstpatrol = MyPatrolGroups select 0; second as: _secondpatrol = MyPatrolGroups select 1; and so on...

Yes I'd like to be able to refer to the group name outside the file so I can then do triggers counting units in the group etc. This worked fine before when I used "tankgroup1 = (_config call RYD_Patrol) select 0;"

Share this post


Link to post
Share on other sites

Yes, but this time you will execute same code for both patrols, so tankgroup1 will be defined twice, and second patrol will overwrite first. In presented by me way, you can keep any number of groups in one variable.

Share this post


Link to post
Share on other sites

Ah yes for one script you wouldn't be able to do that.

Sorry but I don't really understand the last part of your last post, you are much more advanced than me with this stuff.

Things are more complicated, if you need to refer to the group name outside this file (do you? If not, this is not important). Global variable (without _) is sufficient, but, as same code is executed for both patrols, second patrol will ovwerwrite value of this global variable, so you must store first patrol group name in other variable before second patrol will be spawned, or use some setVariable technique, perhaps with array inside, that will contain each spawned group.

EDIT: you can then add such line in init.sqf:

MyPatrolGroups = [];

and use such code in last part of patrol.sqf:

_patrol = _config call RYD_Patrol;  

_grp = _patrol select 0;

MyPatrolGroups set [(count MyPatrolGroups),_grp];

MyPatrolGroups will contain as array all group names of spawned patrols, where first may be obtained as eg: _firstpatrol = MyPatrolGroups select 0; second as: _secondpatrol = MyPatrolGroups select 1; and so on...

Maybe I should stick to the 2 separate script method?

Edited by clydefrog

Share this post


Link to post
Share on other sites

If you want, you can use two. But "my" way is really simple. You run spawn code as many times, as you want, each spawn the name of spawned group will be added to the array named MyPatrolGroups. Each of them may be obtained with this "select (number)".

So in this method MyPatrolGroups select 0 is exactly same, as tankgroup1 and MyPatrolGroups select 1 same as tankgroup2 in "two files" method. Do, as you wish, but if you want to do some more scripting in the future, you will need to familiarize with such "tricks" (and more...), as these are more elegant, but, what more important, makes many things far easier and more effective.

Share this post


Link to post
Share on other sites
If you want, you can use two. But "my" way is really simple. You run spawn code as many times, as you want, each spawn the name of spawned group will be added to the array named MyPatrolGroups. Each of them may be obtained with this "select (number)".

So in this method MyPatrolGroups select 0 is exactly same, as tankgroup1 and MyPatrolGroups select 1 same as tankgroup2 in "two files" method. Do, as you wish, but if you want to do some more scripting in the future, you will need to familiarize with such "tricks" (and more...), as these are more elegant, but, what more important, makes many things far easier and more effective.

Yeah that does definitely seem like the better way of doing it and I will try to do it that way. I'll re-read the stuff and try to understand better. Thanks alot for all your help so far.

Where is it the "_firstpatrol = MyPatrolGroups select 0;" and " _secondpatrol = MyPatrolGroups select 1;" code goes?

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×