Saving player stats on restart
#1

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?
Reply
#2

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];

Reply
#3

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.
Reply
#4

then run a timer?
Reply
#5

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.
Reply
#6

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);
Reply
#7

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 .
Reply
#8

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.
Reply
#9

Not only its fine, it's one of it's intended features.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)