Jump to content
Sign in to follow this  
hogmason

spacing between 2 spawned markers

Recommended Posts

ok so i am creating 2 markers on any random location

using

[color="#FF0000"]		           _gamelogic = center;
	           _towns = nearestLocations [getPosATL _gamelogic, ["NameVillage","NameCity","NameCityCapital"], 25000]; 
	           _convoy_MARKER_start_position = position (_towns select (floor (random (count _towns))));[/color]

                  _Convoy_start_marker = createMarkerLocal ["startmkr", _convoy_MARKER_start_position];
                  _Convoy_start_marker setMarkerTypeLocal "mil_start";
                  _Convoy_start_marker setMarkerColorLocal "ColorRed";
			      _Convoy_start_marker setMarkerTextLocal "Convoy Start.";

[color="#FF0000"]					  	_gamelogic = center;
	                _towns = nearestLocations [getPosATL _gamelogic, ["NameVillage","NameCity","NameCityCapital"], 25000]; 
	                _convoy_MARKER_end_position = position (_towns select (floor (random (count _towns))));[/color]

				 	  _Convoy_start_marker = createMarkerLocal ["endmkr", _convoy_MARKER_end_position];
                      _Convoy_start_marker setMarkerTypeLocal "mil_end";
                      _Convoy_start_marker setMarkerColorLocal "ColorYellow";
			          _Convoy_start_marker setMarkerTextLocal "Convoy End!!!.";

but i have noticed that most times the 2 markers will spawn pretty close to each othe i.e next town down lol.

is there away i can say stop this from happening maybe setting a check distance of like 2000mtrs.

Share this post


Link to post
Share on other sites

Dug this out from a convoy script i used in the past always worked for me might help ?!

set to 4000 apart you can change to what ever distance

if(!isServer) exitWith{};

_cid = floor(random 10000);
_task16 = format["Convoy Start%1",_cid];
/// get town locations
_towns = nearestLocations [getPosATL player, ["NameVillage","NameCity","NameCityCapital"], 25000];
///start location spawn point
_pos1 = position (_towns select (floor (random (count _towns))));
_RandomTownPosition1 = [_pos1 select 0,_pos1 select 1,0];
_nRoads = _RandomTownPosition1 nearRoads 10;

_rng = 10;

while {((count _nRoads) == 0)} do
   {
   _rng = _rng * 2;
   _nRoads = _RandomTownPosition1 nearRoads _rng;
   };

_RandomTownPosition1 = position (_nRoads select (floor (random (count _nRoads))));

/// convoy end destination

_towns = nearestLocations [_RandomTownPosition1, ["NameVillage","NameCity","NameCityCapital"], 25000];

_RandomTownPosition2 = _RandomTownPosition1;

   {
   if (((position _x) distance _RandomTownPosition2) > 4000) exitwith  {_RandomTownPosition2 = [(position _x) select 0,(position _x) select 1,0]}
   }
foreach _towns;

_nRoads = _RandomTownPosition2 nearRoads 10;

_rng = 10;

while {((count _nRoads) == 0)} do
   {
   _rng = _rng * 2;
   _nRoads = _RandomTownPosition2 nearRoads _rng;
   };

_RandomTownPosition2 = position (_nRoads select (floor (random (count _nRoads))));

_t = format["Convoy Start%1",_cid];
[_t, _RandomTownPosition1, "Icon", [1,1], "TEXT:", _t, "TYPE:", "Start", "COLOR:", "ColorGreen", "GLOBAL", "PERSIST"] call CBA_fnc_createMarker;

_t = format["Convoy End%1",_cid];
[_t, _RandomTownPosition2, "Icon", [1,1], "TEXT:", _t, "TYPE:", "End", "COLOR:", "ColorRed", "GLOBAL", "PERSIST"] call CBA_fnc_createMarker;

////////////////maker CONVOY/////////////////////////

///spawn vehicle  

_grp = creategroup EAST;
_veh1 = ( [_RandomTownPosition1, 001, "Offroad_DSHKM_INS", east] call bis_fnc_spawnvehicle ) select 0;
_veh2 = ( [_veh1 modelToWorld [0,10,0], 001, "SUV_TK_EP1", east] call bis_fnc_spawnvehicle ) select 0;
////move vip2 on map into SUV//////
vip2 moveInCargo _veh2;
vip2 assignAsCargo _veh2;
_veh3 = ( [_veh2 modelToWorld [0,10,0], 001, "Offroad_DSHKM_INS", east] call bis_fnc_spawnvehicle ) select 0;
_veh4 = ( [_veh3 modelToWorld [0,10,0], 001, "Offroad_DSHKM_INS", east] call bis_fnc_spawnvehicle ) select 0;

(units _veh1 + units _veh2 + units _veh3 + units _veh4) joinSilent _grp;

Share this post


Link to post
Share on other sites

Something like this maybe.... but it is possible that no town will ever be found outside the specified radius. So you have to do the check x amount of times... otherwise it can loop forever! Here the check is done 1000 times.

Maybe just grab a random town from the array early on just in case one is not found.

_gamelogic = center;
_towns = nearestLocations [getPosATL _gamelogic, ["NameVillage","NameCity","NameCityCapital"], 25000];
_town1 = _towns select (floor (random (count _towns)));
_convoy_MARKER_start_position = position _town1;

_Convoy_start_marker = createMarkerLocal ["startmkr", _convoy_MARKER_start_position];
_Convoy_start_marker setMarkerTypeLocal "mil_start";
_Convoy_start_marker setMarkerColorLocal "ColorRed";
_Convoy_start_marker setMarkerTextLocal "Convoy Start.";

//remove it from the list
_towns = _towns - [_town1];
_found = false;

//try 1000 times to find a random town that is > 2000m
for "_i" from 1 to 1000 do {
_town2 = _towns select (floor (random (count _towns)));
if (_town1 distance _town2 > 2000) then {
	_convoy_MARKER_end_position = position _town2;
	_Convoy_start_marker = createMarkerLocal ["endmkr", _convoy_MARKER_end_position];
	_Convoy_start_marker setMarkerTypeLocal "mil_end";
	_Convoy_start_marker setMarkerColorLocal "ColorYellow";
	_Convoy_start_marker setMarkerTextLocal "Convoy End!!!.";
	_found = true;
} else {
       //not good so remove it from the list
       _towns = _towns - [_town2];
   };
sleep 0.01;
};

if (_found) then {
hint "Town found";
} else {
hint "Town NOT found";
};

Share this post


Link to post
Share on other sites

thanks guys appreciate the help so i am trying the near roads thing first just to spwan the vehicles on a road " i.e my start mkr"

this is what i am trying but its not working

	           _gamelogic = center;
	           _towns = nearestLocations [getPosATL _gamelogic, ["FlatArea"], 25000]; 
	           _convoy_MARKER_start_position = position (_towns select (floor (random (count _towns))));
			   [color="#FF0000"]_rds = _convoy_MARKER_start_position nearRoads 10;[/color]
                  _Convoy_start_marker = createMarkerLocal ["startmkr", [color="#FF0000"]_rds[/color]];
                  _Convoy_start_marker setMarkerTypeLocal "mil_start";
                  _Convoy_start_marker setMarkerColorLocal "ColorRed";
			      _Convoy_start_marker setMarkerTextLocal "Convoy Start.";


Edited by hogmason

Share this post


Link to post
Share on other sites

How important is it to you the spawned vehicles are created at the same time and place on the road?

I am only asking because I have a couple of suggestions, and one of them, creates one vehicle, moves it x meters before the next vehicle is spawned and so on...

The other suggestion would be seriously checking out ruebe's convoy (especially the fn_findRoute) as it returns:

Returns:
   array [
      0: success (boolean)
      1: route, road objects (array of objects)
      2: route, waypoints (array of positions; usually at every junction)
         - you might wanna drop the first and maybe even the last waypoint,
           depending on what you're up to. You might wanna drop the first
           since some group is already there/starts there. And you might 
           wanna drop the last one (from the last road object to the given
           position - in case that's not a road object too) to ensure that
           some group stays on the road... just draw some markers and you'll
           understand.
      3: distance in m (scalar)
      4: time to calculate the route (scalar)
   ]

in which you can place vehicles every Nth route/road object.

Other than those, you have a couple of different posts going here in which several others have given you very good information.

This really goes along with your post from here also.

You can check out my post here for more info from ruebe: convoy info

Edited by panther42

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  

×