HUNGRY:3 Posted August 7, 2015 Share Posted August 7, 2015 hello i'm trying to save player position but it doesn't work code: server function onPlayerQuit ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then local x,y,z = getElementPosition( source ) setAccountData ( playeraccount, "pos", x,y,z ) end end function onPlayerLogin (_, playeraccount ) if ( playeraccount ) then local old = getAccountData ( playeraccount, "pos" ) if ( old ) then setElementPosition ( source, x,y,z ) end end end addEvent("savePos",true) addEventHandler("savePos",root,onPlayerLogin) addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) client function test() if source == GUImain.button[1] then guiSetVisible(GUImain.staticimage[1],false) setElementData(lp,"onmain",false) showCursor( false ) setCameraTarget(lp,lp) triggerServerEvent("savePos",localPlayer) end end addEventHandler("onClientGUIClick",root,test) Link to comment
GTX Posted August 7, 2015 Share Posted August 7, 2015 function onPlayerQuit ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then local x,y,z = getElementPosition( source ) setAccountData ( playeraccount, "pos", {x,y,z} ) end end function onPlayerLogin (_, playeraccount ) if ( playeraccount ) then local x, y, z = unpack(getAccountData ( playeraccount, "pos" )) --if ( old ) then setElementPosition ( source, x,y,z ) --end end end addEvent("savePos",true) addEventHandler("savePos",root,onPlayerLogin) addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) Link to comment
HUNGRY:3 Posted August 7, 2015 Author Share Posted August 7, 2015 not working nothing in debug Link to comment
GTX Posted August 7, 2015 Share Posted August 7, 2015 function onPlayerQuit ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then local x,y,z = getElementPosition( source ) setAccountData ( playeraccount, "pos", {x,y,z} ) end end function onPlayerLogin (_, playeraccount ) if not playeraccount then playeraccount = getPlayerAccount(source) end if ( playeraccount ) then local x, y, z = unpack(getAccountData ( playeraccount, "pos" )) --if ( old ) then setElementPosition ( source, x,y,z ) --end end end addEvent("savePos",true) addEventHandler("savePos",root,onPlayerLogin) addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) Link to comment
HUNGRY:3 Posted August 7, 2015 Author Share Posted August 7, 2015 not working ERROR: [RPG]\RPG\server.lua:95: bad argument #1 to 'unpack' (table expected, got number) Link to comment
GTX Posted August 7, 2015 Share Posted August 7, 2015 It should work. I never set any number in the script I gave you. Link to comment
HUNGRY:3 Posted August 7, 2015 Author Share Posted August 7, 2015 it doesn't work it doesn't warp me to the old position when i click on a button Link to comment
Dimos7 Posted August 7, 2015 Share Posted August 7, 2015 function onQuit(quitType, reason, resposibleElement) if not isGuestAccount(getPlayerAccount(source)) then local account = getPlayerAccount(source) if account then local x, y, z = getElementPosition(source) setAccountData(account, "funmodev2-x", x) setAccountData(account, "funmodev2-y", y) setAccountData(account, "funmodev2-z", z) end end end addEventHandler("onPlayerQuit", getRootElement(), onQuit) function onLogin(thePreviousAccount, theCurrentAccount, autoLogin) if not isGuestAccount(getPlayerAccount(source)) then local playerX = getAccountData(theCurrentAccount, "funmodev2-x") local playerY = getAccountData(theCurrentAccount, "funmodev2-y") local playerZ = getAccountData(theCurrentAccount, "funmodev2-z") setElementPosition(source, playerX, playerY, playerZ) end end addEventHandler("onPlayerLogin", getRootElement(), onLogin) Link to comment
HUNGRY:3 Posted August 7, 2015 Author Share Posted August 7, 2015 nope, doesn't work EDIT: WORKED THANK YOU! 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