Mysql load/save buged
#1

hi everyone

i have this script in my mysql load/save system:

Код:
stock MySQL_Save(playerid)
{
        if( online[ playerid ] )
        {
            new Query[ 512 ];

			printf( "Iљsaugoma. [%s]", GetPlayerNameEx( playerid ) );

			zInfo[ playerid ][ Pinigai ] = GetPlayerMoney(playerid);
			zInfo[ playerid ][ Patirtis ] = GetPlayerScore(playerid);

			format( Query, sizeof( Query ),"UPDATE `minim` SET pinigai = '%i', patirtis = '%i', admin = '%i', vip = '%i' WHERE vardas = '%s'",\
			zInfo[ playerid ][ Pinigai ], zInfo[ playerid ][ Patirtis ], zInfo[ playerid ][ Admin ], zInfo[ playerid ][ Vip ], GetPlayerNameEx( playerid ) );
			mysql_query( Query );
        }
        return 1;
}

stock MySQL_Load(playerid)
{
        new
                fetch[ 16 ],
            	Query[ 256 ];

	    format(Query, sizeof(Query), "SELECT * FROM `minim` WHERE vardas = '%s'", GetPlayerNameEx(playerid));
    	mysql_query(Query);
        mysql_store_result();
        mysql_retrieve_row();

        mysql_fetch_field_row( fetch, "pinigai" );               zInfo[ playerid ][ Pinigai ] = strval(fetch); 		GivePlayerMoney(playerid, zInfo[playerid][Pinigai]);
        mysql_fetch_field_row( fetch, "patirtis" );      		 zInfo[ playerid ][ Patirtis ] = strval(fetch);      SetPlayerScore(playerid, zInfo[playerid][Patirtis]);
        mysql_fetch_field_row( fetch, "admin" );      			 zInfo[ playerid ][ Admin ] = strval(fetch);
        mysql_fetch_field_row( fetch, "vip" );      			 zInfo[ playerid ][ Vip ] = strval(fetch);

        mysql_free_result();

        printf( "Pakrautas ћaidėjas. [%s]", GetPlayerNameEx( playerid ) );

        return 1;
}
Код:
public OnPlayerDisconnect(playerid, reason)
{
    if( online[ playerid ] )
    {
    	MySQL_Save( playerid );
    }
	return 1;
}
Код:
public OnFilterScriptExit()
{	
	for(new i=0; i < MAX_PLAYERS; i++)
 	{
  		if( IsPlayerConnected(i) && online[i] ) MySQL_Save(i);
    }
    mysql_close( );
	return 1;
}
sometimes its not saving the account but log is showing nothing, sometimes saves admin/vip when player dosent have one. whear is the problem?

sorry for bad english
Reply
#2

1st your server is not protected against money cheats with this: zInfo[ playerid ][ Pinigai ] = GetPlayerMoney(playerid);
And make a cmd, /restart, where you save all accounts, and then set timer to unloadfs and close mysql, but why you dealing with user data saving in filterscripts?
Reply
#3

Not realy get that /restart cmd is for?... i'm saving it in filterscript becouse it's MiniMissions server, and all the missions are in difrent gamemodes.
Reply
#4

with /restart cmd I believe your FS unloads and close connection before it have saved all users, thats why make a cmd like /changemission where you save all users, and then after like a second, close mysql and unloadfs without worries
Reply
#5

but in samp when gamemod is restarting the filterscript is'nt restarting it's load for all the time, it's unloading when you shut down server
Reply
#6

Well i took a fast look and you should replace the '%i' with %d only, it's not needed to put '' around integers.
And it's better if you save a player on a unique ID instead of his name.
And one last thing, maybe this is my opinion, but stop using filterscripts for things like this.
Filterscripts are only good when you have small scripts to load sometimes, like objecteditors, objects things like that, but if you are using filterscripts inside your server.cfg you better can just convert them into your gamemode, because it's pointless to use filterscripts when you always use them, and for me those things always caused wierd bugs...
Thats why I never use filterscripts.
Anyway I think you made some small mistake at the saving or loading part, you should check it and see if it all match with your database structure ect.
I can find the cause in this code.
Reply
#7

i found that after crash the script doesnt save player, when he logs out normal its saves
Reply
#8

Yes, sometimes when the server crashes it doesnt go over onplayerdisconnect or ongamemodedisconnect I guess.
What I did is just saving all accounts each minute, but you should use MySQL R7, else this may cause lag.
Reply
#9

Quote:
Originally Posted by Roel
Посмотреть сообщение
Yes, sometimes when the server crashes it doesnt go over onplayerdisconnect or ongamemodedisconnect I guess.
What I did is just saving all accounts each minute, but you should use MySQL R7, else this may cause lag.
Tryed that, not working, some times still don't save player information in mysql logs are good but it's not working
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)