Jump to content

help tables and random stuff


MAB

Recommended Posts

i don't know how to make mta create one of these markers randomly when an event happens.. and on the hit one of the other two will be created and the old one get destroyed i tried and failed so i deleted the old code and i am here for help

markers = { 
marker1 = createMarker ( 1640.04163, -2451.72778, 12.55469, "cylinder", 1.5, 255, 255, 0, 170 ), 
marker2 = createMarker ( -1641.87573, -183.24684, 13.14844, "cylinder", 1.5, 255, 255, 0, 170 ), 
marker3 = createMarker ( 1566.22876, 1498.72900, 9.83527, "cylinder", 1.5, 255, 255, 0, 170 ) 
}       

Link to comment

Put your positions like that in a table.

markers = { 
    {1640.04163, -2451.72778, 12.55469}, 
    {-1641.87573, -183.24684, 13.14844}, 
    {1566.22876, 1498.72900, 9.83527} 
} 

Use math.random to get random position.

pos = markers[math.random(1, #markers)] 

And then create a marker.

marker = createMarker(pos[1], pos[2], pos[3], "cylinder", 1.5, 255, 255, 0, 170) 

Use onClientMarkerHit and destroy previous marker and repeat step from the start.

Continue from there by yourself.

Link to comment
Put your positions like that in a table.
  
Use math.random to get random position. 
[lua]pos = markers[math.random(1, #markers)] 

And then create a marker.

marker = createMarker(pos[1], pos[2], pos[3], "cylinder", 1.5, 255, 255, 0, 170) 

is better if use like this:

local x, y, z = unpack(markers[math.random( #markers)]) 
local marker = createMarker(x, y, z, "cylinder", 1.5, 255, 255, 0, 170) 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...