SA-MP Forums Archive
Accounts don't save when close server. - 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: Accounts don't save when close server. (/showthread.php?tid=546580)



Accounts don't save when close server. - xHanks - 16.11.2014

When i close my server and if someone is connected, the accounts save wrong with all variables in 0..
How i can save the accounts nice when i close the server?

pawn Код:
public OnGameModeExit()
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
new solicitud[359], Float:PosicX, Float:PosicY, Float:PosicZ,name[MAX_PLAYER_NAME];
GetPlayerName(i, name, sizeof(name));
GetPlayerPos(i, PosicX, PosicY, PosicZ);
format(solicitud, sizeof(solicitud), "UPDATE `usuarios` SET `Nivel`=%d, `Tutorial`=%d, `Dinero`=%d,`PosX`=%f,`PosY`=%f,`PosZ`=%f WHERE `Usuario`= '%s'",\
pInfo[i][pNivel],pInfo[i][pTutorial],pInfo[i][pDinero],PosicX,PosicY,PosicZ, name);
mysql_query(mysql, solicitud);
}
}



Re : Accounts don't save when close server. - Dutheil - 16.11.2014

Save the player's infos, when he disconnects + don't use mysql_query in loop, rather use mysql_pquery


Respuesta: Accounts don't save when close server. - xHanks - 16.11.2014

I'm using this when disconnect too but if i close the server directly don't save any account.


Re: Accounts don't save when close server. - Sawalha - 16.11.2014

First, why [359] cells? that's much and a waste of memory. Use [128] , the query string is not that long as 359 cells.

And other, check your mysql_log.txt, and search for "error" , Post it here if exists.


Re: Accounts don't save when close server. - sammp - 16.11.2014

Nobody has noticed this is being called in OnGameModeExit()?

Call it on OnPlayerDisconnect!

Make the size of your query 128 cells big

Dont make a query like that, just call a global save every minute and update a players stats when they disconnect - not when the server is shutdown.


Re: Accounts don't save when close server. - Lordzy - 16.11.2014

OnGameModeExit cannot handle lot of codes since the server shuts down immediately. It's better for you to create a repeating timer which can save everyone's data globally. Also suggesting you to check if player is connected or not while looping through MAX_PLAYERS, it can process invalid data and also it's a waste of time while executing functions over player slots which aren't used.


Re: Accounts don't save when close server. - Kyance - 16.11.2014

Actually, the query size should be between 148 - 158 ( After calculating the approx. string size, it was 148 )
Anyways, do as sammp said, save the stats when a player disconnects, and also,
pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
{
    if(!IsPlayerConnected(i)) continue;
    //rest of code
}
Please use the "IsPlayerConnected" check, otherwise you will might write random stats for players. ( Due to the fact that 'MAX_PLAYERS' is the same as using "50", It goes from 0 to 50, writing the player stats.. i = 0, 1, 2, 3, 4, .... 50)


Re: Accounts don't save when close server. - Kwarde - 16.11.2014

Quote:
Originally Posted by Lordzy
Посмотреть сообщение
OnGameModeExit cannot handle lot of codes since the server shuts down immediately
If you quit the server with the exit RCON command, it does handle everything. Try to add an infinitive loop for example
pawn Код:
public OnGameModeExit()
{
    for( ; ; )
    {
    }
}
If you try to close your server with this (using the exit command), the server client won't close (atleast in Windows)