mysql does no load players stats
#1

hi,

ive set up a mysql database cause i wanna get rid of dini.
But i have some problems.
Saving on disconnect works, also the login with the password ive registered but the player does not get the stats back after login he saved on disconnect.

pawn Code:
new Query[256], pname[24];
    GetPlayerName(playerid, pname, 24);
    format(Query, sizeof(Query), "SELECT * FROM `Users` WHERE `name` = '%s'", pname);
    mysql_query(Query);
    mysql_store_result();
   
    new row[1400];
    if(mysql_num_rows() == 0 )
    {
        print("MySQL Error: Account not found in MySQL Database!");
    }
    else
    {
        mysql_fetch_row(row);
        print(row);// heres a print
        sscanf(row, "p<|>ddddddddddddddddddddddddddddddddddddddd",
        SetPlayerScore(playerid,GetPlayerScore(playerid)),Cash[playerid],kills[playerid],tode[playerid],Spieler[playerid][AdminLevel],
        bombsmuggelcounter[playerid],countdownstartcounter[playerid],bombdisablecounter[playerid],foundmoneybag[playerid],
        playedmoneyrush[playerid],Hours[playerid],Minutes[playerid],randomwepgot[playerid],suddendeathmode[playerid],
        moneyrushstartcount[playerid],drugamount[playerid],RoundsWon[playerid],RoundsLost[playerid],weaponsbought[playerid],
        reactionwon[playerid],DrugsTaken[playerid],cookie[playerid],LottoWins[playerid],LottoWins[playerid],ChainsawRounds[playerid],
        WonChainsawing[playerid],ProCookies[playerid],c4[playerid],condom[playerid],RapedPeople[playerid],GotBriefCase[playerid],
        strike[playerid],strikeDone[playerid],c4done[playerid],ProRank[playerid],Spieler[playerid][Vip],AbsoluteFirstSpawn[playerid],
        WonDuels[playerid],LostDuels[playerid],IsPlayerBanned[playerid]);
        pRank[playerid] = floatround(floatpower((kills[playerid] / 25), 0.5), floatround_floor);
        if(pRank[playerid] >= FUNCTION(sizeof RankName)) pRank[playerid] = (sizeof RankName - 1);
    }
    mysql_free_result();
    print(row);//heres a print
there are 2 prints in this script and they show the right stats. (the row that has been fetched and every value is correct in the print)
But after spawn i get none of them.
So where could be the bug?

I hope someone can help me
Reply
#2

pawn Code:
SetPlayerScore(playerid,GetPlayerScore(playerid))
Isn't actually a variable to save into. What you would do is first save it into a score variable then set the score after the sscanf string.
Reply
#3

ok thx for the hint
but ive fixed this score variable already but the problem is i dont get any of the 39 stats variables loaded.
Pls take a look at the prints.It prints the whole mysql row that is fetched just perfectly including all stats that were saved but i dont get any of them after log in.

Would be great if u could tell me whats wrong here.

//edit

ive also printed an example variable after mysql_free_result and its shows me "null". in the log.
Reply
#4

Can you post the printed result?
Reply
#5

try not using sscanf, that fixed it for me when I had this problem.
Reply
#6

Code:
[18:43:56] [join] BlackWolf has joined the server 
[18:44:00] 1|BlackWolf|0cc175b9c0f1b6a831c399e269772661|0|0|20000|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|50|0|0|0|0|0|0|0|0|0|0|0|0|0|1|0|0|0//print1
[18:44:00] 1|BlackWolf|0cc175b9c0f1b6a831c399e269772661|0|0|20000|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|50|0|0|0|0|0|0|0|0|0|0|0|0|0|1|0|0|0//print2
[18:44:00] (null)//print3

//other prints printed after the login:
[18:44:00] StatsProofLoginMSG: Player BlackWolf has been logged in with: 0$ | 0 cookies | 0 kills | 0 deaths | 0 Score
[18:44:09] [part] BlackWolf has left the server (0:1)
and now the code so u know where it has been printed

pawn Code:
stock MySQL_Login(playerid)
{
    new Query[256], pname[24];
    GetPlayerName(playerid, pname, 24);
    format(Query, sizeof(Query), "SELECT * FROM `Users` WHERE `name` = '%s'", pname);
    mysql_query(Query);
    mysql_store_result();
   
    new row[1400];
    if(mysql_num_rows() == 0 )
    {
        print("MySQL Error: Account not found in MySQL Database!");
    }
    else
    {
        mysql_fetch_row(row);
        print(row);//print1
        sscanf(row, "p<|>ddddddddddddddddddddddddddddddddddddddd",
        SetPlayerScore(playerid,GetPlayerScore(playerid)),pCash[playerid],kills[playerid],tode[playerid],Spieler[playerid][AdminLevel],
        bombsmuggelcounter[playerid],countdownstartcounter[playerid],bombdisablecounter[playerid],foundmoneybag[playerid],
        playedmoneyrush[playerid],Hours[playerid],Minutes[playerid],randomwepgot[playerid],suddendeathmode[playerid],
        moneyrushstartcount[playerid],drugamount[playerid],RoundsWon[playerid],RoundsLost[playerid],weaponsbought[playerid],
        reactionwon[playerid],DrugsTaken[playerid],cookie[playerid],LottoWins[playerid],LottoWins[playerid],ChainsawRounds[playerid],
        WonChainsawing[playerid],ProCookies[playerid],c4[playerid],condom[playerid],RapedPeople[playerid],GotBriefCase[playerid],
        strike[playerid],strikeDone[playerid],c4done[playerid],ProRank[playerid],Spieler[playerid][Vip],AbsoluteFirstSpawn[playerid],
        WonDuels[playerid],LostDuels[playerid],IsPlayerBanned[playerid]);
        pRank[playerid] = floatround(floatpower((kills[playerid] / 25), 0.5), floatround_floor);
        if(pRank[playerid] >= FUNCTION(sizeof RankName)) pRank[playerid] = (sizeof RankName - 1);
    }
    mysql_free_result();
    print(row);//print2
    print(pCash[playerid]);//print3

//other print is somewhere under this...
Reply
#7

pawn Code:
SetPlayerScore(playerid,GetPlayerScore(playerid))
try replacing that with a variable
Reply
#8

Quote:
Originally Posted by dowster
View Post
pawn Code:
SetPlayerScore(playerid,GetPlayerScore(playerid))
try replacing that with a variable
He has already done that.

Also, you seem to have 41 fields returned, not 39.
Reply
#9

yes killer ure right but that does not solve my prob cause no single field is given to me after log in.
Could someone make an example for me how to do this without sscanf?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)