Saving data.
#1

Hey guys, im having an issue with data.
Im saving data with the following code and executing this ingame on command /savestats
however, sometimes a player logs in to find his EXPE set to 0, meaning it did not load, or it did not save.

this is the stock for saving
Code:
stock SavePlayerData(playerid)
{
        new query[512];
        mysql_format(mysql, query, sizeof(query), "UPDATE `players` SET `IP`='%s', `Admin`=%i, `VIP`=%i, `EXPE`=%i, `Kills`=%i, `Deaths`=%i, `Score`=%i, `Wanted`=%i, `Money`=%i WHERE `ID`=%d",
        IP[playerid], pData[playerid][Admin], pData[playerid][VIP], pData[playerid][EXPE], pData[playerid][Kills], pData[playerid][Deaths], GetPlayerScore(playerid), GetPlayerWantedLevel(playerid), pData[playerid][Money], pData[playerid][ID]);
        mysql_tquery(mysql, query, "", "");
}
Then again, i have another problem with the /stats command, its showing everything, exept for the players score.
Code:
CMD:stats(playerid, params[])
{
        new str[254];
        new deaths = pData[playerid][Deaths];
        if(!deaths) deaths = 1;
        new Float:kd =  floatdiv(pData[playerid][Kills], deaths);
        format(str, sizeof(str),"Your Stats\nScore: %d\nKills: %i\nDeaths: %i\nKD-Ratio: %0.2f\nMoney: %i\nXP: %i\nVIP Level: %i",pData[playerid][Score],pData[playerid][Kills],pData[playerid][Deaths],kd,pData[playerid][Money],pData[playerid][EXPE],pData[playerid][VIP]);
        ShowPlayerDialog(playerid, dSTATS,DIALOG_STYLE_MSGBOX,"Account stats",str, "Close","");
        return 1;
}
And ofcourse the Load data code.
Code:
public OnAccountLoad(playerid)
{
        new score;
        new wantedl;
        new XPl;
        pData[playerid][Admin] = cache_get_field_content_int(0, "Admin");
        pData[playerid][VIP] = cache_get_field_content_int(0, "VIP");
        pData[playerid][Money] = cache_get_field_content_int(0, "Money");
        pData[playerid][Kills] = cache_get_field_content_int(0,"Kills");
        pData[playerid][Deaths] = cache_get_field_content_int(0, "Deaths");
        score = cache_get_field_content_int(0, "Score");
        SetPlayerScore(playerid, score);
        wantedl = cache_get_field_content_int(0, "Wanted");
        SetPlayerWantedLevel(playerid, wantedl);
        XPl = cache_get_field_content_int(0, "EXPE");
        SetPlayerXP(playerid, XPl);
        GivePlayerMoney(playerid, pData[playerid][Money]);
        SendClientMessage(playerid, COLOR_WHITE, "{ff387a}[Server]:{ffffff} You have successfully logged in!");
        return 1;
}
The Database fields look like : http://prntscr.com/9b5zou

So i wonder what i have been doing wrong, am i placing %i and %d wrong because i thought they meant the same thing.
Reply
#2

PHP Code:
SetPlayerScore(playeridscore); 
You're setting the score, but not the var in pData use GetPlayerScore for the stats
PHP Code:
format(strsizeof(str),"Your Stats\nScore: %d\nKills: %i\nDeaths: %i\nKD-Ratio: %0.2f\nMoney: %i\nXP: %i\nVIP Level: %i",GetPlayerScore(playerid),pData[playerid][Kills],pData[playerid][Deaths],kd,pData[playerid][Money],pData[playerid][EXPE],pData[playerid][VIP]); 
Reply
#3

i see that seems to have worked.
Do you maybe also have an idea why sometimes when im ingame and i quit without /savestats the EXPE in the database gets reset to 0?
Reply
#4

Also when my vip level is set to 5, and i type /stats it also is showing as 0.
Reply
#5

Are you saving them when you disconnect?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)