Jump to content

[HELP] Position saving


HUNGRY:3

Recommended Posts

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
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
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
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...