SA-MP Forums Archive
User stats saveing on server shutdown - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: User stats saveing on server shutdown (/showthread.php?tid=260380)



User stats saveing on server shutdown - sim_sima - 08.06.2011

Hello everyone. I know i have asked this question before, but didnt get a solution.
Now i will ask again to clear things up.
My problem is, I have a gamemode which saves user stats when player disconnect, but, it doesnt get saved when the server shuts down (like closing the server window or crashing). I have searched ******, and found this https://sampforum.blast.hk/showthread.php?tid=90943
Its about a function called OnPlayerUpdateEx, that i have seen in other gamemodes several times (Ex.: Ravens Roleplay). But i dont know how to do it.

Hope someone here can help me. Thanks.





Msg to SA-MP admins: Yes, i know i posted this before, please don't delete it, delete the old one in stead. Thanks


Re: User stats saveing on server shutdown - Jeffry - 08.06.2011

Hello sim_sima,

I suggest you to take a timer which saves the stats by a given amount of time. I am doing it this way too.

Add at TOP:
pawn Код:
#define SAVE_TIME 30  //Will save the stats every 30 seconds.
new SaveTimer[MAX_PLAYERS] = {-1,...};
Add at OnPlayerConnect:
pawn Код:
SaveTimer[playerid] = SetTimerEx("SaveTheUser", SAVE_TIME*1000, 1, "d", playerid);
Add at OnPlayerDisconnect:
pawn Код:
if(SaveTimer[playerid] != -1) KillTimer(SaveTimer[playerid]);
SaveTimer[playerid] = -1;
At OnGameModeExit:
pawn Код:
for(new i=0; i<MAX_PLAYERS; i++)
{
    if(SaveTimer[i] != -1)
    {
        KillTimer(SaveTimer[i]);
        SaveTimer[i] = -1;
    }
}
Add at bottom:
pawn Код:
forward SaveTheUser(playerid);
public SaveTheUser(playerid)
{
    SavePlayer(playerid);
    //Just change the SavePlayer(playerid) to your stats-saving-function.
    return 1;
}
If you have any questions, feel free to ask.

Jeffry


Re: User stats saveing on server shutdown - sim_sima - 08.06.2011

Quote:
Originally Posted by Jeffry
Посмотреть сообщение
Hello sim_sima,

I suggest you to take a timer which saves the stats by a given amount of time. I am doing it this way too.

Add at TOP:
pawn Код:
#define SAVE_TIME 30  //Will save the stats every 30 seconds.
new SaveTimer[MAX_PLAYERS] = {-1,...};
Add at OnPlayerConnect:
pawn Код:
SaveTimer[playerid] = SetTimerEx("SaveTheUser", SAVE_TIME*1000, 1, "d", playerid);
Add at OnPlayerDisconnect:
pawn Код:
if(SaveTimer[playerid] != -1) KillTimer(SaveTimer[playerid]);
SaveTimer[playerid] = -1;
At OnGameModeExit:
pawn Код:
for(new i=0; i<MAX_PLAYERS; i++)
{
    if(SaveTimer[i] != -1)
    {
        KillTimer(SaveTimer[i]);
        SaveTimer[i] = -1;
    }
}
Add at bottom:
pawn Код:
forward SaveTheUser(playerid);
public SaveTheUser(playerid)
{
    SavePlayer(playerid);
    //Just change the SavePlayer(playerid) to your stats-saving-function.
    return 1;
}
If you have any questions, feel free to ask.

Jeffry
Thank you. But what if the server crashes or shuts down?
The OnGameModeExit isn't called when server shut down or crash.


Re: User stats saveing on server shutdown - Steven82 - 08.06.2011

Yes it is. It's called on OnGameModeExit.


Re: User stats saveing on server shutdown - Jack Shred - 08.06.2011

Hence the timer, it should work as far as I know.


Re: User stats saveing on server shutdown - Jeffry - 08.06.2011

Quote:
Originally Posted by Steven82
Посмотреть сообщение
Yes it is. It's called on OnGameModeExit.
No. Crash = server off.


@Thats why the timer saves the stats every 30 seconds. There won't get much stats lost in case that the server crashes.
But you cannot detect when the server crashes, because at the time it crashes, it is already off.


Re: User stats saveing on server shutdown - Steven82 - 08.06.2011

You better hope your gamemode is optimized and not running a lot of timers. I wouldn't save them every 30 seconds. But thats just me, i would rather save them every 2-5 minutes.


Re: User stats saveing on server shutdown - Jeffry - 08.06.2011

Quote:
Originally Posted by Steven82
Посмотреть сообщение
You better hope your gamemode is optimized and not running a lot of timers. I wouldn't save them every 30 seconds. But thats just me, i would rather save them every 2-5 minutes.
It was just an example time. He can change it for sure. ^^
Just change the SAVE_TIME 30 to SAVE_TIME 300 (= 5 min)


Re: User stats saveing on server shutdown - sim_sima - 08.06.2011

But 2-5 minutes is way too much, because its an RPG server, and the last thing i want is players losing data.
But is there anyone that knows anything about that OnPlayerUpdateEx method?


Re: User stats saveing on server shutdown - sim_sima - 09.06.2011

Bump (12 hours +)