Jump to content

Money and health are not saved when you log out of your account


Recommended Posts

function save ()
  if not (isGuestAccount (getPlayerAccount (source))) then
    account = getPlayerAccount (source)
    if (account) then

      setAccountData (account, "money", tostring (getPlayerMoney (source)))
      setAccountData (account, "health", tostring (getElementHealth (source)))
    end
  end
end
addEventHandler ("onPlayerLogout", getRootElement(), save)

 

Edited by Egor_Varaksa
Link to post

Because onPlayerLogout is called after the logout was successful, at that point the user is in the "guest" account.

Check the wiki page for more info, you need to use the first argument of the event which is the previous account the user was in before logging out.

Link to post
function save (account)
    setAccountData (account, "money", tostring (getPlayerMoney (source)))
    setAccountData (account, "health", tostring (getElementHealth (source)))
end
addEventHandler ("onPlayerLogout", getRootElement(), save)

Parameters

account thePreviousAccount, account theCurrentAccount
  • thePreviousAccount: the account the client was logged in as.
  • theCurrentAccount: the account the client is a part of now (usually a guest account).
Link to post

I want the player to be able to change their account without leaving the server and all their data will be saved.

On some servers, when you enter the /logout command, the login panel appears, and you can log in to another account, and the data of the account you logged out of is saved

Edited by Egor_Varaksa
Link to post
3 minutes ago, Egor_Varaksa said:

I want the player to be able to change their account without leaving the server, and all their data will be saved.

Well you already got an answer from @WASSIm..

Link to post

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