SA-MP Forums Archive
Having problem with saving system [MySql] - 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: Having problem with saving system [MySql] (/showthread.php?tid=658492)



Having problem with saving system [MySql] - akib - 05.09.2018

OnPlayerDisconnect sometime it don't save it and when player relog again, it reset all stats

SavePlayer code:
PHP код:
SavePlayer(playerid)
{
    if(
sInfo[playerid][loggedin] == 1)
    {
        if(
sInfo[playerid][spawned]==1)
        {
            new 
Float:x,Float:y,Float:z,Float:Angle;
            
GetPlayerFacingAngle(playeridAngle);
            
GetPlayerPos(playeridxyz);
            
sInfo[playerid][money] = GetPlayerMoney(playerid);
            
sInfo[playerid][level] = GetPlayerScore(playerid);
            
sInfo[playerid][s_posx] = x;
            
sInfo[playerid][s_posy] = y;
            
sInfo[playerid][s_posz] = z;
            
sInfo[playerid][s_angle] = Angle;
            
sInfo[playerid][skin] = GetPlayerCustomSkin(playerid);
            
sInfo[playerid][inter] = GetPlayerInterior(playerid);
            
sInfo[playerid][vw] = GetPlayerVirtualWorld(playerid);
            new 
query[512];
            
format(querysizeof(query), "UPDATE users SET money='%i', level='%i', pos_x='%f', pos_y='%f', pos_z='%f', angle='%f', inter='%i', vw='%i', skin='%i', job='%i' WHERE id='%i'"sInfo[playerid][money],sInfo[playerid][level],sInfo[playerid][s_posx],sInfo[playerid][s_posy],sInfo[playerid][s_posz],sInfo[playerid][s_angle],sInfo[playerid][inter],sInfo[playerid][vw],sInfo[playerid][skin],sInfo[playerid][job],sInfo[playerid][db_id]);
            
mysql_function_query(dbhandlequeryfalse"""");
        }
    }
    return 
1;

OnPlayerDisconnect code
PHP код:
public OnPlayerDisconnect(playeridreason)
{
    
SavePlayer(playerid);
    return 
1;

When player password response
PHP код:
public OnPasswordResponse(playerid)
{
    new 
num_fields,num_rows;
    
cache_get_data(num_rows,num_fields,dbhandle);
    if(
num_rows==1)
    {
        
//LoggedIn
        
sInfo[playerid][loggedin] = 1;
        print(
"Player logged");
        
sInfo[playerid][level] = cache_get_field_content_int(0,"level",dbhandle);
        
SetPlayerScore(playerid,sInfo[playerid][level]);
        
sInfo[playerid][db_id] = cache_get_field_content_int(0,"id",dbhandle);
        
GivePlayerMoney(playerid,cache_get_field_content_int(0,"money",dbhandle));
        
sInfo[playerid][alevel] = cache_get_field_content_int(0,"alevel",dbhandle);
        
sInfo[playerid][f_rank] = cache_get_field_content_int(0,"f_rank",dbhandle);
        
sInfo[playerid][s_posx] = cache_get_field_content_float(0,"pos_x",dbhandle);
        
sInfo[playerid][s_posy] = cache_get_field_content_float(0,"pos_y",dbhandle);
        
sInfo[playerid][s_posz] = cache_get_field_content_float(0,"pos_z",dbhandle);
        
sInfo[playerid][s_angle] = cache_get_field_content_float(0,"angle",dbhandle);
        
sInfo[playerid][skin] = cache_get_field_content_int(0,"skin",dbhandle);
        
sInfo[playerid][inter] = cache_get_field_content_int(0,"inter",dbhandle);
        
sInfo[playerid][vw] = cache_get_field_content_int(0,"vw",dbhandle);
        
sInfo[playerid][job] = cache_get_field_content_int(0,"job",dbhandle);
        
NiDInfo[playerid][NiDNumber] = cache_get_field_content_int(0,"nid",dbhandle);
        
NiDInfo[playerid][NiDSkin] = cache_get_field_content_int(0,"nidskin",dbhandle);
        new 
m[512];
        
format(msizeof(m), "NiD Number : 1%i"NiDInfo[playerid][NiDNumber]);
        
PlayerTextDrawSetString(playeridNidTD[playerid][4], m);
        
PlayerTextDrawSetPreviewModel(playeridNidTD[playerid][6], NiDInfo[playerid][NiDSkin]);
        new 
f_tmpn[128];
        
cache_get_field_content(playerid"f_name"f_tmpn);
        
strmid(sInfo[playerid][f_name], f_tmpn0sizeof(f_tmpn), sizeof(f_tmpn));
        
SetPlayerPos(playeridsInfo[playerid][s_posx], sInfo[playerid][s_posy], sInfo[playerid][s_posz]);
        
SetPlayerSkin(playeridsInfo[playerid][skin]);
        
SetCameraBehindPlayer(playerid);
    }
    else
    {
        
//Wrong password
        
ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login","Wrong password.\n\nEnter password:","Login","Quit");
    }
    return 
1;

sometime it don't save data on /q

P.S : I have put it on a 1sec timer also


Re: Having problem with saving system [MySql] - akib - 05.09.2018

Latest: on player disconnect not saving

When player do /q or exit anyway, it don't saving data :/
all pos 0 0 0 money 0 score 0 everything got reseted


Re: Having problem with saving system [MySql] - Shinja - 05.09.2018

Remove if(sInfo[playerid][spawned]==1) check at saving

Dont use if(num_rows==1) unless you used LIMIT 1 on your SELECT query, better let it if(num_rows)


Re: Having problem with saving system [MySql] - akib - 06.09.2018

Quote:
Originally Posted by Shinja
Посмотреть сообщение
Remove if(sInfo[playerid][spawned]==1) check at saving

Dont use if(num_rows==1) unless you used LIMIT 1 on your SELECT query, better let it if(num_rows)
Your solution will change the position on player connect, because it will save the pos x y z when player isn't spawned that mean it will store 0,0,0

I got the solution, just add IsPlayerConnected on it, solved. Thanks for your reply.