Dialog doesn't show
#1

Hey guys I am trying to make a register / login mysql script work but the problem is that it doesn't want to show the register dialog. I can just click spawn and it will bypass everything. I think the problem is about wehre I putted the dialog code but I'm not sure.

This is my code:
Код:
#include <a_samp>
#include <a_mysql>
//==============================================================================
//Password Hashing
native WP_Hash(buffer[], len, const str[]);
//==============================================================================
#define MYSQL_DATABASE "sawr"
#define MYSQL_HOST "127.0.0.1"
#define MYSQL_USER "root"
#define MYSQL_PASSWORD ""

#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2

#define COL_WHITE "{FFFFFF}"
#define COL_RED "{F81414}"
#define COL_GREEN "{00FF22}"
#define COL_LIGHTBLUE "{00CED1}"

#define COLOR_YELLOW 	0xFFFF00AA
#define COLOR_WHITE 	0xFFFFFFAA
#define COLOR_RED 		0xAA3333AA
//==============================================================================
new mysql;
new Text:Intro[12];

new bool:IntroScreen = true;
//==============================================================================
forward ShowIntro(playerid);
forward EndIntro(playerid);
forward InvalidRoleplayName(playerid);
forward ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5);
//==============================================================================
stock strreplace(string[], find, replace)
{
    for(new i=0; string[i]; i++)
    {
        if(string[i] == find)
        {
            string[i] = replace;
        }
    }
}
//==============================================================================
stock GetName(playerid)
{
    new Name[MAX_PLAYER_NAME];
    if(IsPlayerConnected(playerid))
    {
		GetPlayerName(playerid, Name, sizeof(Name));
    	strreplace(Name, '_', ' ');
	}
	return Name;
}
//==============================================================================
stock ContainsValidCharacters(string[])
{
    if (
	(strfind(string, "[") != -1) ||
	(strfind(string, "]") != -1) ||
	(strfind(string, "/") != -1) ||
	(strfind(string, "\\") != -1) ||
	(strfind(string, ":") != -1) ||
	(strfind(string, "*") != -1) ||
	(strfind(string, "?") != -1) ||
	(strfind(string, "<") != -1) ||
	(strfind(string, ">") != -1) ||
	(strfind(string, "|") != -1) ||
	(strfind(string, "\"") != -1) )
	    return 0;
	return 1;
}
//==============================================================================
enum
{
    LoginDialog,
    RegisterDialog
};

enum PlayerData
{
    ID,
    Name[MAX_PLAYER_NAME],
    Password[129],
    IP[16],
    Admin,
    VIP,
    Money,
    Float:PosX,
    Float:PosY,
    Float:PosZ,
    Float:PosA
};
new Player[MAX_PLAYERS][PlayerData];
//==============================================================================
main()
{
	print("\n----------------------------------");
	print(" SA:WR Roleplay Scripted by Daniel");
	print(" Version 1.0.0");
	print("----------------------------------\n");
}
//==============================================================================
public OnGameModeInit()
{
    {
    Intro[0] = TextDrawCreate(642.0, 1.0, "~n~");
    TextDrawLetterSize(Intro[0], 0.5, 49.5);
    TextDrawUseBox(Intro[0], 1);
    TextDrawBoxColor(Intro[0], 0x000000FF);
    TextDrawTextSize(Intro[0], -2.0, 0.0);

    Intro[1] = TextDrawCreate(140.000000, 190.000000, "~p~~h~San Andreas");
    TextDrawFont(Intro[1], 2);
    TextDrawLetterSize(Intro[1], 0.570000, 1.799999);

    Intro[2] = TextDrawCreate(305.000000, 190.000000, "West Roleplay");
    TextDrawFont(Intro[2], 2);
    TextDrawColor(Intro[2], 0xFFFFFF22);
    TextDrawLetterSize(Intro[2], 0.570000, 1.799999);

    Intro[3] = TextDrawCreate(305.000000, 190.000000, "West Roleplay");
    TextDrawFont(Intro[3], 2);
    TextDrawColor(Intro[3], 0xFFFFFF44);
    TextDrawLetterSize(Intro[3], 0.570000, 1.799999);

    Intro[4] = TextDrawCreate(305.000000, 190.000000, "West Roleplay");
    TextDrawFont(Intro[4], 2);
    TextDrawColor(Intro[4], 0xFFFFFF66);
    TextDrawLetterSize(Intro[4], 0.570000, 1.799999);

    Intro[5] = TextDrawCreate(305.000000, 190.000000, "West Roleplay");
    TextDrawFont(Intro[5], 2);
    TextDrawColor(Intro[5], 0xFFFFFF88);
    TextDrawLetterSize(Intro[5], 0.570000, 1.799999);

    Intro[6] = TextDrawCreate(305.000000, 190.000000, "West Roleplay");
    TextDrawFont(Intro[6], 2);
    TextDrawColor(Intro[6], 0xFFFFFFAA);
    TextDrawLetterSize(Intro[6], 0.570000, 1.799999);

    Intro[7] = TextDrawCreate(305.000000, 190.000000, "West Roleplay");
    TextDrawFont(Intro[7], 2);
    TextDrawColor(Intro[7], 0xFFFFFFCC);
    TextDrawLetterSize(Intro[7], 0.570000, 1.799999);

    Intro[8] = TextDrawCreate(305.000000, 190.000000, "West Roleplay");
    TextDrawFont(Intro[8], 2);
    TextDrawColor(Intro[8], 0xFFFFFFFF);
    TextDrawLetterSize(Intro[8], 0.570000, 1.799999);

    Intro[9] = TextDrawCreate(190.0, 202.0, ".");
    TextDrawFont(Intro[9], 1);
    TextDrawLetterSize(Intro[9], 23.250051, 1.099999);

    Intro[10] = TextDrawCreate(304.00, 223.0, "~y~~h~www.sawr.com");
    TextDrawFont(Intro[10], 2);
    TextDrawLetterSize(Intro[10], 0.340000, 1.099999);

    Intro[11] = TextDrawCreate(331.0, 235.0, "~g~~h~Enjoy the game!");
    TextDrawFont(Intro[11], 2);
    TextDrawLetterSize(Intro[11], 0.340000, 1.099999);
}
    mysql_log(LOG_ALL);
    mysql = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DATABASE, MYSQL_PASSWORD);
    if(mysql_errno() != 0)
    {
        printf("[MySQL] The connection has failed.");
    }
    else
    {
        printf("[MySQL] The connection was successful.");
    }
    
    UsePlayerPedAnims();
    ShowNameTags(1);
	SetGameModeText("SA:WR v1.0.0");
	AddPlayerClass(299, 1481.0868,-1769.9332,18.7958,1.5524, 0, 0, 0, 0, 0, 0);
    return true;
}
//==============================================================================
public ShowIntro(playerid)
{
        SetPVarInt(playerid, "Intro", GetPVarInt(playerid, "Intro") + 1);
        new iteration = GetPVarInt(playerid, "Intro");
        switch(iteration)
        {
            case 1:
            {
                for(new i; i < 11; i++)
                {
                    SendClientMessage(playerid, -1, "");
                }
                TextDrawShowForPlayer(playerid, Intro[0]);
            }
            case 2:
            {
                TextDrawShowForPlayer(playerid, Intro[1]);
            }
            case 3:
            {
        TextDrawShowForPlayer(playerid, Intro[2]);
            }
            case 4:
            {
                TextDrawHideForPlayer(playerid, Intro[2]);
                TextDrawShowForPlayer(playerid, Intro[3]);
            }
            case 5:
            {
                TextDrawHideForPlayer(playerid, Intro[3]);
                TextDrawShowForPlayer(playerid, Intro[4]);
            }
            case 6:
            {
                TextDrawHideForPlayer(playerid, Intro[4]);
                TextDrawShowForPlayer(playerid, Intro[5]);
            }
            case 7:
            {
                TextDrawHideForPlayer(playerid, Intro[5]);
                TextDrawShowForPlayer(playerid, Intro[6]);
            }
            case 8:
            {
                TextDrawHideForPlayer(playerid, Intro[6]);
                TextDrawShowForPlayer(playerid, Intro[7]);
            }
            case 9:
            {
                TextDrawHideForPlayer(playerid, Intro[7]);
                TextDrawShowForPlayer(playerid, Intro[8]);
            }
            case 10:
            {
                TextDrawShowForPlayer(playerid, Intro[9]);
            }
            case 11:
            {
                TextDrawShowForPlayer(playerid, Intro[10]);
            }
            case 12:
            {
                TextDrawShowForPlayer(playerid, Intro[11]);
            }
        }
        if(GetPVarInt(playerid, "Intro") < 10)
        {
        	SetTimerEx("ShowIntro", 300, 0, "d", playerid);
        }
        else if(9 < GetPVarInt(playerid, "Intro") < 13)
        {
        	SetTimerEx("ShowIntro", 2000, 0, "d", playerid);
        }
        else
        {
            for(new i; i < sizeof(Intro); i++)
            {
            	TextDrawHideForPlayer(playerid, Intro[i]);
            }
            TogglePlayerSpectating(playerid, false);
            ForceClassSelection(playerid);
        }
        return 1;
}
//==============================================================================
public OnGameModeExit()
{
	for(new i; i < sizeof(Intro); i++)
 	{
  		TextDrawDestroy(Intro[i]);
    }
    return 1;
}
//==============================================================================
public OnPlayerRequestClass(playerid, classid)
{
	SetPlayerPos(playerid, 1481.0868,-1769.9332,18.7958);
	SetPlayerFacingAngle(playerid, 0);
	SetPlayerCameraPos(playerid, 1480.9161,-1763.6292,18.7958);
	SetPlayerCameraLookAt(playerid, 1481.0868,-1769.9332,18.7958);
	return 1;
}
//==============================================================================
public OnPlayerConnect(playerid)
{
    SetPlayerColor (playerid, COLOR_WHITE);
	PlayAudioStreamForPlayer(playerid, "https://dl.dropboxusercontent.com/s/mwrm1hdebm4wdl3/GTA4%20Theme.mp3?token_hash=AAEqEhexu3r4E7aacZ9S35-UBV7BjNzk_SrzztMI15LoGg&dl=1");
 	TogglePlayerSpectating(playerid, true);
  	ForceClassSelection(playerid);
   	SetPVarInt(playerid, "Intro", 0);
    SetTimerEx("ShowIntro", 1000, 0, "d", playerid);
    SetTimerEx("EndIntro", 10000, 0, "d", playerid);
    return true;
}
//==============================================================================
public EndIntro(playerid)
{
    new query[128],
	playername[MAX_PLAYER_NAME];
	GetPlayerName(playerid, playername, sizeof(playername));
    mysql_format(mysql, query, sizeof(query), "SELECT `Password`, `ID` FROM `accounts` WHERE `Name` = '%e' LIMIT 1", playername);
    mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);

    new sendername[MAX_PLAYER_NAME];
	GetPlayerName(playerid, sendername, sizeof(sendername));
	new namestring = strfind(sendername, "_", true);
	if(namestring == -1)
	{
		SendClientMessage(playerid, COLOR_RED, "Please choose a roleplay name with the Firstname_Lastname format.");
		SetTimerEx("InvalidRoleplayName", 100, 0, "d", playerid);
		return 1;
	}
 	if(!ContainsValidCharacters(sendername))
	{
		SendClientMessage(playerid,COLOR_RED,"Please choose a roleplay name with the Firstname_Lastname format.");
		SetTimerEx("InvalidRoleplayName", 100, 0, "d", playerid);
		return 1;
	}
	return 1;
}
//==============================================================================
public InvalidRoleplayName(playerid)
{
	Kick(playerid);
	return 1;
}
//==============================================================================
forward OnAccountCheck(playerid);
public OnAccountCheck(playerid)
{
    new
        rows,
        fields;
    cache_get_data(rows, fields, mysql);

    if(rows)
    {
        TogglePlayerSpectating(playerid, true);
  		ForceClassSelection(playerid);
		new pname[MAX_PLAYER_NAME], string[128 + MAX_PLAYER_NAME];
   		GetPlayerName(playerid, pname, sizeof(pname));
   		strreplace(pname, '_', ' ');
   		format(string, sizeof(string), "Welcome back to San Andreas West Roleplay,{FFFFFF} %s!", pname);
   		SendClientMessage(playerid, COLOR_YELLOW, string);
     	cache_get_field_content(0, "Password", Player[playerid][Password], 1, 129);
        Player[playerid][ID] = cache_get_field_content_int(0, "ID");
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,""COL_WHITE"Login",""COL_WHITE"Welcome to San Andreas West Roleplay.\n That name is registered. Please enter your password below.\n","Login","Quit");
    }
    else
    {
        TogglePlayerSpectating(playerid, true);
  		ForceClassSelection(playerid);
		new pname[MAX_PLAYER_NAME], string[128 + MAX_PLAYER_NAME];
   		GetPlayerName(playerid, pname, sizeof(pname));
   		strreplace(pname, '_', ' ');
   		format(string, sizeof(string), "Welcome to San Andreas West Roleplay,{FFFFFF} %s!", pname);
   		SendClientMessage(playerid, COLOR_YELLOW, string);
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,""COL_WHITE"Register",""COL_WHITE"Type your password below to register a new account.","Register","Quit");
    }
    return true;
}
//==============================================================================
forward OnAccountLoad(playerid);
public OnAccountLoad(playerid)
{
	Player[playerid][Admin] = cache_get_field_content_int(0, "Admin");
	Player[playerid][VIP] = cache_get_field_content_int(0, "VIP");
	Player[playerid][Money] = cache_get_field_content_int(0, "Money");
	Player[playerid][PosX] = cache_get_field_content_float(0, "PosX");
	Player[playerid][PosY] = cache_get_field_content_float(0, "PosY");
	Player[playerid][PosZ] = cache_get_field_content_float(0, "PosZ");
	Player[playerid][PosA] = cache_get_field_content_float(0, "PosA");

	GivePlayerMoney(playerid, Player[playerid][Money]);
	SendClientMessage(playerid, -1, "You have successfully logged in.");
    return true;
}
//==============================================================================
forward OnAccountRegister(playerid);
public OnAccountRegister(playerid)
{
    Player[playerid][ID] = cache_insert_id();
    printf("[Registration] New account registered. Database ID: [%d]", Player[playerid][ID]);
    return true;
}
//==============================================================================
public OnPlayerSpawn(playerid)
{
	if(IntroScreen == true)
	{
    	StopAudioStreamForPlayer(playerid);
	}
	if(IntroScreen == false)
	{
	    SetPlayerHealth(playerid, 50);
	}
	return true;
}
//==============================================================================
public OnPlayerDisconnect(playerid, reason)
{
    new
        query[128],
        Float:pos[4];

    GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
    GetPlayerFacingAngle(playerid, pos[3]);

    mysql_format(mysql, query, sizeof(query), "UPDATE `accounts` SET `Money` = %d, `PosX` = %f, `PosY` = %f, `PosZ` = %f, `PosA` = %f WHERE `ID` = %d",
    GetPlayerMoney(playerid), pos[0], pos[1], pos[2], pos[3], Player[playerid][ID]);
    mysql_tquery(mysql, query, "", "");

    return true;
}
//==============================================================================
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case DIALOG_REGISTER:
        {
            TogglePlayerSpectating(playerid, true);
  			ForceClassSelection(playerid);
            if (!response) return Kick(playerid);
            if(response)
            {
	            new query[512],
             	playername[MAX_PLAYER_NAME],
              	playerip[16];
              	
	            GetPlayerName(playerid, playername, sizeof(playername));
	            GetPlayerIp(playerid, playerip, sizeof(playerip));
	            WP_Hash(Player[playerid][Password], 129, inputtext);
	            mysql_format(mysql, query, sizeof(query), "INSERT INTO `accounts` (`Name`, `Password`, `IP`, `Admin`, `VIP`, `Money`, `PosX`, `PosY`, `PosZ`, `PosA`) VALUES ('%e', '%e', '%e', 0, 0, 0, 0.0, 0.0, 0.0, 0.0)", playername, Player[playerid][Password], playerip);
	            mysql_tquery(mysql, query, "OnAccountRegister", "i", playerid);
	            
	            GivePlayerMoney(playerid, 10000);
	            SpawnPlayer(playerid);
            	new str[128];
				format(str, sizeof(str), "~w~Welcome~y~, %s!", GetName(playerid));
				GameTextForPlayer(playerid, str,4000,1);
            }
        }
        
        case DIALOG_LOGIN:
        {
            TogglePlayerSpectating(playerid, false);
  			ForceClassSelection(playerid);
            if ( !response ) return Kick ( playerid );
            if( response )
            {
            	new
                hashpass[129],
                query[100],
                playername[MAX_PLAYER_NAME];

	            GetPlayerName(playerid, playername, sizeof(playername));
	            WP_Hash(hashpass, sizeof(hashpass), inputtext);
	            if(!strcmp(hashpass, Player[playerid][Password]))
	            {
	                mysql_format(mysql, query, sizeof(query), "SELECT * FROM `accounts` WHERE `Name` = '%e' LIMIT 1", playername);
	                mysql_tquery(mysql, query, "OnAccountLoad", "i", playerid);
	                new str[128];
					format(str, sizeof(str), "~w~Welcome~y~, %s!", GetName(playerid));
					GameTextForPlayer(playerid, str,4000,1);
	            }
	            else
	            {
	                SendClientMessage(playerid, -1, "You have specified an incorrect password!");
	                ShowPlayerDialog(playerid, LoginDialog, DIALOG_STYLE_INPUT, "Login", "Welcome player!\nYour account has been found in our database. Please fill in your password:", "Login", "Quit");
	            }
			}
        }
    }
    return false;
}
//==============================================================================
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)