Jonathan
Captain
  
Posts: 295
Registered: 5-4-2003
Member Is Offline
|
|
How to use the random function?
I want to make a map where one of the objectives randomly teleports to one of three teleport markers on the map. But I can't figure out the Random
function. It always seems to return a value of 1. See code below.
// randomly spawn the objective
if random(3) then
set(v1,rnd)
teleport(8,rnd)
endif
In the code below which comes straight from the WAC list, the game displayed "1, 2, 3, 1, 2, 3, 1, 2, 3,...." over and over."
; random(#) randomly true 1 in # times, sets RND for additional tests
;example select 1 of 3 randomly
dornd
text "1"
next
text "2"
next
text "3"
enddo
Anyone know how to use the Random function?
Jonathan
|
|
|
Saedor
Corporal
 
Posts: 145
Registered: 5-26-2004
Location: Indiana, USA
Member Is Offline
Mood: Unperturbed
|
|
What it does is return a randomly true value once every (#) seconds. So, in your WAC, every three seconds the computer will check the random function.
If it comes back true, the objective will spawn. If false, it won't.
I don't think you can use rnd as a variable. It's either gonna be 1 (true) or 0 (false).
|
|
|
Jonathan
Captain
  
Posts: 295
Registered: 5-4-2003
Member Is Offline
|
|
If that's true, then it would explain the first algorithm. However, I'm puzzled over the the 2nd algorithm which comes from the WAC file. It claims
that its suppose to select 1 of 3 randomly. However when I used it, dornd produces "1, 2, 3, 1, 2, 3, ..."
The example listed in the WAC file after the DoRND is DoSEQ. Seems to me that they both produce the same results.
;example select 1 or 3 sequentialy
doseq
text "1"
next
text "2"
next
text "3"
enddo
Oh well, I was hoping to make a random mission, but its not a big deal. Thanks.
Jonathan
|
|
|
Jonathan
Captain
  
Posts: 295
Registered: 5-4-2003
Member Is Offline
|
|
Well I've about given up on trying to randomly an object some where on the map. I thought this piece of code would do it. Nope.
// randomly spawn the object
if random(3) and never() then
teleport(8,V1)
text "done"
else
add(v1,1)
endif
|
|
|
p1gs1ck
Map Rater
       
Posts: 522
Registered: 7-18-2003
Location: Limbo
Member Is Offline
Mood: Vegas2!
|
|
Yep I wasted a lot of time finding this out last year or so (check novaworld forums for my posts!)
The random function doesn't truly work - as it always returns the same numbers (hardly random) but Jonathan worry not.
A way to 'fake' random events is to check for ai kills.
So in your example you want a one in 3 chance of an event happening.
Have 3 ai attack players somewhere near start of mission (they can be in a much larger group of ai) and only trigger your event much later if a
particular ai is killed 1st
so
event check for kills
if ai 1 dead
and ai 2 not dead
and ai 3 not dead
set v1=1 (v1 starts at 0)
So if ai 2 or 3 are killed 1st v1 stays at 0
but if ai 1 killed 1st then v1=1
then your event can trigger later
event take action
if v1=1 and player in area 4
etc
If you think about this there is a lot of variance you can add. I used it in my BHD map bridgadoom to destroy either a right or left walkway when
players stepped on it - based on which of a group of 4 ai they killed 1st at start of map (players fell to their death if they stepped on the wrong
one )
Hope this makes sense.
P1g
"I am not responsible for your stupidity, but if I had a sledgehammer it could be arranged"
|
|
|
p1gs1ck
Map Rater
       
Posts: 522
Registered: 7-18-2003
Location: Limbo
Member Is Offline
Mood: Vegas2!
|
|
I see in your post you want 3 possible outcomes so do it like this
event check for ai 1 dead 1st
if ai 1 dead
and ai 2 not dead
and ai 3 not dead
set v1=1
event check for ai 2 dead 1st
if ai 1 not dead
and ai 2 dead
and ai 3 not dead
set v1=2
event check for ai 3 dead 1st
if ai 1 not dead
and ai 2 not dead
and ai 3 dead
set v1=3
so you can do more conditional events later to do teleports
event teleport
if v1=1 teleport to marker 1
event teleport 2
if v1=2 teleport to marker 2
event teleport 3
if v1=3 teleport to marker 3
I think ai cannot die simultaneously so even if you naded them 1 of them dies 1st and triggers the relevant event
But, if they can die simultaneously do following
if ai 1 dead and
ai 2 dead and
ai 3 dead and
v1 = 0
set v1=1
should cover it...
Good luck
"I am not responsible for your stupidity, but if I had a sledgehammer it could be arranged"
|
|
|
Jonathan
Captain
  
Posts: 295
Registered: 5-4-2003
Member Is Offline
|
|
Thanks for the suggestion. I'll give it a try. I see what you did with checking which A/Is have died. I might also use trigger areas to see
which locations the player has been to. Between the two, this should be enough to generate a random spawn/teleport.
Thanks again.
Jonathan
|
|
|
Saedor
Corporal
 
Posts: 145
Registered: 5-26-2004
Location: Indiana, USA
Member Is Offline
Mood: Unperturbed
|
|
I know we're starting to grasp at straws here, but another possible way would be to set up two events;
The first random event which would either trigger A) teleport spawnpoint to target #1 if true, or B) trigger event #2 if false.
Then, event #2 would C) teleport spawnpoint to target #2 if true, or D) teleport spawnpoint to target #3 if false.
I haven't tried it yet... but it might work.
|
|
|