Saving stats on server turns off (exit command) -
Riwerry - 31.12.2013
Guys how I can save stats when server turns off by exit rcon command? Using Y_INI
(btw, tried it in OnPlayerDisconnect not work)
Re: Saving stats on server turns off (exit command) -
StuartD - 01.01.2014
If you make a /exit command or something you can call your saving system to save all the players then use SendRconCommand("exit"); to then exit the gamemode
Re: Saving stats on server turns off (exit command) -
Lordzy - 01.01.2014
Quote:
Originally Posted by StuartD
If you make a /exit command or something you can call your saving system to save all the players then use SendRconCommand("exit"); to then exit the gamemode 
|
That may not work in case if there's many players. "exit" command on RCON is too fast for the INI functions to execute.
While a player disconnects, store their data on temporary variables and then store it to INI files using those variables. That's what I've done before when I used INI file systems.
EDIT : In case if there's too much data, use a timer to execute the function under OnPlayerDisconnect. Ensure that you get the player's name and store it on a temporary variable to execute the file.
Re: Saving stats on server turns off (exit command) -
Riwerry - 01.01.2014
hmm okay, and what about if server crashes? THen will be stats saved? or no?
Re: Saving stats on server turns off (exit command) -
Lordzy - 01.01.2014
For that, use a timer which gets called at every specified interval. So that it would save the player's data every time the timer gets called.
Re: Saving stats on server turns off (exit command) -
Riwerry - 01.01.2014
Yeah, thanks dude I need to put that timer to OnGameModeInit, right?
And wont it cause much cpu use? When I use that timer?
Re: Saving stats on server turns off (exit command) -
Lordzy - 01.01.2014
Quote:
Originally Posted by Riwerry
Yeah, thanks dude I need to put that timer to OnGameModeInit, right?
And wont it cause much cpu use? When I use that timer?
|
When the gamemode starts, create a timer which gets repeated every 2 minutes or 3. And on the timer, loop through all registered players and save their data using INI functions.
About CPU : It will cause in case if you reduce the repeating intervals. An example of it:
pawn Код:
public OnGameModeInit()
{
SetTimer("SaveAccs", 1000*120, true); //2 minute, repeating timer. I preferred 4-5 mins.
return 1;
}
forward SaveAccs();
public SaveAccs()
{
for(new i; i< GetMaxPlayers(); i++)
{
if(!IsPlayerConnected(i)) continue;
if(!IsPlayerLoggedIn(i)) continue;
SavePlayerStats(i); //The saving function.
}
return 1;
}
Re: Saving stats on server turns off (exit command) -
DaRk_RaiN - 01.01.2014
There is no way (afaik) to save the stats when the server suddenly goes off, however there are ways around it, use a timer that saves the stats every 15 minutes maybe? atleast the damage will be less.
--If you're the one that wants to restart the server, make a command that saves the stats and executes a 7000 ms interval timer, within there is the Rcon exit command.
Starting code:
pawn Код:
CMD:restart(playerid, params[])
{
//code (saving the stats)
SetTimer("RestartTimer",7000,0);
return 1;
}
forward RestartTimer();
public RestartTimer()
{
SendRconCommand("exit");
}