Jump to content

OOP problem


sc00r3

Recommended Posts

Hello guys!
I have the problem with oop in MTA:SA.
I want to save my data to account so i'm using it like that

function playerAccountSetData(player, dataname, amount)
  player:getAccount():setData(dataname, amount)
end

Okey, my data is changed, but when i logout and log in again, my data in account is null...
Is this a oop problem? Or i'm making something bad?
This is not even editing my db file...


Thanks for help! 
Greetings, sc00r3!

 

//Edit1 
 

I'm checking data after adding it by 

  outputChatBox(player:getAccount():getData(dataname))

and it show the data, what i saved.

Edited by sc00r3
Link to comment

I don't think onPlayerLogout gets called when onPlayerQuit happens.
If you use onPlayerLogout and use the function which is wrote above, it'll always be the "guest" user, because the logout has been already done.

function playerAccountSetData(account, dataname, amount)
	account:setData(dataname, amount)
end

addEventHandler("onPlayerLogout", getRootElement(), function(oldAcc)
	playerAccountSetData(oldAcc, "money", getPlayerMoney(source))
end)

Try this.

  • Thanks 1
Link to comment
9 minutes ago, NeXuS™ said:

I don't think onPlayerLogout gets called when onPlayerQuit happens.
If you use onPlayerLogout and use the function which is wrote above, it'll always be the "guest" user, because the logout has been already done.


function playerAccountSetData(account, dataname, amount)
	account:setData(dataname, amount)
end

addEventHandler("onPlayerLogout", getRootElement(), function(oldAcc)
	playerAccountSetData(oldAcc, "money", getPlayerMoney(source))
end)

Try this.

I fixed it by myself, really thanks for help you are awesome! 

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