Jump to content

math.random


Recommended Posts

Posted

I'm not sure how to use math.random

I'm trying to create a vehicle randomly on the map can anyone give me an example?

I tried this but it's not working

planeCrash= createVehicle ( 577, math.random,math.random,math.random) 

Thanks.

Posted

The X coordinate is -3000 on the edge of the western side and 3000 on the east. The Y coordinate is -3000 in the south and 3000 in the north.

Posted

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.

Posted

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 

Posted
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: 

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