Jump to content
Sign in to follow this  
1para{god-father}

Generate Random Position

Recommended Posts

I am trying to get a random position for my spawns , It works fine but when I need to spawn in say 10 group I would like to have each spawn in a diffrent location, I know I can create the below 10 times and add a _1 after each varible but is there a quicker way as that would be a lot of code just to get a new _positionToSpawnIn

_vehicleambush=VEH1
_ang = random 360; 
_dis = 100;
_dx = sin(_ang)*_dis;
_dy = cos(_ang)*_dis;
_positionToSpawnIn = [((getpos _vehicleambush) select 0) + _dx, ((getpos _vehicleambush) select 1) + _dy, 0]; 

_upsgrp1 = [1,_positionToSpawnIn,1,["ambush1","spawned","showmarker","delete:",30,"respawn:",5]] execVM "SCRIPTS\UPSMON\MON_SPAWN.SQF";

Share this post


Link to post
Share on other sites
_pos = getPos _vehicleambush;
_radius = 100;

// Find a good spot for the spawn (open area, not in trees)
_exp = "(1 + meadow) * (1 - forest) * (1 - trees)";
_prec = 100;
_bestplace = [url="http://community.bistudio.com/wiki/selectBestPlaces"]selectBestPlaces[/url] [_pos,_radius,_exp,_prec,1];
_spot = _bestplace select 0;
_positionToSpawnIn = _spot select 0;

Share this post


Link to post
Share on other sites

I think he meant that he wants 10 different areas within which a random position will be selected. Or did you want 10 different groups to spawn randomly in 10 different positions within the same area?

Please specify.

Share this post


Link to post
Share on other sites

10 diffrent Groups in diffrent positions wityhing the area, so a random _positionToSpawnIn each time.

Will try that kylania now - many thanks

Share this post


Link to post
Share on other sites

Oh, in that case plop down 10 markers and choose one at random? The code I did will just pick a random spot in the open within 100 meters of something.

Share this post


Link to post
Share on other sites

That would not be possible as it is dynamic the Area i need to attack, the vehicle could be anywhere on the map so once i trigger i need to spawn in a ambush i get a random location already but if i want to spawn a ambush of 10 groups i need 10 random location so the only way i know is to generate my script 10 times

I.e 10 diffrent _positionToSpawnIn

_vehicleambush=VEH1
_ang = random 360; 
_dis = 100;
_dx = sin(_ang)*_dis;
_dy = cos(_ang)*_dis;
_positionToSpawnIn = [((getpos _vehicleambush) select 0) + _dx, ((getpos _vehicleambush) select 1) + _dy, 0]; 

_upsgrp1 = [1,_positionToSpawnIn,1,["ambush1","spawned","showmarker","delete:",30,"respawn:",5]] execVM "SCRIPTS\UPSMON\MON_SPAWN.SQF"

Share this post


Link to post
Share on other sites

Use a loop:

_vehicleambush=VEH1;
_grps = [];

for "_x" from 1 to 10 do
{
_ang = random 360; 
_dis = 100;
_dx = sin(_ang)*_dis;
_dy = cos(_ang)*_dis;
_positionToSpawnIn = [((getpos _vehicleambush) select 0) + _dx, ((getpos _vehicleambush) select 1) + _dy, 0]; 

_newgrp = [1,_positionToSpawnIn,1,["ambush1","spawned","showmarker","delete:",30,"respawn:",5]] execVM "SCRIPTS\UPSMON\MON_SPAWN.SQF";
_grps = _grps + [_newgrp];

};

Then you end up with an array of all the returned groups.

Share this post


Link to post
Share on other sites
_pos = getPos _vehicleambush;
_radius = 100;

// Find a good spot for the spawn (open area, not in trees)
_exp = "(1 + meadow) * (1 - forest) * (1 - trees)";
_prec = 100;
_bestplace = [url="http://community.bistudio.com/wiki/selectBestPlaces"]selectBestPlaces[/url] [_pos,_radius,_exp,_prec,1];
_spot = _bestplace select 0;
_positionToSpawnIn = _spot select 0;

any ideas how I would modify this to get an open area further than say 500m but less that 1000m

Share this post


Link to post
Share on other sites

Instead of using _pos as the starting location based on an object just use the code in the OP and change the dist to 750. That'll give you a random spot 750m away in a random direction, then use my code (setting _radius to 250) to find a clear spot with 250m which will result in a clear spot 500-1000 meters from the start.

Share this post


Link to post
Share on other sites

the script is to move virtual artillery within correct range to be able to fire anywhere on map so went with this to ensure position returned is always with the 2375m - 5800m required for M119

_pos = getmarkerpos "Arty1";
_radius = 2500 + random 3000;
_exp = "(1 + meadow) * (1 - forest) * (1 - trees)";
_prec = 100;

_bestplace = selectBestPlaces [_pos,_radius,_exp,_prec,1];
_spot = _bestplace select 0;
_spot2 = _spot select 0;

Share this post


Link to post
Share on other sites

hmmm...this seems like a interesting thing!

One question though? I dont really understand none of this scripting stuff, so what would I have to do to make a simple script that will search for random flat areas away from a town/building and place a tent or two with a camp fire and maby a weapons crate or other small miscs stuff, and a small group of enemy guarding/patroling/doing stuff??? Is there already a script like this made that someone can share please? Or help me write one??

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  

×