Jump to content
Sign in to follow this  
mike@uk

Several Possible locations for 1 object?

Recommended Posts

Is there a way to make it so that an item appears in a random place out of a number of possible places, for example if I had a Sniper then on the first mission attempt he would be stood in a bush, but then if I started again he might be stood on a tower, etc?

I know you can change the placement radius but thats abit too random, also it doesn't matter if it's exactly the same unit in each location, just as long as only 1 appears.

Hope that makes sense. tounge2.gif

Share this post


Link to post
Share on other sites

If your spawn locations are that specific like "on a tower", then you

should put all imaginable spawn locations into an array like

_spcoords1=[x1,y1,z1];

_spcoords2=[x2,y2,z2];

_spcoords3=[x3,y3,z3];

_spawncoordsarray=[_spcoords1,_spcoords2,_spcoords3];

and then make a random element selection:

_n= round (random (count _spawncoordsarray));

_spawnpos=_spawncoordsarray select _n;

_type createUnit [_spawnpos, YOURGROUP];

You can then subtract these already used coordinates from the array

_spawncoordsarray=_spawncoordsarray-[_spawnpos];

and run it again for the remaining units to spawn.

Hope that helped.

Share this post


Link to post
Share on other sites
Quote[/b] ]_n= round (random (count _spawncoordsarray));

What you really meant was this...

Quote[/b] ]_n= floor (random (count _spawncoordsarray));
smile_o.gif

Share this post


Link to post
Share on other sites

Lol, if you say so,knowing better what i mean.

Mike@Uk just needs a random selection, so it's all about the random command.

Either with "floor" (as you suggest) or without it, he gets a "select"-compatible rounded random number and all possible spawnlocations will be allocated to the units anyway, so each unit will eventually get one of the positions in the array,regardless if the result is next to lowest integer in relation to the random result or not.

Share this post


Link to post
Share on other sites

My reasons to suggest 'floor' instead of 'round' are these:-

For a 3-element array, "round(random count _array)" will return 0,1,2,or 3. Obviously 3 is an invalid index. Also the probabilities are not evenly distributed. Both 0 and 3 (end cases) have half the probability of 1 and 2. smile_o.gif

Share this post


Link to post
Share on other sites

No need for floor or round. If i may show you an example from a training mission i've made.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_roll1 = random 4

? _roll1 <= 1 : goto "east"

? _roll1 <= 2 : goto "north"

? _roll1 <= 3 : goto "south"

? _roll1 <= 4 : goto "west"

As the script jumps to #east if it is smaller or equal to 1 the 3 others don't have any effect. And now if it is smaller than 3, the script will jump to #south only if _roll1 is greater than 2.

smile_o.gif

Share this post


Link to post
Share on other sites

Thanks for all your help, I used the marker group one, works a treat. tounge2.gif

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  

×