Jump to content

Random Position?


FWCentral

Recommended Posts

local randPosTable = { 
{ 0 , 0 , 0 } , 
{ 1 , 1 , 1 } , 
--etc 
} 
  
function getRandomData ( table ) 
return table [ math.random ( #table ) ] 
end 

now use it like getRandomData ( randPosTable )

And the returned data will be a table, since the data in the table is several tables

So you will use it like:

local data = getRandomData ( randPosTable ) 
local x = data [ 1 ] 
local y = data [ 2 ] 
local z = data [ 3 ] 

Link to comment

this is more better:

  
local randPosTable = { -- 1 x 2 y 3 z 4 rotation 5 skin 6 interior 7 dimension 8 team 
{ 0 , 0 , 0 , 0 , 15 , 0 , 0 , nil } , 
{ 1 , 1 , 1 , 0 , 25 , 0 , 0 , nil } , 
-- and etc 
} 
  
function randomSpawn(player,randPosTable) 
    local random = math.random(1,#randPosTable) 
    spawnPlayer(player, 
    randPosTable[random][1], 
    randPosTable[random][2], 
    randPosTable[random][3], 
    randPosTable[random][4], 
    randPosTable[random][5], 
    randPosTable[random][6], 
    randPosTable[random][7], 
    randPosTable[random][8])  
end 
  

example:

  
addEventHandler("onPlayerJoin",root, 
    function() 
        randomSpawn(source,randPosTable) 
        fadeCamera(source, true)  
        setCameraTarget(source, source) 
    end 
)    
  

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