Jump to content

Random Position?


FWCentral

Recommended Posts

Posted

I want to create random vehicle positions to use to spawn vehicle later but the way i tried does not work

  
randompos = { } 
randompos[1] = (2514, 2396, 3) 
randompos[2] = (2133, 1009, 10) 
randompos[3] = (1674, 988, 10) 
  

but i get an error when i start the script?

Posted

What you mean use random math? i used random math for the createVehicle, randompos[math.random(1,3)] but this is not the problem it is the randompos[1] = (2514, 2396, 3) i don't think i can use this on it own to get x y z i may need to change it.

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

Posted

Example for unpack:

local dataTable = { 0 , 0 , 0 } 
-- dataTable = { posX , posY , posZ } 
  
local posX , posY , posZ = unpack ( dataTable ) 

unpack unpacks the table.

If my code didn't work, post what you did.

Posted
for index , player in ipairs ( getPlayersInTeam ( getTeamFromName ( "CarJacker" ) ) ) do 
outputChatBox("Go get the stolen car! It is marked on your map.", player, 255,0,0) 
end 

Sorry, my bad, I was mistaken at the team name.

Posted

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 
)    
  

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