sc00r3 Posted August 4, 2017 Share Posted August 4, 2017 (edited) 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 August 4, 2017 by sc00r3 Link to comment
NeXuS™ Posted August 4, 2017 Share Posted August 4, 2017 Try debugging. function playerAccountSetData(player, dataname, amount) outputChatBox(player:getAccount():getName()) player:getAccount():setData(dataname, amount) end 1 Link to comment
sc00r3 Posted August 4, 2017 Author Share Posted August 4, 2017 Wow, yeah that was my fault, this is saying "guest". Do you know what the handler should i use to save my account before use script? Link to comment
NeXuS™ Posted August 4, 2017 Share Posted August 4, 2017 When are you trying to use this function? 2 Link to comment
sc00r3 Posted August 4, 2017 Author Share Posted August 4, 2017 I had 2 handlers onPlayerLogout and onPlayerQuit. Does onePlayerLogout work, while you are leaving server? Link to comment
NeXuS™ Posted August 5, 2017 Share Posted August 5, 2017 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. 1 Link to comment
sc00r3 Posted August 5, 2017 Author Share Posted August 5, 2017 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
MisterQuestions Posted August 6, 2017 Share Posted August 6, 2017 You can simply access it like variables. player.account, if player.account.guest then return, player.account:setData(...) Link to comment
NeXuS™ Posted August 7, 2017 Share Posted August 7, 2017 @MisterQuestions, this question is already answered... Link to comment
MisterQuestions Posted August 11, 2017 Share Posted August 11, 2017 On 7/8/2017 at 05:24, NeXuS™ said: @MisterQuestions, this question is already answered... Just added another option for him. 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