Jump to content

Random Spawn


#DaMiAnO

Recommended Posts

Hi!

I have this:

That's working, but when anyone dies, it not spawn him, and i see error in debugscript.

local randomSpawnTable =  
{ 
    { -2818.3391, 1134.4768, 26.1129, 179.2400 }, 
    { 2021.3114, 1344.1099, 10.8203, 269.5800 }, 
    { 2221.3726, 1838.4792, 10.8203, 90.3700 } 
} 
  
function randomSpawn(thePlayer, randomSpawnTable) 
    local random = math.random(1, #randomSpawnTable) 
    spawnPlayer(thePlayer, 
    randomSpawnTable[random][1], 
    randomSpawnTable[random][2], 
    randomSpawnTable[random][3], 
    randomSpawnTable[random][4]) 
end 
  
function onPlayerJoin() 
    fadeCamera(source, true) 
    setCameraTarget(source, source) 
    randomSpawn(source, randomSpawnTable) 
end 
addEventHandler("onPlayerJoin", g_root, onPlayerJoin) 
  
function onPlayerDeath() 
    fadeCamera (source, false, 1.0, 255, 0, 0) 
    setTimer(randomSpawn, 3000, 1, source) 
    setTimer(fadeCamera, 2500, 1, source, true, 0.5) 
end 
addEventHandler("onPlayerWasted", g_root, onPlayerDeath) 

attempt to get length of local 'randomSpawnTable' (a nil value)
Link to comment
local randomSpawnTable =  
{ 
    { -2818.3391, 1134.4768, 26.1129, 179.2400 }, 
    { 2021.3114, 1344.1099, 10.8203, 269.5800 }, 
    { 2221.3726, 1838.4792, 10.8203, 90.3700 } 
} 
  
function randomSpawn( thePlayer, randomSpawnTable ) 
    local random = math.random( 1, #randomSpawnTable ) 
    spawnPlayer(  
        thePlayer, 
        randomSpawnTable[random][1], 
        randomSpawnTable[random][2], 
        randomSpawnTable[random][3], 
        randomSpawnTable[random][4] 
    ) 
end 
  
function onPlayerJoin( ) 
    fadeCamera( source, true ) 
    setCameraTarget( source, source ) 
    randomSpawn( source, randomSpawnTable ) 
end 
addEventHandler( "onPlayerJoin",root, onPlayerJoin ) 
  
function onPlayerDeath( ) 
    fadeCamera ( source, false, 1.0, 255, 0, 0 ) 
    setTimer( randomSpawn, 3000, 1, source,randomSpawnTable ) 
    setTimer( fadeCamera, 2500, 1, source, true, 0.5 ) 
end 
addEventHandler( "onPlayerWasted", root, onPlayerDeath ) 

Edited by Guest
Link to comment
local randomSpawnTable =  
{ 
    { -2818.3391, 1134.4768, 26.1129, 179.2400 }, 
    { 2021.3114, 1344.1099, 10.8203, 269.5800 }, 
    { 2221.3726, 1838.4792, 10.8203, 90.3700 } 
} 
  
function randomSpawn( thePlayer ) 
    local random = math.random( #randomSpawnTable ) 
    spawnPlayer( 
        thePlayer, 
        randomSpawnTable[random][1], 
        randomSpawnTable[random][2], 
        randomSpawnTable[random][3], 
        randomSpawnTable[random][4] 
    ) 
end 
  
function onPlayerJoin( ) 
    fadeCamera( source, true ) 
    setCameraTarget( source, source ) 
    randomSpawn( source ) 
end 
addEventHandler( "onPlayerJoin", root, onPlayerJoin ) 
  
function onPlayerDeath( ) 
    fadeCamera ( source, false, 1.0, 255, 0, 0 ) 
    setTimer( randomSpawn, 3000, 1, source ) 
    setTimer( fadeCamera, 2500, 1, source, true, 0.5 ) 
end 
addEventHandler( "onPlayerWasted", root, onPlayerDeath ) 

Not working. :/

Link to comment

It working, i test it now. :/

Also i forgot say problem.

You problem in 28 line

setTimer( randomSpawn, 3000, 1, source ) 

You forgot call table.

setTimer( randomSpawn, 3000, 1, source,randomSpawnTable ) 

Correct.

Full correct code

local randomSpawnTable =  
{ 
    { -2818.3391, 1134.4768, 26.1129, 179.2400 }, 
    { 2021.3114, 1344.1099, 10.8203, 269.5800 }, 
    { 2221.3726, 1838.4792, 10.8203, 90.3700 } 
} 
  
function randomSpawn( thePlayer, randomSpawnTable ) 
    local random = math.random( 1, #randomSpawnTable ) 
    spawnPlayer(  
        thePlayer, 
        randomSpawnTable[random][1], 
        randomSpawnTable[random][2], 
        randomSpawnTable[random][3], 
        randomSpawnTable[random][4] 
    ) 
end 
  
function onPlayerJoin( ) 
    fadeCamera( source, true ) 
    setCameraTarget( source, source ) 
    randomSpawn( source, randomSpawnTable ) 
end 
addEventHandler( "onPlayerJoin",root, onPlayerJoin ) 
  
function onPlayerDeath( ) 
    fadeCamera ( source, false, 1.0, 255, 0, 0 ) 
    setTimer( randomSpawn, 3000, 1, source,randomSpawnTable ) 
    setTimer( fadeCamera, 2500, 1, source, true, 0.5 ) 
end 
addEventHandler( "onPlayerWasted", root, onPlayerDeath ) 

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