07.08.2012, 10:32
Hello.I got problem with my Register system.When I join to game none dialog shows up.I don`t know what`s the problem but that is strange!
Code:
Here is my full Register System take a look and tell me where is problem.Thanks
Code:
pawn Код:
// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT
#include <a_samp>
#include <a_mysql>
#include <zcmd>
#include <sscanf2>
#define mysql_host "127.0.0.1" //Has to be a string
#define mysql_user "root" //Has to be a string
#define mysql_password "" //There is none for wamp unless you set one.
#define mysql_database "sa-mp" //Has to be a string
#define COL_GREEN "{6EF83C}"
#define COL_RED "{F81414}"
#define COL_BLUE "{00C0FF}"
#define embed_blue "{00C0FF}"
#define embed_red "{FF0000}"
#define embed_white "{FFFFFF}"
#define embed_green "{33FF33}"
#define embed_yellow "{E8D04C}"
#define embed_grey "{C0C0C0}"
#define embed_orange "{FF9900}"
#define embed_pink "{FF66FF}"
#define embed_lblue "{00AFFF}"
#define embed_sw "{ED136A}"
#define ERROR 0xFF0000AA
#define SYSTEM 0x375FFFFF
#define blue 0x375FFFFF
#define red 0xFF0000FF
#define white 0xFFFFFFFF
#define green 0x33FF33FF
#define yellow 0xFFFF00FF
#define grey 0xC0C0C0FF
#define orange 0xFF9900FF
#define pink 0xFF66FFFF
new IsRegistered[MAX_PLAYERS];
new Pname[24];
new MoneyGiven[MAX_PLAYERS];
new Logged[MAX_PLAYERS];
new AdminL[MAX_PLAYERS];
new Banned[MAX_PLAYERS];
new Kills[MAX_PLAYERS];
new Deaths[MAX_PLAYERS];
new dbHandle;
public OnFilterScriptInit()
{
print("\n--------------------------------------");
print(" Blank Filterscript by your name here");
print("--------------------------------------\n");
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
main()
{
print("\n----------------------------------");
print(" SA-MP Border Attacks");
print("----------------------------------\n");
}
public OnGameModeInit()
{
mysql_connect(mysql_host, mysql_user, mysql_database, mysql_password);
mysql_function_query(dbHandle,"CREATE TABLE IF NOT EXISTS playerdata(user VARCHAR(24), password VARCHAR(41), score INT(20), money INT(20), IP VARCHAR(16), level INT(20), ban INT(20), kills INT(20), deaths INT(20))",false,"","");
//Fields:
//Field Name - Use - Type
//user- Player Name - String
//password- Players password - String
//score - Players score - int
//money - Players Cash - int
//IP - Players IP - int
SetGameModeText("Border Line");
AddPlayerClass(281,1524.9503,-1677.9791,5.8906,270.5254,31,200,29,120,22,50); // Police
return 1;
}
public OnGameModeExit()
{
return 1;
}
public OnPlayerRequestClass(playerid, classid)
{
//Your code for Requesting class
return 1;
}
public OnPlayerConnect(playerid)
{
MoneyGiven[playerid] = -1;
new query[200], pName[MAX_PLAYER_NAME],string[140];
TogglePlayerSpectating(playerid,0);
GetPlayerName(playerid, pName,sizeof(pName));
format(query, sizeof(query), "SELECT IP FROM `playerdata` WHERE user = '%s' LIMIT 1", pName);
mysql_function_query(dbHandle,query,false,"","");
mysql_store_result();
new rows = mysql_num_rows();
if(!rows)
{
format(string, sizeof(string), "{FFFFFF}Welcome "COL_BLUE"%s(%d){FFFFFF} to the server, you're "COL_RED"not{FFFFFF} registered\n\nPlease log in by inputting your password.", pName, playerid);
ShowPlayerDialog(playerid, 15000, DIALOG_STYLE_INPUT, "Register",string,"Register","Cancel"); //Shows our register dialog :).
}
if(rows == 1)
{
new IP[2][16];
mysql_fetch_field_row(IP[0],"IP");
GetPlayerIp(playerid, IP[1], 16);
if(strlen(IP[0]) != 0 && !strcmp(IP[0], IP[1], true))
{
MySQL_Login(playerid);
}
else if(!strlen(IP[0]) || strcmp(IP[0], IP[1], true))
{
format(string, sizeof(string), "{FFFFFF}Welcome "COL_BLUE"%s(%d){FFFFFF} to the server, you're registered\n\nPlease log in by inputting your password.", pName, playerid);
ShowPlayerDialog(playerid, 15500, DIALOG_STYLE_INPUT, "Login",string,"Login","Cancel");
IsRegistered[playerid] = 1;
}
}
mysql_free_result();
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
if(Logged[playerid] == 1)
{
new score = GetPlayerScore(playerid);
new money = GetPlayerMoney(playerid);
new query[200], pname[24];
GetPlayerName(playerid, pname, 24);
format(query, sizeof(query), "UPDATE playerdata SET score=%d, money=%d, level=%d, ban=%d, kills=%d, deaths=%d WHERE user='%s'", score, money, pname);
mysql_function_query(dbHandle,query,false,"","");
}
return 1;
}
public OnPlayerSpawn(playerid)
{
if(MoneyGiven[playerid] != -1)
{
GivePlayerMoney(playerid, MoneyGiven[playerid]);
MoneyGiven[playerid] = -1;
}
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
new str[128];
Kills[killerid]++;
Deaths[playerid]++;
format(str, sizeof(str), "UPDATE `playerdata` SET `kills` = %d WHERE `User` = '%s'", Kills[killerid], PlayerName(killerid));
mysql_function_query(dbHandle,str,false,"","");
format(str, sizeof(str), "UPDATE `playerdata` SET `deaths` = %d WHERE `User` = '%s'", Deaths[playerid], PlayerName(playerid));
mysql_function_query(dbHandle,str,false,"","");
return 1;
}
public OnVehicleSpawn(vehicleid)
{
return 1;
}
public OnVehicleDeath(vehicleid, killerid)
{
return 1;
}
public OnPlayerText(playerid, text[])
{
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
return 0;
}
CMD:setlevel(playerid, params[])
{
new
id,
level,
str[158]
;
if(AdminL[playerid] >= 5 || IsPlayerAdmin(playerid))
{
if(sscanf(params, "ui", id, level))
{
return SendClientMessage(playerid, 0x0FB4F5FF, "Usage: /setlevel (playerid) (level)") &&
SendClientMessage(playerid, 0x7EF50FFF, "Function: Set a person a admin");
}
if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xF50F35FF, "ERROR: That is a invalid player ID");
format(str, sizeof(str), "UPDATE `playerdata` SET `level` = %d WHERE `User` = '%s'", level, PlayerName(id));
mysql_function_query(dbHandle,str,false,"","");
format(str, sizeof(str), ""embed_sw"[ADMIN]"embed_white"Administrator "embed_sw"%s "embed_white"has made "embed_sw"%s "embed_blue"(%d) "embed_white"admin level "embed_orange"%d"embed_white"!", PlayerName(playerid), PlayerName(id), id, level);
SendClientMessageToAll(0xF5C70FFF, str);
AdminL[playerid] = level;
}
else SendClientMessage(playerid, 0xF50F35FF, "ERROR: You are not a level 5 admin!");
return 1;
}
CMD:ban(playerid,params[])
{
new
id,
str[128],
reason[74]
;
if(AdminL[playerid] >=3)
{
if(sscanf(params,"uS(No Reason)[78]", id, reason)) return SendClientMessage(playerid, yellow, "[Usage]"embed_grey "/ban [Part Of Name/ID] [Reason]");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid, red, "[ERROR]"embed_grey "That player is not connected");
format(str, sizeof(str),""embed_sw"[ADMIN]"embed_white"You are banned by admin "embed_blue"%s "embed_white"for: {ED136A}%s", PlayerName(playerid), reason);
SendClientMessage(id, white, str);
format(str, sizeof(str),""embed_sw"[ADMIN]"embed_white"You banned "embed_blue"%s "embed_white"for: {ED136A}%s", PlayerName(id), reason);
SendClientMessage(playerid, white, str);
format(str, sizeof(str),""embed_sw"[ADMIN]"embed_white"Admin "embed_blue"%s "embed_white"banned "embed_blue"%s "embed_white"for: {ED136A}%s",PlayerName(playerid),PlayerName(id), reason);
SendClientMessageToAll( white, str);
Ban(id);
Banned[id] = 1;
format(str, sizeof(str), "UPDATE `playerdata` SET `ban` = %d WHERE `User` = '%s'", Banned[id], PlayerName(id));
mysql_function_query(dbHandle,str,false,"","");
}
else SendClientMessage(playerid, 0xF50F35FF, "ERROR: You are not a level 3 admin!");
return 1;
}
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
return 1;
}
public OnPlayerEnterCheckpoint(playerid)
{
return 1;
}
public OnPlayerLeaveCheckpoint(playerid)
{
return 1;
}
public OnPlayerEnterRaceCheckpoint(playerid)
{
return 1;
}
public OnPlayerLeaveRaceCheckpoint(playerid)
{
return 1;
}
public OnRconCommand(cmd[])
{
return 1;
}
public OnPlayerRequestSpawn(playerid)
{
return 1;
}
public OnObjectMoved(objectid)
{
return 1;
}
public OnPlayerObjectMoved(playerid, objectid)
{
return 1;
}
public OnPlayerPickUpPickup(playerid, pickupid)
{
return 1;
}
public OnVehicleMod(playerid, vehicleid, componentid)
{
return 1;
}
public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
return 1;
}
public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
return 1;
}
public OnPlayerSelectedMenuRow(playerid, row)
{
return 1;
}
public OnPlayerExitedMenu(playerid)
{
return 1;
}
public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
return 1;
}
public OnRconLoginAttempt(ip[], password[], success)
{
return 1;
}
public OnPlayerUpdate(playerid)
{
return 1;
}
public OnPlayerStreamIn(playerid, forplayerid)
{
return 1;
}
public OnPlayerStreamOut(playerid, forplayerid)
{
return 1;
}
public OnVehicleStreamIn(vehicleid, forplayerid)
{
return 1;
}
public OnVehicleStreamOut(vehicleid, forplayerid)
{
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == 15000)
{
if(response)
{
if(!strlen(inputtext) || strlen(inputtext) > 100)
{
new string[150],pName[MAX_PLAYER_NAME];
GetPlayerName(playerid,pName,sizeof(pName));
format(string, sizeof(string), "{FFFFFF}Welcome "COL_BLUE"%s(%d){FFFFFF} to the server, you're "COL_RED"not{FFFFFF} registered\n\nPlease log in by inputting your password.", pName, playerid);
SendClientMessage(playerid, 0xFF0000, "{ED478A}[INFO]{FFFFFF}You must insert a password between 1-100 characters!");
ShowPlayerDialog(playerid, 15000, DIALOG_STYLE_INPUT, "{FFFFFF}Register",string,"Register","Cancel");
}
else if(strlen(inputtext) > 0 && strlen(inputtext) < 100)
{
new escpass[100];
mysql_real_escape_string(inputtext, escpass);
MySQL_Register(playerid, escpass);
}
}
if(!response)
{
new string[150],pName[MAX_PLAYER_NAME];
GetPlayerName(playerid,pName,sizeof(pName));
format(string, sizeof(string), "{FFFFFF}Welcome "COL_BLUE"%s(%d){FFFFFF} to the server, you're "COL_RED"not{FFFFFF} registered\n\nPlease log in by inputting your password.", pName, playerid);
SendClientMessage(playerid, 0xFF0000, "{ED478A}[INFO]{FFFFFF}You must register before logging in!");
ShowPlayerDialog(playerid, 15000, DIALOG_STYLE_INPUT, "{FFFFFF}Register",string,"Register","Cancel");
}
}
if(dialogid == 15500)
{
if(!response)
{
new string[120],pName[MAX_PLAYER_NAME];
GetPlayerName(playerid,pName,sizeof(pName));
SendClientMessage(playerid, 0xFF0000, "{ED478A}[INFO]{FFFFFF}You must login before you spawn!");
format(string, sizeof(string), "{FFFFFF}Welcome "COL_BLUE"%s(%d){FFFFFF} to the server, you're registered\n\nPlease log in by inputting your password.", pName, playerid);
ShowPlayerDialog(playerid, 15500, DIALOG_STYLE_INPUT, "{FFFFFF}Login",string,"Login","Cancel");
}
if(response)
{
new query[200], pName[MAX_PLAYER_NAME], escapepass[100];
GetPlayerName(playerid, pName, sizeof(pName));
mysql_real_escape_string(inputtext, escapepass);
format(query, sizeof(query), "SELECT `user` FROM playerdata WHERE user = '%s' AND password = SHA1('%s')", pName, escapepass);
mysql_function_query(dbHandle,query,false,"","");
mysql_store_result();
new numrows = mysql_num_rows();
if(numrows == 1) MySQL_Login(playerid);
if(!numrows)
{
new string[120];
format(string, sizeof(string), "{FFFFFF}Welcome "COL_BLUE"%s(%d){FFFFFF} to the server, you're registered\n\nPlease log in by inputting the correct password.", pName, playerid);
ShowPlayerDialog(playerid, 15500, DIALOG_STYLE_INPUT, "Login",string,"Login","Cancel"); //Shows our login dialog :).
SendClientMessage(playerid, 0xFF0000, "{ED478A}[INFO]{FFFFFF}Incorrect password!"); //Sends the client a error message
}
mysql_free_result();
}
}
return 1;
}
public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
return 1;
}
stock MySQL_Register(playerid, passwordstring[])
{
new query[200], pname[24], IP[16];
GetPlayerName(playerid, pname, 24);
GetPlayerIp(playerid, IP, 16);
format(query, sizeof(query), "INSERT INTO playerdata (user, password, score, money, IP, level, ban, kills, deaths) VALUES('%s', SHA1('%s'), 0, 0, '%s', 0, 0, 0, 0)", pname, passwordstring, IP);
mysql_function_query(dbHandle,query,false,"","");
SendClientMessage(playerid, -1, "{ED478A}[INFO]{FFFFFF}You have been registered on this server!");
Logged[playerid] = 1;
return 1;
}
stock MySQL_Login(playerid)
{
new query[300], pname[24], savingstring[20];
GetPlayerName(playerid, pname, 24);
format(query, sizeof(query), "SELECT * FROM playerdata WHERE user = '%s'", pname);
mysql_function_query(dbHandle,query,false,"","");
mysql_store_result();
while(mysql_fetch_row_format(query,"|"))
{
mysql_fetch_field_row(savingstring, "score"); SetPlayerScore(playerid, strval(savingstring));
mysql_fetch_field_row(savingstring, "money"); MoneyGiven[playerid] = strval(savingstring);
mysql_fetch_field_row(savingstring, "level"); AdminL[playerid] = strval(savingstring);
mysql_fetch_field_row(savingstring, "ban"); Banned[playerid] = strval(savingstring);
mysql_fetch_field_row(savingstring, "kills"); Kills[playerid] = strval(savingstring);
mysql_fetch_field_row(savingstring, "deaths"); Deaths[playerid] = strval(savingstring);
}
mysql_free_result();
SendClientMessage(playerid, -1, "{ED478A}[INFO]{FFFFFF}You have been logged in!");
Logged[playerid] = 1;
if(Banned[playerid] == 1)
{
SendClientMessage(playerid, -1, "{ED478A}[ANTI-CHEAT]{FFFFFF}You have been already banned!");
Kick(playerid);
}
return 1;
}
stock PlayerName(playerid)
{
GetPlayerName(playerid, Pname, 24);
return Pname;
}