Jump to content

math.random


Recommended Posts

I got it working, but it's kind of a bad way, the planes spawns in water sometimes sometimes in a building. so i was thinking of creating a table and selecting a random selection of 3 coordinates, any idea how this could be done? I can't figure it out.

Link to comment

Best thing that I prefer to do so, is create an array in another array giving the X, Y, Z into it. The use a loop to get random info. Something like;

local saves = { 
                {"0","0","5","522"}, 
                {"632","1253","51","522"}} 
local rand = math.rand(#saves); 
  
for i, item in ipairs(saves) do 
    eventVehicle = createVehicle(item[4],item[1], item[2], item[3]); 
end 

Link to comment
Best thing that I prefer to do so, is create an array in another array giving the X, Y, Z into it. The use a loop to get random info. Something like;
local saves = { 
                {"0","0","5","522"}, 
                {"632","1253","51","522"}} 
local rand = math.rand(#saves); 
  
for i, item in ipairs(saves) do 
    eventVehicle = createVehicle(item[4],item[1], item[2], item[3]); 
end 

That will create a vehicle for each line in the table, so if you want the creation of just 1 vehicle you should do something like this:

--x, y, z, model 
spawns = { 
    {200, 200, 34, 522}, 
    {400, 300, 25, 411}, 
    {567, 235, 56, 567} 
    } 
  
function whatEver() 
    rLine = math.random(1, #spawns) 
    createVehicle(spawns[rLine][1], spawns[rLine][2], spawns[rLine][3], spawns[rLine][4]) 
end 
--Remember to call the function C: 

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...