Xierra Posted April 19, 2011 Posted April 19, 2011 I have been trying to make something, to respawn players on hospitals when that player is dead. I'm using part of varez's code which was made in 2010. I wanted to post this once, so I tried to copy, and then tweak and improve it a little. The script(Server-side): hospitalsTable = { { 1177.7994384766, -1323.0667724609, 14.088536262512 }, { -2656.2421875, 635.99420166016, 14.453125 }, { 1607.1225585938, 1817.8732910156, 10.8203125 }, } function findNearestHostpital(thePlayer) local nearest = nil local min = 999999 for key,val in pairs(hospitalsTable) do local xx,yy,zz=getElementPosition(thePlayer) local x1=val[1] local y1=val[2] local z1=val[3] local dist = getDistanceBetweenPoints2D(xx,yy,x1,y1) if distthen nearest = val min = dist end end return nearest[1],nearest[2],nearest[3] end function spawn(player) local xx,yy,zz = findNearestHostpital(source) spawnPlayer( player, xx,yy,zz) fadeCamera(player,true,3.0) end addEventHandler("onPlayerWasted", root, function() fadeCamera(source,false,6.0,0,0,0) setTimer(spawn, 8000, 1, source) end ) Errors that came out: hospital-respawns\server.lua:11: Bad Argument @ 'getElementPosition' hospital-respawns\server.lua:15: Bad Argument @ 'getDistanceBetweenPoints2D hospital-respawns\server.lua:16: Attempt to compare bollean with number There's a problem though, I can't seem to find a way to fix this problem as I was not so experienced in scripting yet (As it was my first try at server-side script). But I did successfully made the fade in and out part. Now, how can I fix those? Any help is appreciated.
Castillo Posted April 19, 2011 Posted April 19, 2011 hospitalsTable = { { 1177.7994384766, -1323.0667724609, 14.088536262512 }, { -2656.2421875, 635.99420166016, 14.453125 }, { 1607.1225585938, 1817.8732910156, 10.8203125 }, } function findNearestHostpital(thePlayer) local nearest = nil local min = 999999 for key,val in pairs(hospitalsTable) do local xx,yy,zz=getElementPosition(thePlayer) local x1=val[1] local y1=val[2] local z1=val[3] local dist = getDistanceBetweenPoints2D(xx,yy,x1,y1) if distthen nearest = val min = dist end end return nearest[1],nearest[2],nearest[3] end function spawn(player) local xx,yy,zz = findNearestHostpital(player) spawnPlayer( player, xx,yy,zz) fadeCamera(player,true,3.0) end addEventHandler("onPlayerWasted", root, function() fadeCamera(source,false,6.0,0,0,0) setTimer(spawn, 8000, 1, source) end )
Xierra Posted April 22, 2011 Author Posted April 22, 2011 Wow! It worked! Thanks SolidSnake14. What was changed here? I can't see lots of differences on the script.
MTA Team qaisjp Posted April 23, 2011 MTA Team Posted April 23, 2011 I usually store the coordinates as strings and use for i,v in pairs(hospitalsTable) do x = gettok(v, 1, string.byte(",") y = gettok(v, 2, string.byte(",") z = gettok(v, 3, string.byte(",") outputChatBox(x..", "..y..", "..z) end but the code solidsnake provided is better.
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