Jusonex Posted May 3, 2011 Share Posted May 3, 2011 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
NeXTreme Posted May 4, 2011 Share Posted May 4, 2011 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
Jusonex Posted May 4, 2011 Author Share Posted May 4, 2011 Oh...yeah. spawnPunkte[0][1] was nil. Thanks Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now