liamknight24 Posted January 25, 2010 Posted January 25, 2010 i want my server to be like when a player has logged in he will spawn at a postion and then when he reconnects he wont spawn at the first position he will spawn where he left off, here is what i have so far:: function spawn(player) local playeraccount = getPlayerAccount ( thePlayer ) playerpos = getAccountData ( playeraccount, "position", playerpos ) if ( playerpos ) then spawnPlayer ( player, playerpos ) fadeCamera(player, true) setCameraTarget(player, player) else spawnPlayer ( player, 2315.0593261719, -2968.7006835938, 1816.2529296875, 90, math.random(1,2) ) fadeCamera(player, true) setCameraTarget(player, player) end end function onPlayerQuit ( ) local playeraccount = getPlayerAccount ( thePlayer ) if ( playeraccount ) then local playerpos = getElementPosition ( thePlayer ) setAccountData ( playeraccount, "position", playerpos ) end end is there any other way of doing this?? thanks for any help.
liamknight24 Posted January 25, 2010 Author Posted January 25, 2010 i want my server to be like when a player has logged in he will spawn at a postion and then when he reconnects he wont spawn at the first position he will spawn where he left off, here is what i have so far:: function spawn(player) local playeraccount = getPlayerAccount ( thePlayer ) playerpos = getAccountData ( playeraccount, "position", playerpos ) if ( playerpos ) then spawnPlayer ( player, playerpos ) fadeCamera(player, true) setCameraTarget(player, player) else spawnPlayer ( player, 2315.0593261719, -2968.7006835938, 1816.2529296875, 90, math.random(1,2) ) fadeCamera(player, true) setCameraTarget(player, player) end end function onPlayerQuit ( ) local playeraccount = getPlayerAccount ( thePlayer ) if ( playeraccount ) then local playerpos = getElementPosition ( thePlayer ) setAccountData ( playeraccount, "position", playerpos ) end end is there any other way of doing this?? thanks for any help.
Gamesnert Posted January 25, 2010 Posted January 25, 2010 function spawn(player) local playeraccount = getPlayerAccount ( player ) local playerposX = getAccountData ( playeraccount, "positionX") local playerposY = getAccountData ( playeraccount, "positionY") local playerposZ = getAccountData ( playeraccount, "positionZ") if ( playerposX ) then spawnPlayer ( player, playerposX, playerposY, playerposZ ) fadeCamera(player, true) setCameraTarget(player, player) else spawnPlayer ( player, 2315.0593261719, -2968.7006835938, 1816.2529296875, 90, math.random(1,2) ) fadeCamera(player, true) setCameraTarget(player, player) end end function onPlayerQuit ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) then local playerposX,playerposY,playerposZ = getElementPosition ( source ) setAccountData ( playeraccount, "positionX", playerposX ) setAccountData ( playeraccount, "positionY", playerposY ) setAccountData ( playeraccount, "positionZ", playerposZ ) end end I just did a quick sweep and fixed some minor stuff. Important stuff to note: - getElementPosition returns X, Y and Z. Not just 1 value - In the "spawn" function there is no such variable as "thePlayer" - In the "onPlayerQuit" function the player who quit is marked by "source", not "thePlayer" - I don't see any event handlers
Gamesnert Posted January 25, 2010 Posted January 25, 2010 function spawn(player) local playeraccount = getPlayerAccount ( player ) local playerposX = getAccountData ( playeraccount, "positionX") local playerposY = getAccountData ( playeraccount, "positionY") local playerposZ = getAccountData ( playeraccount, "positionZ") if ( playerposX ) then spawnPlayer ( player, playerposX, playerposY, playerposZ ) fadeCamera(player, true) setCameraTarget(player, player) else spawnPlayer ( player, 2315.0593261719, -2968.7006835938, 1816.2529296875, 90, math.random(1,2) ) fadeCamera(player, true) setCameraTarget(player, player) end end function onPlayerQuit ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) then local playerposX,playerposY,playerposZ = getElementPosition ( source ) setAccountData ( playeraccount, "positionX", playerposX ) setAccountData ( playeraccount, "positionY", playerposY ) setAccountData ( playeraccount, "positionZ", playerposZ ) end end I just did a quick sweep and fixed some minor stuff. Important stuff to note: - getElementPosition returns X, Y and Z. Not just 1 value - In the "spawn" function there is no such variable as "thePlayer" - In the "onPlayerQuit" function the player who quit is marked by "source", not "thePlayer" - I don't see any event handlers
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