Jump to content
Sign in to follow this  
HateDread

Selecting Pos in random direction and random distance?

Recommended Posts

Hey all,

I'm attempting to use a particular function from Charon's Undead Mod;

[_spawnpos,_spawnnumber,_movepos] call CHN_UNDEAD_fn_CRTZEDGRPMV

Spawns a group of random type undead with _spawnnumber members

and adds a waypoint to position _movepos to the group.

But I would like to select the position that shall be '_Spawnpos' as a random direction from the player, and at a random distance, so they won't know where the group will come from (they won't know what direction from, and how far away they'll be spawned). How does one achieve this?

Also, how do I calculate a position of a group? Ie. the centre of four grouped soldiers. This would be the basis of the above question - I would need it to be a random direction and distance from the -centrer- of the group of four.

Cheers in advance,

- HateDread

Share this post


Link to post
Share on other sites

_dist = 50 + random 50;
_dir = random 360;

_pos = [(getPos player select 0) + (sin _dir) * _dist, (getPos player select 1) + (cos _dir) * _dist, 0];

[_pos,_spawnnumber,_movepos] call CHN_UNDEAD_fn_CRTZEDGRPMV;

That should work for a random direction and random distance between 50 and 100 meters.

Share this post


Link to post
Share on other sites
Also, how do I calculate a position of a group? Ie. the centre of four grouped soldiers. This would be the basis of the above question - I would need it to be a random direction and distance from the -centrer- of the group of four.

Just calcluate the average position of your group members for each coordinate separately.

And as to random positions, you may use commands like isFlatEmpty or selectBestPlaces to get "better" positions. For example you may use isFlatEmpty to verify that the random position is not in water or that it's a big (and empty) enough position to spawn anything. And with selectBestPlaces you could make sure, that they will be spawned between trees/in a forest or on a hill...

Stuff like this helps a lot to make "random" way more coherent.

Share this post


Link to post
Share on other sites

Thank you so much, guys.

@Ruebe

I ended up with this for average position. Works well, thanks...

_grouppos = [((Getpos S1 select 0) + (Getpos S2 select 0) + (Getpos S3 select 0) + (Getpos S4 select 0)) / 4, ((Getpos S1 select 1) + (Getpos S2 select 1) + (Getpos S3 select 1) + (Getpos S4 select 1)) / 4, 0];

@Deadfast

Thanks a lot. That's really helped out :)

If anyone's interested, the script ended up looking like this:

_zattacknum = 0;

while {_zattacknum < 10} do

{

_dist = 150 + random 100;

_dir = random 360;

_pos = [(((Getpos S1 select 0) + (Getpos S2 select 0) + (Getpos S3 select 0) + (Getpos S4 select 0)) / 4) +

(sin _dir) * _dist, (((Getpos S1 select 1) + (Getpos S2 select 1) + (Getpos S3 select 1) + (Getpos S4 select

1)) / 4) + (cos _dir) * _dist, 0];

sleep 35 + random 20 + random 15;

hintsilent "Check";

[_pos,1 + random 2,getpos S1] call CHN_UNDEAD_fn_CRTZEDGRPMV;

_zattacknum = _zattacknum + 1;

};

FirstZAttackDone = 1;

Share this post


Link to post
Share on other sites
I ended up with this for average position. Works well, thanks...

Well that might work (for now), but I'm afraid it's not only ugly, but also dangerous. What happens if you come back later at some point and decide to add another unit to this group?

Write a function that takes any amount of objects or positions, returning the average position. Then you might find yourself using that function for many other purposes...

In the end you should be able to write something like this:

  _center = (units _grp) call HD_averagePosition;

where _grp is probably (group player) and HD_averagePosition would be the function you'd need to write.

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  

×