Posts: 1,679
Threads: 232
Joined: Nov 2009
Reputation:
0
I wonder if i could use a saving function for onplayerupdate for mysql variables i want to save
for example if player stats are saved through onplayerupdate will this cause problem to server like lagging or something like that?
Posts: 807
Threads: 10
Joined: Jan 2013
Reputation:
0
Why would you need to?
Just save the data on score/money/data change. Plus OnPlayerDisconnect. As Vince mentioned in a thread, people seem to want to save everything in one query. Don't do that either. Save the major stuff. IE: Money, score, skin etc and leave stuff out like, house id, admin level and stuff.
Posts: 3,133
Threads: 71
Joined: Dec 2013
Reputation:
0
OnPlayerUpdate is called EVERY TIME the client updates the server with new information. I remember ****** showing a graph / diagram, or something of what happens when the callback is called. Its a long list. Just save when the players stats update. Make sure how-ever you save though, that it doesn't cause the server to lag, and or hang while the data is being saved, that'd make gameplay an awful experience for players.
Simply put: No: it's a horrible idea! It will cause many issues, and is simply put, illogical.
Posts: 1,733
Threads: 20
Joined: Nov 2010
Reputation:
0
If you're certain every query works, you can skip saving everything again during OnPlayerDisconnect.
Whenever a variable changes, like money, save it in the database with a small query, preferably inside a small function that updates the money on the server, as well as sending a small query to change the money value in the database (like I showed previously using Player_Reward in the other thread).
If you have such a system for everything, you don't need another huge query to save everything when a player logs out, as all data has been saved already when he was playing the game.
Because after the last save, data didn't change anymore, so no reason to save it again.
Whenever I add a new query to my script, I run the server, open Navicat and display the data in my tables.
When I run the game and I edit the value of that new variable (say jailtime), I put myself in jail and check the database, when the game is still running.
If it updates everytime, it works and you can skip saving that when you logout as it has been updated properly.
Posts: 214
Threads: 18
Joined: Oct 2014
Reputation:
0
Yes, It will lag your server as this OnPlayerUpdate is called very frequently per second per player. You should use OnPlayerDisconnect for saving player stats.
Posts: 248
Threads: 13
Joined: Jul 2014
Reputation:
0
To keep updating players stats time to time, I would suggest you to set a repeated timer of 5-7 minutes and do not use OnPlayerUpdate for updating stats it will crash your server or create too much of lag because INIs are not that fast.
dini: 63810 -over 1 minute
yini: 1564 - 1 second
Update is called several times within 1 second, forcing the INI system to write will cause server crash or data loss.