I have made a register system with mysql, but it doesn't work well. I have created this on OnDialogResponse:
Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == 2)
{
if(response)
{
if(!strlen(inputtext))
{
ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Register", "You don't have an account. Please Register.", "Register", "Cancel");
SendClientMessage(playerid, COLOR_RED, "You have to enter an password");
}
new PIP[50];
new Query[300], Pname[24];
GetPlayerName(playerid, Pname, 24);
new escpname[24], escpass[100];
mysql_real_escape_string(inputtext, escpass);
mysql_real_escape_string(Pname, escpname);
GetPlayerIp(playerid, PIP, 50);
format(Query, sizeof(Query), "INSERT INTO `playerinfo` (`user`, `password`, `adminlevel`, `rank`, `rankn`, `score`, `money`, `working`, `flylicense`, `rankc`, `IP`) VALUES ('%s', '%s', 0, 0, 'Trucker Wannabe', 0, 5000, 0, 0, 0, '%s')", escpname, escpass, PIP); //Insert string
mysql_query(Query);
GameTextForPlayer(playerid, "~g~Registerd", 2000, 3);
SendClientMessage(playerid, COLOR_YELLOW, "Registerd and logged in!");
gPlayerLogged[playerid] = 1;
}
}
if(dialogid == 1)
{
if(response)
{
new Query[300], Pname[24];
GetPlayerName(playerid, Pname, 24);
new escpname[24];
mysql_real_escape_string(Pname, escpname);
format(Query, sizeof(Query), "SELECT * FROM `playerinfo` WHERE `user` = '%s' AND `password` = '%s'", escpname, inputtext);
mysql_query(Query);
mysql_store_result();
if(!mysql_num_rows())
{
SendClientMessage(playerid, COLOR_RED, "Wrong Password");
maxtries[playerid] = maxtries[playerid] + 1;
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Login", "This account is registerd. please log in.", "Ok", "Cancel");
if(maxtries[playerid] == 3)
{
SendClientMessage(playerid, COLOR_RED, "Max tries exceeded!");
Kick(playerid);
}
}
else
{
new line[2048];
if(mysql_fetch_row_format(line, "|"))
{
if(sscanf(line, "p<|>e<s[40]s[40]dds[40]ddddxs[40]>", PlayerInfo[playerid]))
{
SendClientMessage(playerid, COLOR_RED, "There is an error with loading your account.");
}
else
{
SetPlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
SetPlayerColor(playerid, PlayerInfo[playerid][pRankC]);
SendClientMessage(playerid, COLOR_YELLOW, "Succesful logged in!");
gPlayerLogged[playerid] = 1;
}
}
}
}
}
return 1;
}
When i am alone, it just works fine, but when we are with 2 or more, everything is doing weard. My color is doing weard and everything does weard. PlayerInfo doesn't function right on the login. How can i help this?
One huge problem I see is that you forgot to exit the callback with a return when there's no inputtext.
@vince, but that is not the problem, it's just the problem that the PlayerInfo doesn't work with 2 or more players