22.11.2014, 07:43
so when player join my server register dialog is not showing
pawn Код:
public OnAccountCheck(playerid)
{
new rows, fields; //a variable that will be used to retrieve rows and fields in the database.
cache_get_data(rows, fields, mysql);//let's get the rows and fields from the database.
if(rows) //if there is row
{//then
cache_get_row(0, 2, pInfo[playerid][Password], mysql, 129);
//we will load their password into pInfo[playerid][Password] to be used in logging in
//0 is row, 2 is field. If you're wondering why row is 0; remember we used LIMIT 1 while checking player's account. LIMIT is a limitation of results to be shown. Since we used LIMIT 1, it'd be like;
// ---> row> ID | Username | Password | IP | Admin | .... and so on
// ^ ^ ^
// fields 0 1 2
//So we're getting row 0, field 2 which is password
pInfo[playerid][ID] = cache_get_row_int(0, 0); //now let's load player's ID into pInfo[playerid][ID] so we can use it later
printf("%s", pInfo[playerid][Password]); //OPTIONAL: Just for debugging. If it didn't show your password, then there must be something wrong while getting player's password
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Login", "In order to play, you need to login", "Login", "Quit"); //And since we found a result from the database, which means, there is an account; we will show a login dialog
}
else //if we didn't find any rows from the database, that means, no accounts were found
{
ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Register", "In order to play, you need to register.", "Register", "Quit");
//So we show the a dialog register
}
return 1;
}
pawn Код:
public OnPlayerConnect(playerid)
{
new query[128]; //We use this variable to format our query
GetPlayerName(playerid, Name[playerid], 24); //Getting player's name
GetPlayerIp(playerid, IP[playerid], 16); //Getting layer's IP
mysql_format(mysql, query, sizeof(query),"SELECT * FROM `players` WHERE `Username` = '%e' LIMIT 1", Name[playerid]);
// - We use mysql_format instead of format because we can use an %e specifier. %e specifier escapes a string so we can avoid sql injection which means we don't have to use mysql_real_escape_string
// - Formatting our query; SELECT * FROM `players` WHERE `Username`='%e' means we are selecting all rows in the table called `players` that has your name in Username column
// - LIMIT 1; we only need 1 result to be shown
mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);
//lets execute the formatted query and when the execution is done, a callback OnAccountCheck will be called
//You can name the callback however you like
return 1;
}