30.05.2012, 09:28
Follow the tut better OnPlayerConnect does what you want read the comments.
Taken from [HiC]TheKiller's tut:
Taken from [HiC]TheKiller's tut:
pawn Код:
public OnPlayerConnect(playerid)
{
MoneyGiven[playerid] = -1; //Resets the variable that you will discover later in the tutorial.
new query[200], pname[24]; //Creates our variables.
GetPlayerName(playerid, pname, 24); //Gets the players name
format(query, sizeof(query), "SELECT IP FROM `playerdata` WHERE user = '%s' LIMIT 1", pname); //Formats the query, view above the code for a explanation
mysql_query(query); //This is our query function to query the string
mysql_store_result(); //We store the result.
new rows = mysql_num_rows(); //We get how many rows the query returned.
if(!rows)
{
//If the rows are equal to 0. This means that the query did not find
//anyone under the name we connected under in the database.
//So here we send the player the register dialog.
ShowPlayerDialog(playerid, 15000, DIALOG_STYLE_INPUT, "Register","Your user is {FF0000}not{FFFFFF} registered! Please {0000FF}register{FFFFFF} with a password below!","Register","Cancel"); //Shows our register dialog :).
}
if(rows == 1)
{
//If the rows are equal to 1, this means there is a player already registered
//so we can initiate the login dialog to the player or check if the players
//current IP is the same one as in the database.
new IP[2][16]; //We create a variable with two IP strings, one for retrieving the mysql field and one for GetPlayerIP.
mysql_fetch_field_row(IP[0],"IP");
GetPlayerIp(playerid, IP[1], 16);
if(strlen(IP[0]) != 0 && !strcmp(IP[0], IP[1], true)) //Checks that the MySQL IP has a value and that they are the same.
{
MySQL_Login(playerid);
}
else if(!strlen(IP[0]) || strcmp(IP[0], IP[1], true))
{
ShowPlayerDialog(playerid, 15500, DIALOG_STYLE_INPUT, "Login","Your user is {FF0000}registered{FFFFFF}! Please {0000FF}login{FFFFFF} with your password below!","Login","Cancel"); //Shows our login dialog :).
IsRegistered[playerid] = 1; //Sets the registered variable to 1 (Shows that the player is registered).
}
}
mysql_free_result();
//You must always free the mysql result to avoid
//there being massive memory usage.
return 1;
}