Saving players' stats in OnGameModeExit.
#1

Hi there, thanks for putting some time aside to read this, and perhaps, help me solve my problem.

I'm trying to save the players' stats in OnGameModeExit public, in the usual way I do it, it doesn't seem to be working.

Here's the code:

pawn Код:
for(i = 0; i < MAX_PLAYERS; i++)
{
        printf("The player's name is %s", ppName[i]);

        mysql_format(mysql, query, sizeof(query), "UPDATE `players` SET `Hours` = '%d', `Minutes` = '%d' WHERE `Username` = '%e'",PlayerInfo[i][Hours], PlayerInfo[i][Minutes], ppName[i]);
        mysql_query(mysql, query);
}
The printf was used to debug. Anyway, I checked the server log, and it doesn't show the printf message there. So I suppose it doesn't have enough time to reach it?
I'm getting the player name in OnPlayerConnect, so it should have it stored until the server is closed, or w/e.

Note: I'm closing it by pressing the red x. Dunno if the callback gets called when it's closed like that, any answer would be appreciated.

Note2: As you can obviously see, I am using MySQL.
Reply
#2

You don't even need to loop just use OnPlayerDisconnect callback instead because it is also called when you restart server or exit.
Reply
#3

Quote:
Originally Posted by iZN
Посмотреть сообщение
You don't even need to loop just use OnPlayerDisconnect callback instead because it is also called when you restart server or exit.
Doesn't seem to work, it works when the players' /q, but not when I close the server.
(That's why I used OnGameModeExit in the first place.)
Reply
#4

Kick all the players OnGameModeExit.

Also, type exit in the console instead of pressing the red X.
Reply
#5

To successfully call OnGameModeExit, close the server by pressing 'Ctrl + C' - and not using

EDIT: Or of course, use what's stated below
Reply
#6

Quote:
Originally Posted by RajatPawar
Посмотреть сообщение
To successfully call OnGameModeExit, close the server by pressing 'Ctrl + C' - and not using
I see, that helps. I should've used ******.

However, what if it crashes? It never crashed, but it could happen when putting it on a host. Perhaps an attack, or w/e.
Reply
#7

Quote:
Originally Posted by Denying
Посмотреть сообщение
I see, that helps. I should've used ******.

However, what if it crashes? It never crashed, but it could happen when putting it on a host. Perhaps an attack, or w/e.
The only way to get around that is periodic saves, using a timer. Also, you can add a snippet to check for a suddenly large amount of connections and then immediately save everyone's statistic, just in case.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)