Jump to content

spawn/table problem


Recommended Posts

Hey guys,

I've got a problem. Sometimes the player didn't spawn, if he was killed.

That's my code:

  
local spawnPunkte = { 
    {2490.9541015625, -1665.9912109375, 14}, 
    {2665.7795410156, -1430.2344970703, 31}, 
    {2423.7976074219, -1239.5343017578, 25}, 
    {2154.5483398438, -1137.8609619141, 26}, 
    {2108.0493164063, -1781.1252441406, 14.5}, 
    {1685.4399414063, -2323.234375, 14}, 
    {1785.7797851563, -1926.1567382813, 14}, 
    {1972.0899658203, -1156.9620361328, 21.5} 
 } 
  
addEvent("onPlayerNewSpawn", true) 
function spawn(player, new) 
    if ( new == "new" ) then 
        spawnPlayer(player, 1834.4523925781, -1682.6423339844, 14, 90) 
        createBlips(player) 
    else 
        local spawn = math.random(0,#spawnPunkte) 
        repeat until spawnPlayer(player, spawnPunkte[spawn][1]+math.random(-2,2), spawnPunkte[spawn][2]+math.random(-2,2), spawnPunkte[spawn][3], 0, math.random(9,288)) 
    end 
    setCameraTarget(player, player) 
end 
addEventHandler("onPlayerNewSpawn", getRootElement(), spawn) 
  
addEventHandler("onPlayerWasted", getRootElement(), function(_, killer) 
    setTimer(spawn, 5000, 1, source) 
    givePlayerMoney(killer, 50) 
end) 

If the player didn't spawn, I get this error message: "attempt to index field '?' (a nil value)" (Line 20)

But why only sometimes?

Justus

Link to comment

Try this:

 local spawnPunkte = { 
    {2490.9541015625, -1665.9912109375, 14}, 
    {2665.7795410156, -1430.2344970703, 31}, 
    {2423.7976074219, -1239.5343017578, 25}, 
    {2154.5483398438, -1137.8609619141, 26}, 
    {2108.0493164063, -1781.1252441406, 14.5}, 
    {1685.4399414063, -2323.234375, 14}, 
    {1785.7797851563, -1926.1567382813, 14}, 
    {1972.0899658203, -1156.9620361328, 21.5} 
 } 
  
addEvent("onPlayerNewSpawn", true) 
function spawn(player, new) 
    if ( new == "new" ) then 
        spawnPlayer(player, 1834.4523925781, -1682.6423339844, 14, 90) 
        createBlips(player) 
    else 
        local spawn = math.random(1,#spawnPunkte) 
        repeat until spawnPlayer(player, spawnPunkte[spawn][1]+math.random(-2,2), spawnPunkte[spawn][2]+math.random(-2,2), spawnPunkte[spawn][3], 0, math.random(9,288)) 
    end 
    setCameraTarget(player, player) 
end 
addEventHandler("onPlayerNewSpawn", getRootElement(), spawn) 
  
addEventHandler("onPlayerWasted", getRootElement(), function(_, killer) 
    setTimer(spawn, 5000, 1, source) 
    givePlayerMoney(killer, 50) 
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...