Jump to content
Sign in to follow this  
cds1984

Random Waypoints function.

Recommended Posts

Hi,

I have gleened a lot from here for ages and I recently wrote this function which I have had some great results with, since I keep playing the same maps over and over.

Hopefully it will help some one out.

In saying all of that there might be a function exactly the same as this somewhere but since I find it difficult to not reinvent the wheel every time I start something, here is my effort.

// [start,radius,waypoints,behaviour,mode,speed,type,formation,grp,prefix,land] call randomWP
randomWP =
{
 private ["_centre","_radius","_waypoints","_prefix","_pos","_i","_randomX","_randomY","_random","_veh","_type","_formation","_speed","_mode","_behaviour","_grp","_wp","_prefix","_land","_start","_v","_classes"];
 _centre = _this select 0;
 _radius = _this select 1;
 _waypoints = _this select 2;
 _behaviour = _this select 3;
 _mode = _this select 4;
 _speed = _this select 5;
 _type = _this select 6;
 _formation = _this select 7;
 _grp = _this select 8;
 _prefix = _this select 9;
 _land = _this select 10;

 for "_i" from 0 to _waypoints do
 {
   _randomX = floor(random _radius);
   _randomY = floor(random _radius);
   _random = floor(random 2);
   if (_random == 0) then
   {
     _randomX = _randomX * -1;
   };
   _random = floor(random 2);
   if (_random == 0) then
   {
     _randomY = _randomY * -1;
   };

   _pos = [(_centre select 0) + _randomX,(_centre select 1) + _randomY,1];
   _classes = ["Land_DustMask_F","Land_HumanSkull_F","Land_Matches_F","Land_PainKillers_F"];
   _veh = createVehicle [format ["%1",_classes select floor random count _classes],_pos,[],0,"NONE"];
   //waitUntil {(speed _veh) <= 0};
   sleep 0.2;

   if ((!(getPosASL _veh select 2 < 0) && _land) || (!_land)) then
   {
     //_veh = nil;
     deleteVehicle _veh;
     if (_i == 0) then
     {
       _start = _pos;
     };

     //_respawn = format ["MARKER%1",_i];
     //deleteMarkerLocal _respawn;
     //_marker = createMarkerLocal [_respawn, _pos];
     //_marker setMarkerShapeLocal "ICON";
     //_marker setMarkerColorLocal "ColorYellow";
     //_marker setMarkerTypeLocal "mil_objective";

     //Create waypoint.
     _wp = _grp addwaypoint [_pos,_i];
     _wtype = format ["%1",_type select floor random count _type];
     _wspeed = format ["%1",_speed select floor random count _speed];
     _wbehaviour = format ["%1",_behaviour select floor random count _behaviour];
     _wmode = format ["%1",_mode select floor random count _mode];
     _wformation = format ["%1",_formation select floor random count _formation];

     if (_i == _waypoints - 1) then
     {
       _wp setWaypointType "CYCLE";         
     }
     else
     {
       if (_wtype != "") then
       {
         _wp setWaypointType _wtype;
       }
       else
       {
         _wp setWaypointType "MOVE";
       };
     };
     if (_wspeed != "") then
     {
       _wp setWaypointSpeed _wspeed;
     };
     if (_wbehaviour != "") then
     {
       _wp setWaypointBehaviour _wbehaviour;
     };
     if (_wmode != "") then
     {
       _wp setWaypointCombatMode _wmode;
     };
     if (_wformation != "") then
     {
       _wp setWaypointFormation _wformation;
     };
   }
   else
   {
     _i = _i - 1;
     //_veh = nil;
     deleteVehicle _veh;
   };
 };
 _start
};

invoked with,

[[start],radius,waypoints,[behaviour],[mode],[speed],[type],[formation],grp,prefix,land] call randomWP

So,

If i put a marker in the middle of a town 'TOWN' and i want 8 waypoints to possibly span the 200metre diameter and I wanted a random set of 15 OPFor soldiers to spawn in a 100metre random placement around the 'TOWN' marker, I could do this,

_classes = ["O_Soldier_GL_F","O_soldier_AT_F","O_Soldier_SL_F","O_Soldier_AR_F"];
_security = 15;
_pos = getMarkerPos "TOWN";
_grp = createGroup east;
[_pos,100,8,["AWARE","CARELESS","COMBAT"],[""],["LIMITED"],[""],["STAG COLUMN"],_grp,"",TRUE] call randomWP;
for "_s" from 0 to _security do
{
 _soldier = _grp createUnit [format ["%1",_classes select floor (random (count _classes) + 1)],_pos,[],100,"NONE"];
};

I have left the commented out createMarkerLocal bits in the function but it isn't necessary as it was only for troubleshooting.

The last parameter 'land' is a boolean and removes the test for above sea level, so waypoints will be created in the water also, so probably good for amphibious vehicles or air vehicles or divers or... but not so much for infantry etc.

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  

×