SA-MP Forums Archive
MySQL does not save score, money - 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: MySQL does not save score, money (/showthread.php?tid=481925)



MySQL does not save score, money - ZBits - 18.12.2013

Hello there,

Please help me with this, my mysql does not save my money, score.

my SavePlayer Code

pawn Код:
SavePlayer(playerid)
{
if(pInfo[playerid][Logged] == 1)
{
new Query[500];
format(Query, 500, "UPDATE `playerdata` SET `admin` =%i, `score` =%i, `money` =%i, `kills` =%i, `deaths` =%i WHERE `id` =%d LIMIT 1",
pInfo[playerid][pAdmin],
pInfo[playerid][pScore],
pInfo[playerid][pMoney],
pInfo[playerid][pKills],
pInfo[playerid][pDeaths],
pInfo[playerid][ID]);
mysql_query(Query);
print(Query);
}
}
Thanks for any help provided!


Re: MySQL does not save score, money - speed258 - 18.12.2013

Quote:

format(Query, 500, "UPDATE `playerdata` SET `admin` = '%i', `score` = '%i', `money` = '%i', `kills` = '%i', `deaths` = '%i' WHERE `id` = '%d' LIMIT 1",

you missed these: ' '


Re: MySQL does not save score, money - Patrick - 18.12.2013

Quote:
Originally Posted by speed258
Посмотреть сообщение
you missed these: ' '
No, ' ' is mosly used on %s placeholder, This code should work

pawn Код:
SavePlayer(playerid)
{
    if(pInfo[playerid][Logged] != 1) return true;
   
    new Query[500], pInfo[playerid][pScore] = GetPlayerScore(playerid), pInfo[playerid][pMoney] = GetPlayerMoney(playerid);

    format( Query, sizeof( Query ), "UPDATE `playerdata` SET `admin` =%i, `score` =%i, `money` =%i, `kills` =%i, `deaths` =%i WHERE `id` =%d LIMIT 1",pInfo[playerid][pAdmin],pInfo[playerid][pScore],pInfo[playerid][pMoney],pInfo[playerid][pKills],pInfo[playerid][pDeaths],pInfo[playerid][ID]);
    mysql_query(Query);
    print(Query);
   
}



Re: MySQL does not save score, money - CaveDweller - 18.12.2013

Quote:
Originally Posted by speed258
Посмотреть сообщение
you missed these: ' '
You don't need those around integral values.

Domnic Toretto, please go into your server log and you should see something like:
Код:
UPDATE `playerdata` SET `admin` =0, `score` =1, `money` =3000, `kills` =4, `deaths` =8 WHERE `id` =22 LIMIT 1
Please post this.


Re: MySQL does not save score, money - ZBits - 18.12.2013

Quote:
Originally Posted by pds2k12
Посмотреть сообщение
No, ' ' is mosly used on %s placeholder, This code should work

pawn Код:
SavePlayer(playerid)
{
    if(pInfo[playerid][Logged] != 1) return true;
   
    new Query[500], pInfo[playerid][pScore] = GetPlayerScore(playerid), pInfo[playerid][pMoney] = GetPlayerMoney(playerid);

    format( Query, sizeof( Query ), "UPDATE `playerdata` SET `admin` =%i, `score` =%i, `money` =%i, `kills` =%i, `deaths` =%i WHERE `id` =%d LIMIT 1",pInfo[playerid][pAdmin],pInfo[playerid][pScore],pInfo[playerid][pMoney],pInfo[playerid][pKills],pInfo[playerid][pDeaths],pInfo[playerid][ID]);
    mysql_query(Query);
    print(Query);
   
}
I get errors

Код:
C:\Users\-\Desktop\-\gamemodes\freeroamz.pwn(1862) : warning 219: local variable "pInfo" shadows a variable at a preceding level
C:\Users\-\Desktop\-\gamemodes\freeroamz.pwn(1862) : error 008: must be a constant expression; assumed zero
C:\Users\-\Desktop\-\gamemodes\freeroamz.pwn(1862) : error 008: must be a constant expression; assumed zero
C:\Users\-\Desktop\-\gamemodes\freeroamz.pwn(1864) : error 032: array index out of bounds (variable "pInfo")
C:\Users\-\Desktop\-\gamemodes\freeroamz.pwn(1868) : warning 209: function "SavePlayer" should return a value
C:\Users\-\Desktop\-\gamemodes\freeroamz.pwn(1862) : warning 204: symbol is assigned a value that is never used: "pInfo"
@ Cave
Код:
UPDATE `playerdata` SET `admin` =4, `score` =0, `money` =0, `kills` =0, `deaths` =0 WHERE `id` =1478 LIMIT 1



Re: MySQL does not save score, money - Patrick - 18.12.2013

Quote:
Originally Posted by Domnic Toretto
Посмотреть сообщение
I get errors

Код:
C:\Users\-\Desktop\-\gamemodes\freeroamz.pwn(1862) : warning 219: local variable "pInfo" shadows a variable at a preceding level
C:\Users\-\Desktop\-\gamemodes\freeroamz.pwn(1862) : error 008: must be a constant expression; assumed zero
C:\Users\-\Desktop\-\gamemodes\freeroamz.pwn(1862) : error 008: must be a constant expression; assumed zero
C:\Users\-\Desktop\-\gamemodes\freeroamz.pwn(1864) : error 032: array index out of bounds (variable "pInfo")
C:\Users\-\Desktop\-\gamemodes\freeroamz.pwn(1868) : warning 209: function "SavePlayer" should return a value
C:\Users\-\Desktop\-\gamemodes\freeroamz.pwn(1862) : warning 204: symbol is assigned a value that is never used: "pInfo"
@ Cave
Код:
UPDATE `playerdata` SET `admin` =4, `score` =0, `money` =0, `kills` =0, `deaths` =0 WHERE `id` =1478 LIMIT 1
Show me the code where the error occurs.


Re: MySQL does not save score, money - ZBits - 18.12.2013

pawn Код:
SavePlayer(playerid)
{
    if(pInfo[playerid][Logged] != 1) return true;
   
    new Query[500], pInfo[playerid][pScore] = GetPlayerScore(playerid), pInfo[playerid][pMoney] = GetPlayerMoney(playerid);

    format( Query, sizeof( Query ), "UPDATE `playerdata` SET `admin` =%i, `score` =%i, `money` =%i, `kills` =%i, `deaths` =%i WHERE `id` =%d LIMIT 1",pInfo[playerid][pAdmin],pInfo[playerid][pScore],pInfo[playerid][pMoney],pInfo[playerid][pKills],pInfo[playerid][pDeaths],pInfo[playerid][ID]);
    mysql_query(Query);
    print(Query);
   
}



Re: MySQL does not save score, money - ZBits - 18.12.2013

I fixed it, i added
pawn Код:
pInfo[playerid][pScore] = GetPlayerScore(playerid);
to SavePlayer and the Login function and it works perfectly. Same with the Money thing.

Thanks for any help provided