Jump to content
Sign in to follow this  
galzohar

Random placement

Recommended Posts

I was wondering if there was a simple way to make a script to pick up random numbers for coordinates and then place an object at those coordinates. The idea is to have a mission with randomly placed starting location for each squad and the objective (but needs a script to make sure the distances work right).

Share this post


Link to post
Share on other sites

or if you go to markers and place one of those "empty" ones (its the one with a box in the center and then two L shaped things on either side) you can group a unit to a whole bunch of them and it will randomly choose which placed to put him.

Ex.

Put a man and group him with 3 of those markers

One in a house. one in a forest and one by a factory.

He will randomly appear at any one of them.

I cant remember if his normal starting spot is also an option or not though.

Share this post


Link to post
Share on other sites

There's a lot you can do in the editor to give a more chaotic, random but still controlled feel to any mission. One of the things I do with missions I make is to make it playable for me, so that I get something new & unexpected out of it each time as well. Another thing I do is to make sure that things kick off whether I'm there or not, so that I feel I'm part of something bigger.

Anyways, here's a few ideas on getting randomisation into missions.

First of all, as far as scripts go the UPS (Urban Patrol Script) is rather excellent:

Kronzy's UPS script.

it adds patrol waypoints to units you want it to. Just the lead unit in a group is necessary, the script flows downward. It also can randomise start positions so you really never know where they are going to be unless you first do a thorough recce. And it's a script solution, which means no necessary addons.

Another thing you can do is to randomise the number of units you will encounter, so that not only will you not know the location, but you can not even be sure of numbers. Create a group of footsoldiers, either by using the add group function in the editor (F2) or by making up the group yourself. It will have one leader and as many units attached to him as you added.

Lets say you added a 12-man patrol.

Now, in each soldier's properties box (accessed by double-clicking him) you can see a field called Placement radius. If you enter a number here it will randomise that unit's starting position, so if you type "200" the unit will materialise anywhere in a 200 meter radius of his editor position. This only works on either standalone units or in leaders of groups. That means that wherever the leader appears, all his group will appear too. Already we have some randomisation.

In the properties box there is a slider called Probability of presence (PoP), which is a value (0-1) that represents the probability of that particular unit even existing. Set it to 25% of the way up, and there's a 25% probability that the unit will spawn. Don't touch the leader's PoP slider, and lets say we don't touch the next 5 guys' PoP sliders either. For all the other units, we set the slider to roughly 25%.

This means that the patrol unit will have a minimum of 6 units, a maximum of 12 units, but the likeliehood is that it's going to be closer to 6.

Likewise, set all the sliders to 75% and the patrol will consist of a minimum of 6 units, a maximum of 12, but the likeliehood is that it will be closer to 12.

So you can see that you can mess with the probabilities quite substantially right in the editor. In fact, you can mess quite a lot, you can add more AT troops for example, and have them *slightly* more likely to exist than snipers, and you know roughly the sort of trouble you're going to be in in a vehicle as opposed to on foot, and you can set that group's patrol area appropriately.

Edited by DMarkwick

Share this post


Link to post
Share on other sites

That's not exactly what I was looking for. What I need is to place the entire defending squad and the objective they're defending in the same randomized location, and then placing the attacking team exactly (or around) 1km away from them in a random direction. Then having a "objective here" and "attackers coming from here" markers on those chosen locations to finish it up.

Share this post


Link to post
Share on other sites

Right, so you place an invisible object (say an invisible helo landing pad) with it's placement radius set to how you want it.

Then for each object (or leader) you use the invisible object as the starting point for placements and add offsets.

_invPos = getPos InvObj;
setPos LeaderName [(_invPos select 0) + 20, (_invPos select 1) + 5, _invPos select 2];

Share this post


Link to post
Share on other sites

// Define the distance
_dist = 1000;
// Get a random direction
_dir = random 359;

// Move the person _DIST meters away from the destination (in the direction of _dir)
unit_name_here SetPos [(getMarkerPos "spawnCenter" select 0)-_dist*sin(_dir),(getMarkerPos "spawnCenter" select 1)-_dist*cos(_dir)];

That should do the trick. :) Requires a marker named "spawnCenter" obviously.

Share this post


Link to post
Share on other sites

For some reason some objects can't be moved in relation to some objects. Also your code gives "local variable in global space" error when placed in the initialization field. I can't seem to be able to move markers no matter what.

Also moving the leader doesn't move the rest of the squad with him, and setting each one's relative position is rather annoying... Any better way to do it?

Also any way to know what numbers translate to which locations on the map other than trial and error?

Edited by galzohar

Share this post


Link to post
Share on other sites

Still can't get this to work. I managed to place some stuff in relation to another object with placement radius (which is funny and is bad programming since it relies on "who spawns first?" which isn't really defined and can only be checked through trial and error), but anyway I couldn't do anything that requires variables, not with the above example and not in other ways.

Share this post


Link to post
Share on other sites

Still can't figure out proper use of variables.

Share this post


Link to post
Share on other sites
// Define the distance
_dist = 1000;
// Get a random direction
_dir = random 359;

// Move the person _DIST meters away from the destination (in the direction of _dir)
unit_name_here SetPos [(getMarkerPos "spawnCenter" select 0)-_dist*sin(_dir),(getMarkerPos "spawnCenter" select 1)-_dist*cos(_dir)];

That should do the trick. :) Requires a marker named "spawnCenter" obviously.

Still can't make the variables work.

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  

×