SA-MP Forums Archive
Issue with MySQL saving - 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)
+--- Thread: Issue with MySQL saving (/showthread.php?tid=657227)



Issue with MySQL saving - Jing_Chan - 03.08.2018

Hi all.

Under OnPlayerDisconnect I call the function
pawn Код:
SavePlayer(playerid);
This is the SavePlayer function.

pawn Код:
SavePlayer(playerid)
{
    new DB_Query[256];

    mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `PLAYERS` SET `SCORE` = %d, `KILLS` = %d, `CASH` = %d, `DEATHS` = %d, `ADMIN` = %d, `SKIN` = %d, `TOKENS` = %d, `DONATOR` = %d, `NAMECHANGES` = %d, `HEADSHOTS`= %d WHERE `ID` = %d LIMIT 1",
    pInfo[playerid][Score], pInfo[playerid][Kills], pInfo[playerid][Cash], pInfo[playerid][Deaths], pInfo[playerid][Admin], pInfo[playerid][Skin], pInfo[playerid][Tokens], pInfo[playerid][Donator], pInfo[playerid][Namechanges], pInfo[playerid][Headshots], pInfo[playerid][ID]);
    mysql_tquery(Database, DB_Query);
    return 1;

}
Often it saves, but randomly on restarts and at other times it will wipe my statistics. Any ideas?


Re: Issue with MySQL saving - GRiMMREAPER - 03.08.2018

Loop through every player and save their statistics under OnGameModeExit. You will inevitably lose data if you don't save the players' statistics periodically.


Re: Issue with MySQL saving - Jing_Chan - 03.08.2018

Quote:
Originally Posted by GRiMMREAPER
Посмотреть сообщение
Loop through every player and save their statistics under OnGameModeExit. You will inevitably lose data if you don't save the players' statistics periodically.
I've added SavePlayer(i); beneath OnGameModeExit, hopefully that'll work.


Re: Issue with MySQL saving - Banditul18 - 03.08.2018

Its better to save player stats when they change. I guess admin or other stats doesnt update so often so why dont you save them when they change? Far better then save all of them in a query