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");
}
}
}
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(const string[]) { for (new i = 0, j = strlen(string); i < j; i++) { if (string[i] > '9' || string[i] < '0') return 0; } return 1; }
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(const string[]) { for (new i = 0, j = strlen(string); i < j; i++) { if (string[i] > '9' || string[i] < '0') return 0; } return 1; } |
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"); } } }
Код:
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"); } } } |
#if !defined isnull
#define isnull(%1) \
((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif
#define YOUR_SUPER_SECRET_CODE "1234567890"
if (dialogid == DIALOG_ACTIVATION)
{
if (!response) return Kick(playerid);
if (!isnull(inputtext))
{
if (!strcmp(inputtext, YOUR_SUPER_SECRET_CODE))
{
PlayerInfo[playerid][pActivated] = true;
return 1;
}
}
ShowPlayerDialog(playerid, DIALOG_ACTIVATION, DIALOG_STYLE_INPUT, "Oops! Something went wrong.", "You have entered an incorrect code. Please Try again.", "Activate", "Quit");
return 1;
}
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 код:
The code should look something like this: 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(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;
}
#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;
}
pawn Код:
|