Xierra Posted February 21, 2010 Share Posted February 21, 2010 (edited) Hello guys. I wanted to make more than one spawn areas at once. I have edited the broph.lua like this: addEventHandler("onResourceStart", resourceRoot, function() for i,player in ipairs(getElementsByType("player")) do spawn(player) end end ) function spawn(player) local spawns = { } spawns[1].x = -2030.1610107422 spawns[1].y = 172.25221252441 spawns[1].z = 28.8359375 spawns[1].rot = 90.0 spawns[2].x = 423.2495 spawns[2].y = 453.2564 spawns[2].z = 564.6321 spawns[2].rot = 120.6928 local rnd = math.random( #spawns ) spawnPlayer( player, spawns[rnd].x, spawns[rnd].y, spawns[rnd].z, spawns[rnd].rot ) end addEventHandler("onPlayerJoin", root, function() spawn(source) end ) addEventHandler("onPlayerWasted", root, function() setTimer(spawn, 3000, 1, source) end ) But at the game it says (with debugscript 3) ERROR: MTA SA deathmatch/server/mods/resources/play/broph.lua:12: attempt to index field '?' (a nil value) aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa A little edit: To anyone who wanted the fixed version, just copy the lines! addEventHandler("onResourceStart", resourceRoot,. function() for i,player in ipairs(getElementsByType("player")) do spawn(player) end end ) function spawn(player) local spawns = { } spawns[1] = { } spawns[1].x = -2030.1610107422 spawns[1].y = 172.25221252441 spawns[1].z = 28.8359375 spawns[1].rot = 90.0 spawns[2] = { } spawns[2].x = 423.2495 spawns[2].y = 453.2564 spawns[2].z = 564.6321 spawns[2].rot = 120.6928 local rnd = math.random( #spawns ) spawnPlayer( player, spawns[rnd].x, spawns[rnd].y, spawns[rnd].z, spawns[rnd].rot ) end addEventHandler("onPlayerJoin", root, function() spawn(source) end ) addEventHandler("onPlayerWasted", root, function() setTimer(spawn, 3000, 1, source) end ) Edited February 22, 2010 by Guest Link to comment
DakiLLa Posted February 21, 2010 Share Posted February 21, 2010 You can create a multi-array table, which will contain x,y,z and rz values like this: local spawns = { --x, y, z, rotZ { -2030.1610107422, 172.25221252441, 28.8359375, 90.0 }, { 423.2495, 453.2564, 564.6321, 120.6928 } } function spawn( player ) local rnd = math.random( 1, #spawns ) spawnPlayer( player, spawns[rnd][1], spawns[rnd][2], spawns[rnd][3], spawns[rnd][4] ) end Link to comment
Xierra Posted February 21, 2010 Author Share Posted February 21, 2010 Thanks Dak! It's working now. Anyway why was my previous script doesn't work? Link to comment
Aibo Posted February 21, 2010 Share Posted February 21, 2010 error was in spawns[1].x, cause spawns is a table, while spawns[1] is not. you need to make a table before indexing it: local spawns = { } spawns[1] = { } spawns[1].x = -2030.1610107422 spawns[1].y = 172.25221252441 spawns[1].z = 28.8359375 spawns[1].rot = 90.0 spawns[2] = { } spawns[2].x = 423.2495 spawns[2].y = 453.2564 spawns[2].z = 564.6321 spawns[2].rot = 120.6928 etc. basically, the same thing DaK did *) Link to comment
Xierra Posted February 22, 2010 Author Share Posted February 22, 2010 Ah, I see, maybe I forgot to put the table at the spawn[1]. Now I understood about the tables, but I need to learn more about multi-array table. That's all. Thanks Dak & xbost! The topic is over! 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