Random Vscript Triggers

Posted by Shorembro on Mon 08 Jan 2007 04:07 PM — 2 posts, 10,905 views.

#0
Hi, I'm new to this.

I'm just trying to make a trigger so that when I get the message:

Move!

I move my character in a random direction. (north, east, south, west)

Thank you so much,
Jennifer

EDIT - uh just trying out Lua, how might I randomize this in Lua per say?
Amended on Mon 08 Jan 2007 05:59 PM by Shorembro
Australia Forum Administrator #1
This trigger will do that:


<triggers>
  <trigger
   enabled="y"
   match="Move!"
   send_to="12"
   sequence="100"
  >
  <send>
local directions = { "n", "s", "e", "w" }

Send ( directions  [ math.random (#directions) ] )
</send>
  </trigger>
</triggers>



If you wanted more directions (eg. up, down, ne, nw etc.) then add them to the list.

What this does is use math.random to randomly pick an item from the "directions" table, in the range 1 to the number of entries (4 in the example above).