Last position not being saved upon disconnection
#1

Hello, I am using a SQLite type of saving system and recently I have noticed that my last position isn't being saved even though I am saving it before disconnecting and it worked before but suddenly it stopped.

here is my code
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    if(pLoggedIn[playerid] == true)
    {
        new Query[1000], Float:x, Float:y, Float:z, Float:a;
        GetPlayerPos(playerid, x, y, z);
        GetPlayerFacingAngle(playerid, a);
       
        pInfo[playerid][USER_POSX] = x;
        pInfo[playerid][USER_POSY] = y;
        pInfo[playerid][USER_POSZ] = z;
        pInfo[playerid][USER_ROTA] = a;
        pInfo[playerid][USER_SCORE] = GetPlayerScore(playerid);
        pInfo[playerid][USER_MONEY] = GetPlayerMoney(playerid);
       
       
        format(Query,sizeof(Query),"UPDATE users SET score = %d, money = %d, admin = %d, vip = %d, kills = %d, deaths = %d, skin = %d, userposx = %f, userposy = %f, userposz = %f, userrota = %f, faction = %d, factionrank = %d WHERE username = '%s'",
        pInfo[playerid][USER_SCORE], pInfo[playerid][USER_MONEY], pInfo[playerid][USER_ADMIN], pInfo[playerid][USER_VIP], pInfo[playerid][USER_KILLS], pInfo[playerid][USER_DEATHS], pInfo[playerid][USER_SKIN],
        pInfo[playerid][USER_POSX], pInfo[playerid][USER_POSY], pInfo[playerid][USER_POSZ],
        pInfo[playerid][USER_ROTA],DB_Escape(pInfo[playerid][USER_NAME]));
        db_query(Database, Query);

        FirstSpawn[playerid] = 0;
        pLoggedIn[playerid] = false;
        return 1;
    }

    for( new i; i < _: USER_DATA; ++i ) pInfo[ playerid ][ USER_DATA: i ] = 0;
    return 1;
}
Reply
#2

These fields do not have a specifier-values whatsoever: 'faction = %d, factionrank = %d'.

So, basically what it is doing:
Quote:

faction = PLAYER_NAME_AS_AN_INTEGER, factionrank = NULL WHERE username = 'NULL'

Also, you could do this instead:
pawn Код:
GetPlayerPos(playerid, pInfo[playerid][USER_POSX], pInfo[playerid][USER_POSY], pInfo[playerid][USER_POSZ]);
GetPlayerFacingAngle(playerid, pInfo[playerid][USER_ROTA]);
Also, you should format queries using format + strcat (I personally made a function called strcat_format for this matter), eventually you will get a warning that the input is too long.

And validate booleans like this:
pawn Код:
if(pLoggedIn[playerid])
if(!pLoggedIn[playerid])
And make FirstSpawn[playerid] a boolean.
Reply
#3

Код:
public OnPlayerDisconnect(playerid, reason)
{
	if(pLoggedIn[playerid] == true)
	{
	    new Query[1000], Float:x, Float:y, Float:z, Float:a;
	    GetPlayerPos(playerid, x, y, z);
	    GetPlayerFacingAngle(playerid, a);
	    
		pInfo[playerid][USER_SCORE] = GetPlayerScore(playerid);
		pInfo[playerid][USER_MONEY] = GetPlayerMoney(playerid);
		
		
	    format(Query,sizeof(Query),"UPDATE users SET score = %d, money = %d, admin = %d, vip = %d, kills = %d, deaths = %d, skin = %d, userposx = %f, userposy = %f, userposz = %f, userrota = %f WHERE username = '%s'",
		pInfo[playerid][USER_SCORE], pInfo[playerid][USER_MONEY], pInfo[playerid][USER_ADMIN], pInfo[playerid][USER_VIP], pInfo[playerid][USER_KILLS], pInfo[playerid][USER_DEATHS], pInfo[playerid][USER_SKIN],
		x,y,z,a,DB_Escape(pInfo[playerid][USER_NAME]));
	    db_query(Database, Query);

		FirstSpawn[playerid] = 0;
	    pLoggedIn[playerid] = false;
	    return 1;
	}

    for( new i; i < _: USER_DATA; ++i ) pInfo[ playerid ][ USER_DATA: i ] = 0;
	return 1;
}
You did not enter for ( faction = %d, factionrank = %d )
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)