CodX Posted February 21, 2018 Share Posted February 21, 2018 Hello ! function savePlayerData(thePlayer) local account = getPlayerAccount(thePlayer); if account then for _,v in ipairs(playerDataTable) do setAccountData(account, v[1], getElementData(thePlayer, v[1])); end local x,y,z = getElementPosition(thePlayer); setAccountData(account, "last_x", x); setAccountData(account, "last_y", y); setAccountData(account, "last_z", z); end end I have some problems with this script. He always get player name as "nil" and i don't know why can't. Warning Text from debugger: Bad Argument @'getPlayerAccount' [Expected element at argument 1, got nil] Link to comment
NeXuS™ Posted February 21, 2018 Share Posted February 21, 2018 How do you call the savePlayerData function? Link to comment
CodX Posted February 21, 2018 Author Share Posted February 21, 2018 1 minute ago, NeXuS™ said: How do you call the savePlayerData function? setTimer(function() savePlayerData(source) end, 1000, 0); Link to comment
NeXuS™ Posted February 21, 2018 Share Posted February 21, 2018 addEventHandler("onPlayerQuit", root, function() savePlayerData(source) end) Try it with this. 1 Link to comment
CodX Posted February 21, 2018 Author Share Posted February 21, 2018 Just now, NeXuS™ said: addEventHandler("onPlayerQuit", root, function() savePlayerData(source) end) Try it with this. I've tried this but sometimes don't save playerData when the player has disconnected. Link to comment
NeXuS™ Posted February 21, 2018 Share Posted February 21, 2018 There is no way it isn't saved with this method. It is called every single time a player is disconnected. 1 Link to comment
CodX Posted February 21, 2018 Author Share Posted February 21, 2018 Just now, NeXuS™ said: There is no way it isn't saved with this method. It is called every single time a player is disconnected. Sometiems didn't save my data, that is the reason why i've used a timer. Link to comment
NeXuS™ Posted February 21, 2018 Share Posted February 21, 2018 (edited) If you want to create an unoptimized script, here ya go. setTimer(function() for i, k in pairs(getElementsByType("player")) do savePlayerData(k) end end, 1000, 0) Edited February 21, 2018 by NeXuS™ 1 Link to comment
CodX Posted February 21, 2018 Author Share Posted February 21, 2018 3 minutes ago, NeXuS™ said: If you want to create an unoptimized script, here ya go. setTimer(function() for i, k in pairs(getElementsByType("player")) do savePlayerData(k) end end, 1000, 0) Work ! Thank you for help ! Link to comment
MIKI785 Posted February 21, 2018 Share Posted February 21, 2018 8 hours ago, NeXuS™ said: There is no way it isn't saved with this method. It is called every single time a player is disconnected. In fact, there are at least two ways. One way is that the server crashes; nothing you can do there.. or that the resource gets stopped and a player leaves within the time the resource is not running; this can be solved using onResourceStop. Link to comment
NeXuS™ Posted February 21, 2018 Share Posted February 21, 2018 I was explaining in a situation where everything was fine, and he disconnected. 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