Home   Help Search Login Register  

Author Topic: Random Position  (Read 2230 times)

0 Members and 1 Guest are viewing this topic.

Offline Nephris

  • Members
  • *
Random Position
« on: 27 Oct 2009, 20:11:20 »
Hi folks,
i am sure this has been answered several times but i seem to be too stupid to find the right solution...

So how can i create  random positions on the map, on what e.g. objects/compositions or whatever can be spawned or moved at misson start?

I tried sth like that, but then it left me....

Code: [Select]
_spawns = ["mkpos1", "mkpos2", "mkpos3"]  ;// ingame marker 
_logs = ["log1", "log2", "log3"]  ;//ingame logic
_spawn = _spawns select floor random count _spawns ;// select marker
_log = _logs select floor random count _logs  ;//select logic

_log setpos getmarkerpos _spawn;


Offline Shuko

  • Members
  • *
Re: Random Position
« Reply #1 on: 27 Oct 2009, 21:44:33 »
Didn't test, but something like?

Code: [Select]
call compile format ["
  log%1 setpos [(getmarkerpos ""mkpos%2"" select 0),(getmarkerpos ""mkpos%2"" select 1),0]
",ceil(random 3),ceil(random 3)];
« Last Edit: 28 Oct 2009, 20:56:36 by Shuko »

Offline Nephris

  • Members
  • *
Re: Random Position
« Reply #2 on: 28 Oct 2009, 12:12:05 »
When i understand your example right, i guess we misunderstood.
I dont want to create a random position around a marker, which could be handled via Editor.

I would like to postition log1 random at mkpos1,mkpo2 or mkpos3.


Offline Shuko

  • Members
  • *
Re: Random Position
« Reply #3 on: 28 Oct 2009, 15:23:51 »
You have set of markers and set of logics, you then randomly select a marker and randomly select a logic. Then you move the selected logic to the location of the selected marker?

Offline Nephris

  • Members
  • *
Re: Random Position
« Reply #4 on: 28 Oct 2009, 20:30:28 »
Yes, that is the basic idea.
It doesnt hve to be a logic, as it can also be any object.
I just would like to have a general script i can use,to place logics,objects or units by random to positions that have been created before.

Offline Shuko

  • Members
  • *
Re: Random Position
« Reply #5 on: 28 Oct 2009, 20:56:22 »
Then why did you reject my code without trying?

If you want to move a specific logic/object, just remove the random for that part:

Code: [Select]
call compile format ["
  myLogicOrSomething setpos [(getmarkerpos ""mkpos%1"" select 0),(getmarkerpos ""mkpos%1"" select 1),0]
",ceil(random 3)];

That will move myLogicOrSomething to location of either mkpos1, mkpos2 or mkpos3 marker.

Offline Nephris

  • Members
  • *
Re: Random Position
« Reply #6 on: 28 Oct 2009, 21:32:09 »
I am so sry m8!
Works as it should!

Nevertheless i absolutely dont understand the few lines of script...
What does that mean?

Code: [Select]
""mkpos%1""

Offline Shuko

  • Members
  • *
Re: Random Position
« Reply #7 on: 28 Oct 2009, 22:21:47 »
Double quote marks are because it's inside a string already (format command). They make sure the marker name is a string and not a variable ("mkpos1" vs mkpos1).

%1 is part of the format command, it is replaced by the first value given to it. In this case our first, and only one, "ceil(random 3)", which returns 1, 2 or 3. So, the %1 is replaced by either 1, 2 or 3 and giving us "mkpos1", "mkpos2" or "mkpos3".

Offline Nephris

  • Members
  • *
Re: Random Position
« Reply #8 on: 29 Oct 2009, 08:24:51 »
Getting light on Planet Darkness...

That means if we would have 10 markers, named from mkpos1 - mkpos10 it would be "ceil(random 10)" ?

Offline Shuko

  • Members
  • *
Re: Random Position
« Reply #9 on: 29 Oct 2009, 09:21:17 »
yes

Offline Nephris

  • Members
  • *
Re: Random Position
« Reply #10 on: 29 Oct 2009, 22:29:38 »
coolaroony, cheerz m8
 :good: