Mysql Registration help - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Mysql Registration help (
/showthread.php?tid=256883)
Mysql Registration help -
futuretrucker - 22.05.2011
I am currently working on a mysql registration system. I have everything working besides taking things out of the database such as score and money. I have money set to 100 in the database and score set to 9. When I go into the game it gives me 53 dollars and 52 score. Can anyone help me sort this out?
Here is the code I am using.
pawn Код:
case LOGIN_DIALOG:
{
new Query[300];
format(Query,sizeof(Query),"SELECT * FROM `names` WHERE `Username` = '%s' AND `Password` = '%s'", Name(playerid), inputtext);
mysql_query(Query);
mysql_store_result();
if(!mysql_num_rows())
{
SendClientMessage(playerid, red, "Your account isnt registered or your password is wrong!");
LoginDialog(playerid);
}
else
{
new stats[2500];
if(mysql_fetch_row_format(stats))
{
mysql_fetch_field_row(pInfo[playerid][Money],"Money");
mysql_fetch_field_row(pInfo[playerid][Level],"Level");
mysql_fetch_field_row(pInfo[playerid][Score],"Score");
SetPlayerScore(playerid, pInfo[playerid][Score]);
GivePlayerMoney(playerid,pInfo[playerid][Money]);
print(pInfo[playerid][Money]);
print(pInfo[playerid][Score]);
}
pInfo[playerid][logged] = 1;
SendClientMessage(playerid, green, "You have succesfully logged in!");
printf("%s (%i) logged in with password %s", Name(playerid), playerid, inputtext);
}
mysql_free_result();
if(response == 0)
{
SendClientMessage(playerid, red, "You must log in or register to use this server");
}
return 1;
}
Re: Mysql Registration help -
Georgelopez1 - 22.05.2011
Perhaps put it in a stock?
Re: Mysql Registration help -
BLAbla93 - 22.05.2011
You do not need a stock but when you get the Query string from the db and then split it with sscanf.
so instead of mysql_fetch_field_row(...) use sscanf(stats, "p<|>ddd", pInfo[playerid][Money], pInfo[playerid][Score], pInfo[playerid][Level]);
Re: Mysql Registration help -
futuretrucker - 22.05.2011
Could this part of the sscanf be explained? "p<|>ddd" I read the sscanf post and I still have no idea how to use it on something like this.
Re: Mysql Registration help -
BLAbla93 - 22.05.2011
p<|> = split were it finds a | and d = a interger so a number
Re: Mysql Registration help -
futuretrucker - 22.05.2011
So if i understand this rite. In my mysql_log this shows up: [16:54:43] CMySQLHandler::FetchRow() - Return: Futuretrucker|zack|255.255.255.255|100|9|5
I would use this code to get the values? : sscanf(stats, "p<|>sssddd", pInfo[playerid][Pname], pInfo[playerid][Password], pInfo[playerid][Ip], pInfo[playerid][Money], pInfo[playerid][Score], pInfo[playerid][Level]);
Re: Mysql Registration help -
JaTochNietDan - 23.05.2011
Quote:
Originally Posted by futuretrucker
So if i understand this rite. In my mysql_log this shows up: [16:54:43] CMySQLHandler::FetchRow() - Return: Futuretrucker|zack|255.255.255.255|100|9|5
I would use this code to get the values? : sscanf(stats, "p<|>sssddd", pInfo[playerid][Pname], pInfo[playerid][Password], pInfo[playerid][Ip], pInfo[playerid][Money], pInfo[playerid][Score], pInfo[playerid][Level]);
|
That is correct!