04.05.2011, 08:01
Hello, this is my commands:
how to make this commands dialog based ?
Код:
CMD:register(playerid, params[]) { if(GetPVarInt(playerid, "Logged")) return SendClientMessage(playerid, COLOR_ORANGE, "[*] You're already logged in!"); if(isnull(params)) return SendClientMessage(playerid, COLOR_ORANGE, "[*] Usage: /register [pass]"); new Query[320], pName[MAX_PLAYER_NAME]; GetPlayerName(playerid, pName, MAX_PLAYER_NAME); mysql_real_escape_string(pName, pName); format(Query, sizeof Query, "SELECT * FROM `accounts` WHERE `Name` = '%s' LIMIT 1", pName); mysql_query(Query); mysql_store_result(); if(mysql_num_rows()) { SendClientMessage(playerid, COLOR_ORANGE, "[*] An account already exists under that name! Use \"/login\" to log in!"); mysql_free_result(); return 1; } mysql_free_result(); WP_Hash(Query, 129, params); new IP[16]; GetPlayerIp(playerid, IP, 16); format(Query, sizeof Query, "INSERT INTO `accounts` (Name, Password, IP, Admin, Money, Score, Kills, Deaths) VALUES ('%s', '%s', '%s', %i, %i, %i, %i, %i)", pName, Query, IP, GetPVarInt(playerid, "Admin"), GetPlayerMoney(playerid), GetPlayerScore(playerid), GetPVarInt(playerid, "Kills"), GetPVarInt(playerid, "Deaths")); mysql_query(Query); SetPVarInt(playerid, "Logged", 1); SendClientMessage(playerid, COLOR_LIMEGREEN, "[*] Succesfully registered and automatically logged in!"); return 1; } CMD:login(playerid, params[]) { if(GetPVarInt(playerid, "Logged")) return SendClientMessage(playerid, COLOR_ORANGE, "[*] You're already logged in!"); if(isnull(params)) return SendClientMessage(playerid, COLOR_ORANGE, "[*] Usage: /login [pass]"); new Query[256], pName[MAX_PLAYER_NAME]; GetPlayerName(playerid, pName, MAX_PLAYER_NAME); mysql_real_escape_string(pName, pName); format(Query, sizeof Query, "SELECT * FROM `accounts` WHERE `Name` = '%s' LIMIT 1", pName); mysql_query(Query); mysql_store_result(); if(!mysql_num_rows()) { SendClientMessage(playerid, COLOR_ORANGE, "[*] You're not registered! Use \"/register\" to register an account!"); mysql_free_result(); return 1; } mysql_free_result(); WP_Hash(Query, 129, params); format(Query, sizeof Query, "SELECT * FROM `accounts` WHERE `Name` = '%s' AND `Password` = '%s' LIMIT 1", pName, Query); mysql_query(Query); mysql_store_result(); if(!mysql_num_rows()) { SetPVarInt(playerid, "LoginWarns", GetPVarInt(playerid, "LoginWarns") + 1); if(GetPVarInt(playerid, "LoginWarns") == 3) { format(Query, sizeof Query, "[*] %s has been kicked for 3 wrong login attempts!", pName); SendClientMessageToAll(COLOR_ROYALBLUE, Query); Kick(playerid); } else { format(Query, sizeof Query, "[*] Wrong password! Attempt %i out of 3.", GetPVarInt(playerid, "LoginWarns")); SendClientMessage(playerid, COLOR_ORANGE, Query); } return 1; } mysql_fetch_row(Query); new values[5]; sscanf(Query, "p<|>{s[24]s[129]s[16]}a<i>[5]", values); //Enjoy editing. SetPVarInt(playerid, "Admin", values[0]); GivePlayerMoney(playerid, values[1]); SetPlayerScore(playerid, values[2]); SetPVarInt(playerid, "Kills", values[3]); SetPVarInt(playerid, "Deaths", values[4]); mysql_free_result(); SetPVarInt(playerid, "Logged", 1); SendClientMessage(playerid, COLOR_LIMEGREEN, "[*] Succesfully logged in!"); //Ip setting GetPlayerIp(playerid, Query, 16); format(Query, sizeof Query, "UPDATE `accounts` SET `IP` = '%s' WHERE `Name` = '%s' LIMIT 1", Query, pName); mysql_query(Query); return 1; }