Home   Help Search Login Register  

Author Topic: Random placement ?  (Read 628 times)

0 Members and 1 Guest are viewing this topic.

Berghoff

  • Guest
Random placement ?
« on: 21 Feb 2004, 18:32:12 »
:) Hi again.

Now I nearly completed my map I have 1 more question :).

Q: I have a marker of 1000 by 1000 and in that area I need to randomly spawn this:
Tank_West (Empty tank), W1, W2,W3,W4,W5,W6,W7,W8 (all soldiers), these units need to spawn together in the marker area randomly after you completed a objective... Any help ?  ;)

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:Random placement ?
« Reply #1 on: 22 Feb 2004, 01:21:17 »
You could use some code looking a little something like this:

...
_randx = random 1000
_randy = random 1000

"Unitname" createunit [[(getmarkerpos "marker" select 0) + (_randx - 500), (getpos op select 1) + (_randy - 500), 0], group, "init line"]
...


That would randomly choose an x and y value between 0 and 1000. Then it would place your unit within a 1km 'box' of the center of your marker.

The reason we define variables for the random values rather than just using the 'random' command is to keep all your guys together ;)

Hope that helps you out

Berghoff

  • Guest
Re:Random placement ?
« Reply #2 on: 25 Feb 2004, 13:54:44 »
Hi, I have this now:
Code: [Select]
_rand = random 7

? _rand < 1: Tank_East2 setpos getpos Place1
? _rand > 1 AND _rand < 2 : Tank_East2 setpos getpos Place2
? _rand > 3 AND _rand < 4 : Tank_East2 setpos getpos Place3
? _rand > 4 AND _rand < 5 : Tank_East2 setpos getpos Place4
? _rand > 5 AND _rand < 6 :Tank_East2 setpos getpos Place5
? _rand > 6 AND _rand < 7 :Tank_East2 setpos getpos Place6
? _rand > 7 : Tank_East2 setpos getpos Place7

But it seems that sometimes the tank doesn't move at all (Doesn't choose new position when I active this script), can some1 help me with this ?  :-[

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:Random placement ?
« Reply #3 on: 25 Feb 2004, 14:34:19 »
What happens if _rand = 3 exactly?   You need to use <= rather than <.
Plenty of reviewed ArmA missions for you to play

micropilot

  • Guest
Re:Random placement ?
« Reply #4 on: 25 Feb 2004, 14:38:37 »
What haapens if the random value is between 2 and 3 (2.65) ?

Offline icarus_uk

  • Members
  • *
  • LiarLiarPants Inflame True
    • [furryclan]
Re:Random placement ?
« Reply #5 on: 25 Feb 2004, 15:12:37 »
Use;

? _rand <= 1 :goto ......
? _rand <= 2 :goto ......
? _rand <= 3 :goto ......
? _rand <= 4 :goto ......
? _rand <= 5 :goto ......
etc

This way, if _rand = 0.26 it finds the first line and as its less than 1 it goes to the first place.  If _rand is 1.96 it goes to the second place, as its less than 2.  And so on.  You dont need to state an upper limit, as the script will stop checking _rand after it finds the first condition that is satisfied.

If your mission is going to be played online, you'll need to stop the clients from generating their own value of _rand, as they will all come up with different values.