Jump to content
Sign in to follow this  
alleycat

How randomize the position of something?

Recommended Posts

How randomize the position of something by choosing one of several positions? I assume there is markers involved, and I would also like to know how to make invisible markers.

Share this post


Link to post
Share on other sites

Very easy, but not very well known, I never figured out why : group the unit or object with markers positioned where you want. That's all.

Share this post


Link to post
Share on other sites

Wow, that is some real mission editing kung fu.

Share this post


Link to post
Share on other sites

In general, you have the position of something, then you can randomize it a bit by

_pos = [_x,_y,_z]; // thats your pos
_radius = <a number>; 
_randompos = [_x + _radius - random 2*_radius, _y + _radius - random 2*_radius, z];

This will generate a random position in a circle of _radius meters around _pos.

An "empty" marker is indeed invisible, however it is not that simple to get the area an empty marker is covering. You can make ANY marker invisible by setting its alpha value to zero:

marker setMarkerAlpha 0;

Edited by Bon

Share this post


Link to post
Share on other sites
Take a look at this script, it's super simple to read and understand :)

http://forums.bistudio.com/showthread.php?t=94061

A marker set to "Empty" is invisible :)

Well, for randomizing starting positions, no need to use a script. It's always better to try and use editor's possibilities than script. A lot of very powerfull tools are so badly used (such as game logics with waypoints, guard triggers etc...).

Share this post


Link to post
Share on other sites
Well, for randomizing starting positions, no need to use a script. It's always better to try and use editor's possibilities than script. A lot of very powerfull tools are so badly used (such as game logics with waypoints, guard triggers etc...).

I know it's not needed but i prefere it because it's very simple to use :)

Anyways it was just a suggestion and alleycat can take it or leave it ;)

Share this post


Link to post
Share on other sites

I was looking for randomly selecting exact locations, and the marker group thing did it. Thx to all other suggestions.

Share this post


Link to post
Share on other sites
Very easy, but not very well known, I never figured out why : group the unit or object with markers positioned where you want. That's all.

wait, what...

wow i cant believe it, i never knew this haha. thnx for the info!

Share this post


Link to post
Share on other sites
Very easy, but not very well known, I never figured out why : group the unit or object with markers positioned where you want. That's all.

Holy cow batman, that is seriously ninja!!! Brilliant Prof, that opens up realms of possibilities to the non-scripters amongst us!!!!! :yay:

PS OK on the same topic, say I'm placing a tank or static weapon at 1 of 5 positions (note that anyone using this ninja method, the intial unit position also counts as a random position, so if you place 4 markers, you will actually have 5 random positions)..

How can I easily use the setdir command so that at say marker A, the setdir is 45, at B its 185, C its 270, etc? The marker orientation seems to make no difference, and markers have no init line, so I'm gathering a script will be involved. In laymans terms I'm guessing the logic will be:

If tank pos = marker A, tank setdir = 45

If tank pos = marker b, tank setdir = 185, etc?

Edited by gnarly_rider

Share this post


Link to post
Share on other sites
Very easy, but not very well known, I never figured out why : group the unit or object with markers positioned where you want. That's all.

Hmm, I've been giving this a very good workout, and am actually no longer convinced that it is purely random; I see a fairly hefty bias towards the unit/objects actual start location, over the various alternative marker locations.

E.g. I have an ammo crate with 4 grouped markers. Easily 3 out of 5 mission restarts sees the ammo crate at its actual placed (in the mission editor) location.

I also hava ZSU grouped with about 12 markers, but easily 25% of the time it spawns at its placed location as well.

Be curious if others can confirm or deny this level of bias.

Think I'll give the scripting option a go. I'm going to do somehting along the lines: place 5 markers, A1 - A5. Place the unit, called ZSU1. In its Init, run a sript called random_loc. Random_loc is basically a Switch, assessing a random (rounded) variable between 1 and 5: each case basically sets the unit to that markers location.

If anyone has a simpler way of accoplishing this script, particauly if it bypasses the need to explicitily name each marker in the switch and have a case explicitly for each marker, that would be great, I was thinking there might be somehting funky you can do with game logcs or something (they seem to be omniproesent and mysterious)?

Edited by gnarly_rider

Share this post


Link to post
Share on other sites
E.g. I have an ammo crate with 4 grouped markers. Easily 3 out of 5 mission restarts sees the ammo crate at its actual placed (in the mission editor) location.

What happens if the ammo crate itself has it's placement radius set to a wide value?

Share this post


Link to post
Share on other sites
What happens if the ammo crate itself has it's placement radius set to a wide value?

It already does (200m). The problem is that the ammo crate is mostly still placded in the 200m radius of its primary location, rather being truly randomly placed in any of the other 4 markers and their 200m placemnt raduii.

And no, a massive placement radius is not a solution for my needs: I need the control afforded by markers (ammo crates needs to be near buildings/infrastructure)

Share this post


Link to post
Share on other sites

I just thought that a massive placement radius might initially place it closer to a random marker first, but if you say that the fist "level" of placement is the marker position THEN the random placement kicks in, well that knocks my thoughts out of the hat :)

I guess for a truly random placement among x number of possibilities, and given that the above behaviors are true, a script-based one is needed.

Share this post


Link to post
Share on other sites

I also need this but in a different way. I would like to use exact locations via the setpos command. I want this because i want to randomize the position of a civilian unit inside buildings and doing this with markers will place the unit in the roof of buildings.

Let's say i have 20 specific setpos coordinates i made. How can i randomize the selection of these 20 specific locations? Also this is for a MPMission. Will there be problems regarding locality using the setpos command?

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  

×