OnPlayerDialog problems
#1

Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
new str[128];
format(str, sizeof str, "%d", response);
if(dialogid == 1 && response)
format(PlayerInfo[playerid][pAge], 128, str);
if(!strlen(str)) return SendClientMessage(playerid, COLOR_RED, "You must enter a numeric age 1 and 120 Ex: 56"); ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Please enter your characters age",str,"Continue","Cancel"); {}
if(strlen(str)) {
if(IsNumeric(str)) {
if(strval(str) <= 1 || strval(str) > 120)
TogglePlayerControllable(playerid,1); } }
else {
SendClientMessage(playerid, COLOR_RED, "You must enter a numeric age between 1 and 120 Ex: 56");
ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Please enter your characters age",str,"Continue","Cancel"); }
return 1;
}
For some reason the "Please enter your characters age" turns to 1 or 0 when i enter it and it bugs out


When I click continue it turns to 1 when i click cancel it turns to 0
Reply
#2

Код:
PlayerInfo[playerid][pAge] = strval(inputtext);
Reply
#3

What is the str string meant to show? Also try:

pawn Код:
format(str, sizeof str, "%d", inputtext);
Reply
#4

It's an input type dialog, which would return into the 'inputtext' variable (which is a string, not an integer).

Use this as it's a hell of a lot neater and your problem is fixed:

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == 1 && response)
    {
      new age = strval(inputtext);
        if(strlen(inputtext) < 1 && !IsNumeric(inputtext))
        {
            SendClientMessage(playerid, COLOR_RED, "You must enter a numeric string!");
            ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Please enter your characters age", "Please enter your characters' age!" , "Continue", "Cancel");
        }
        else
        {
          if(age < 120 || age >= 1)
          {
            new string[128];
            PlayerInfo[playerid][pAge] = age;
            format(string, sizeof(string), "Hooray! Your age has been set to %d!", age);
            SendClientMessage(playerid, COLOR_RED, string);
          }
          else
          {
                SendClientMessage(playerid, COLOR_RED, "You must enter an age, from between 1 to 120!");
                ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Please enter your characters age", "Please enter your characters' age!" , "Continue", "Cancel");
          }
        }
    }
    return 1;
}
Reply
#5

Thanks, I'm fairly new to scripting and I kept trying to get it to work thats why its so sloppy and fucked up.

How can I make it not allow text strings cause I can enter like "lol" and it will say I set my age to 0

I think this...
Код:
if(strlen(inputtext) < 1 && !IsNumeric(inputtext))
{
SendClientMessage(playerid, COLOR_RED, "You must enter a numeric age between 1 and 120 Ex: 56");
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Questionare", "Please enter your age", "Continue", "Cancel");
}
Was supposed to stop it but it didn't

My IsNumeric is this if its messed up
Код:
stock IsNumeric(string[])
{
	for (new i = 0, j = strlen(string); i < j; i++)
	{
		if (string[i] > '9' || string[i] < '0') return 0;
	}
	return 1;
}

Reply
#6

Quote:
Originally Posted by MisterTickle
Thanks, I'm fairly new to scripting and I kept trying to get it to work thats why its so sloppy and fucked up.

How can I make it not allow text strings cause I can enter like "lol" and it will say I set my age to 0

I think this...
Код:
if(strlen(inputtext) < 1 || !IsNumeric(inputtext))
{
SendClientMessage(playerid, COLOR_RED, "You must enter a numeric age between 1 and 120 Ex: 56");
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Questionare", "Please enter your age", "Continue", "Cancel");
}
Was supposed to stop it but it didn't

My IsNumeric is this if its messed up
Код:
stock IsNumeric(string[])
{
	for (new i = 0, j = strlen(string); i < j; i++)
	{
		if (string[i] > '9' || string[i] < '0') return 0;
	}
	return 1;
}

Код:
if(strlen(inputtext) < 1 || !IsNumeric(inputtext))
{
SendClientMessage(playerid, COLOR_RED, "You must enter a numeric age between 1 and 120 Ex: 56");
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Questionare", "Please enter your age", "Continue", "Cancel");
}
My bad. That'll work for ye'.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)