User stats saveing on server shutdown
#1

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

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
Reply
#3

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

Yes it is. It's called on OnGameModeExit.
Reply
#5

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

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

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

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

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

Bump (12 hours +)
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)