Saving player stats on restart -
Eyce - 19.05.2016
I was wondering if a foreach statement would efficiently work on saving player stats by ID using threaded queries. Like for example, there are 20 players online and once an admin uses rcon command to restart, it'll save each player by ID. Something like...
Player ID 1 saved then goes to Player ID 2 and saves until it reaches the last player ID online. And after all players are saved, it saves the server stats or dynamics, like houses, businesses, etc., it then triggers the "gmx" after everything is saved.
pawn Код:
foreach(Player, i)
{
if(IsPlayerConnected(i)) OnPlayerSave(i);
}
Would the code above do the trick or does it save all the players online at the same time?
Re: Saving player stats on restart -
itsCody - 19.05.2016
i personally set a var to true on login
then do something like this on disconnect
PHP код:
if(var[playerid])
{
save_shit(playerid);
var[playerid] = !var[playerid];
}
Re: Saving player stats on restart -
Eyce - 19.05.2016
Quote:
Originally Posted by itsCody
i personally set a var to true on login
then do something like this on disconnect
PHP код:
if(var[playerid])
{
save_shit(playerid);
var[playerid] = !var[playerid];
}
|
I have a function that saves the player's stats when they disconnect and it works fine. What I'm asking about is whenever restarting the server. What I'd like to happen is to save all server stats/dynamics first, then start saving player stats - starting from ID 0 (whichever is the lowest player ID online) until it reaches the last player ID online then restart the server.
Re: Saving player stats on restart -
itsCody - 19.05.2016
then run a timer?
Re: Saving player stats on restart -
BornHuman - 19.05.2016
I use Player[playerid][Authenticated] as my login verifier. Then when the gamemode shuts down I save players data with a foreach loop. The best way I've found to do it is to use a command to shutdown the gamemode such as /gmx. Then have the script run a 30000 timer and during that time save all data just to make sure it saves. When the timer is over, have it run the rcon cmd to shut down the server.
But yes, foreach would be the most efficient way to do it.
Re: Saving player stats on restart -
Eyce - 19.05.2016
Quote:
Originally Posted by BornHuman
I use Player[playerid][Authenticated] as my login verifier. Then when the gamemode shuts down I save players data with a foreach loop. The best way I've found to do it is to use a command to shutdown the gamemode such as /gmx. Then have the script run a 30000 timer and during that time save all data just to make sure it saves. When the timer is over, have it run the rcon cmd to shut down the server.
But yes, foreach would be the most efficient way to do it.
|
That's I have right now. Just out of the topic question though, on threaded queries. Is it safe to do more than 1 query before going to the next threaded query?
Such as:
pawn Код:
format(Query...);
mysql_query(Query);
format(Query...);
mysql_query(Query);
format(Query...);
mysql_query(Query);
Re: Saving player stats on restart -
MBilal - 19.05.2016
Try to save things when player bought anything or under OnPlayerDeath or Like for tdm server . save player kills or death streak under OnPlayerDeath . if player bought any house or any car save it when at that moment when he bought it because when player crash some time stats not save Under OnPlayerDisconnect .
Re: Saving player stats on restart -
BornHuman - 19.05.2016
Quote:
Originally Posted by Eyce
That's I have right now. Just out of the topic question though, on threaded queries. Is it safe to do more than 1 query before going to the next threaded query?
Such as:
pawn Код:
format(Query...); mysql_query(Query);
format(Query...); mysql_query(Query);
format(Query...); mysql_query(Query);
|
Yeah, that should be fine.
Re: Saving player stats on restart -
PrO.GameR - 19.05.2016
Not only its fine, it's one of it's intended features.