Dialog and inputtext
#1

So, I want players to enter a certain security code before being able to play. I got this working for now, however it only allows me to add one digit as a code. If I were to make it say a 10 digit code, how would I proceed?

pawn Код:
if(dialogid == DIALOG_ACTIVATION)
    {
        if(!response) return Kick(playerid);
        if(response)
        {
            if(inputtext[0] == '1')
            {
                PlayerInfo[playerid][pActivated] = 1;
            }
            else
            {
                ShowPlayerDialog(playerid, DIALOG_ACTIVATION, DIALOG_STYLE_INPUT, "Oops! Something went wrong.", "You have entered an incorrect code. Please Try again.", "Activate", "Quit");
            }
        }
    }
Reply
#2

You must use the strval and IsNumeric.
Код:
if(dialogid == DIALOG_ACTIVATION)
{
	if(!response) return Kick(playerid);
	if(!IsNumeric(inputtext)) return SendClientMessage(playerid, -1, "In this dialog you can only use numbers."); // Else, another message
	if(response)
	{
		if(strval(inputtext) == 1)
		{
			PlayerInfo[playerid][pActivated] = 1;
		}
		else
		{
			ShowPlayerDialog(playerid, DIALOG_ACTIVATION, DIALOG_STYLE_INPUT, "Oops! Something went wrong.", "You have entered an incorrect code. Please Try again.", "Activate", "Quit");
		}
	}
}
IsNumeric:
Код:
IsNumeric(const string[])
{
	for (new i = 0, j = strlen(string); i < j; i++)
	{
		if (string[i] > '9' || string[i] < '0') return 0;
	}
    return 1;
}
Reply
#3

Quote:
Originally Posted by Lunoxel
Посмотреть сообщение
You must use the strval and IsNumeric.
Код:
if(dialogid == DIALOG_ACTIVATION)
{
	if(!response) return Kick(playerid);
	if(!IsNumeric(inputtext)) return SendClientMessage(playerid, -1, "In this dialog you can only use numbers."); // Else, another message
	if(response)
	{
		if(strval(inputtext) == 1)
		{
			PlayerInfo[playerid][pActivated] = 1;
		}
		else
		{
			ShowPlayerDialog(playerid, DIALOG_ACTIVATION, DIALOG_STYLE_INPUT, "Oops! Something went wrong.", "You have entered an incorrect code. Please Try again.", "Activate", "Quit");
		}
	}
}
IsNumeric:
Код:
IsNumeric(const string[])
{
	for (new i = 0, j = strlen(string); i < j; i++)
	{
		if (string[i] > '9' || string[i] < '0') return 0;
	}
    return 1;
}
That didn't really work at all, now it doesn't matter what number I enter it will still activate the account even if I just make up any random number and enter it in the dialog.
Reply
#4

Код:
if(dialogid == DIALOG_ACTIVATION)
{
	if(!response) return Kick(playerid);
	if(!IsNumeric(inputtext)) return SendClientMessage(playerid, -1, "In this dialog you can only use numbers.");
        if(strval(inputtext) != 1) return SendClientMessage(playerid, -1, "......................" ); // ....
	if(response)
	{
		if(strval(inputtext) == 1)
		{
			PlayerInfo[playerid][pActivated] = 1;
		}
		else
		{
			ShowPlayerDialog(playerid, DIALOG_ACTIVATION, DIALOG_STYLE_INPUT, "Oops! Something went wrong.", "You have entered an incorrect code. Please Try again.", "Activate", "Quit");
		}
	}
}
Now go unless you write 1.. It`s ok?
Reply
#5

Quote:
Originally Posted by Lunoxel
Посмотреть сообщение
Код:
if(dialogid == DIALOG_ACTIVATION)
{
	if(!response) return Kick(playerid);
	if(!IsNumeric(inputtext)) return SendClientMessage(playerid, -1, "In this dialog you can only use numbers.");
        if(strval(inputtext) != 1) return SendClientMessage(playerid, -1, "......................" ); // ....
	if(response)
	{
		if(strval(inputtext) == 1)
		{
			PlayerInfo[playerid][pActivated] = 1;
		}
		else
		{
			ShowPlayerDialog(playerid, DIALOG_ACTIVATION, DIALOG_STYLE_INPUT, "Oops! Something went wrong.", "You have entered an incorrect code. Please Try again.", "Activate", "Quit");
		}
	}
}
Now go unless you write 1.. It`s ok?
I think you misunderstand me, I want the activation code to be a 10 digit numeric code. The scripts you have provided me still let me enter any random number and still it will activate said users account.
Reply
#6

Strcmp is used to compare two strings, however, you might first want to check if 'inputtext' is NULL, and if it has numeric characters only.
'isnull' from the zcmd include:
PHP код:
#if !defined isnull
    #define isnull(%1) \
                
((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif 
'IsNumeric' you have already been given.
The code should look something like this:
PHP код:
#define YOUR_SUPER_SECRET_CODE "1234567890"
if (dialogid == DIALOG_ACTIVATION)
{
    if (!
response) return Kick(playerid);
    if (!
isnull(inputtext))
    {
        if (!
strcmp(inputtextYOUR_SUPER_SECRET_CODE))
        {
            
PlayerInfo[playerid][pActivated] = true;
            return 
1;
        }
    }
    
ShowPlayerDialog(playeridDIALOG_ACTIVATIONDIALOG_STYLE_INPUT"Oops! Something went wrong.""You have entered an incorrect code. Please Try again.""Activate""Quit");
    return 
1;

Reply
#7

Quote:
Originally Posted by Virtual1ty
Посмотреть сообщение
Strcmp is used to compare two strings, however, you might first want to check if 'inputtext' is NULL, and if it has numeric characters only.
'isnull' from the zcmd include:
PHP код:
#if !defined isnull
    #define isnull(%1) \
                
((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif 
'IsNumeric' you have already been given.
The code should look something like this:
PHP код:
#define YOUR_SUPER_SECRET_CODE "1234567890"
if (dialogid == DIALOG_ACTIVATION)
{
    if (!
response) return Kick(playerid);
    if (!
isnull(inputtext))
    {
        if (!
strcmp(inputtextYOUR_SUPER_SECRET_CODE))
        {
            
PlayerInfo[playerid][pActivated] = true;
            return 
1;
        }
    }
    
ShowPlayerDialog(playeridDIALOG_ACTIVATIONDIALOG_STYLE_INPUT"Oops! Something went wrong.""You have entered an incorrect code. Please Try again.""Activate""Quit");
    return 
1;

Getting there, however now it won't activate even though I enter said code. Probably something small I have forgotten.

PHP код:
#if !defined isnull
    #define isnull(%1) \
                
((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif
#define ACTIVATION_CODE "1234567891"
if(dialogid == DIALOG_ACTIVATION)
    {
         if(!
response) return Kick(playerid);
         if(!
IsNumeric(inputtext))
         if (!
isnull(inputtext))
         if(
response)
         {
            if(!
strcmp(inputtextACTIVATION_CODE))
            {
                
PlayerInfo[playerid][pActivated] = 1;
                return 
1;
            }
        }
        
ShowPlayerDialog(playeridDIALOG_ACTIVATIONDIALOG_STYLE_INPUT"Oops! Something went wrong.""You have entered an incorrect activation code. Please Try again.""Activate""Quit");
        return 
1;
    } 
Reply
#8

pawn Код:
#define ACTIVATION_CODE "1234567891"

if(dialogid == DIALOG_ACTIVATION)
{
    if(!response) Kick(playerid);
    else
    {
        if(inputtext[0] && !strcmp(inputtext, ACTIVATION_CODE))
        {
            PlayerInfo[playerid][pActivated] = 1;
            return 1;
        }
        ShowPlayerDialog(playerid, DIALOG_ACTIVATION, DIALOG_STYLE_INPUT, "Oops! Something went wrong.", "You have entered an incorrect activation code. Please Try again.", "Activate", "Quit");
    }
    return 1;
}
Reply
#9

Quote:
Originally Posted by Jefff
Посмотреть сообщение
pawn Код:
#define ACTIVATION_CODE "1234567891"

if(dialogid == DIALOG_ACTIVATION)
{
    if(!response) Kick(playerid);
    else
    {
        if(inputtext[0] && !strcmp(inputtext, ACTIVATION_CODE))
        {
            PlayerInfo[playerid][pActivated] = 1;
            return 1;
        }
        ShowPlayerDialog(playerid, DIALOG_ACTIVATION, DIALOG_STYLE_INPUT, "Oops! Something went wrong.", "You have entered an incorrect activation code. Please Try again.", "Activate", "Quit");
    }
    return 1;
}
Now it detects the activation code and lets people spawn, but it fails to change the PlayerInfo[playerid][pActivated] to 1.
Reply
#10

Gonna bump this, still having issues with this.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)