Help with dialogs (inputtext)
#1

Im really a beginner with dialogs, i want that when you type "/answer" a input dialog pops up, and if you write "Hannes" you get $500, if you write something else you dont get any money, and if you press cancel you get a message.

I have this, and i can compile without errors, but when i try it in game nothing happens when i press cancel or submit

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(strcmp(cmdtext, "/answer", true)==0)
    {
        ShowPlayerDialog(playerid, 3275, DIALOG_STYLE_INPUT, "What is the correct answer?", "Write the answer below:", "Submit", "Cancel");
        return 1;
    }
    return 0;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    new string[7] = "Hannes";
    new str = strval(string);
   
    if(dialogid == 3275)
    {
        if(response)
        {
            if(inputtext[playerid] == str)
            {
                SendClientMessage(playerid, 0xFFFFFFFF, "You won $500!");
                GivePlayerMoney(playerid, 500);
            }
            else
            {
                SendClientMessage(playerid, 0xFFFFFFFF, "Wrong answer!");
            }
        }
        if(!response) return SendClientMessage(playerid, 0xFFFFFFFF, "You canceled!");
        return 1;
    }
    return 0;
}
Reply
#2

here try this
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(strcmp(cmdtext, "/answer", true)==0)
    {
        ShowPlayerDialog(playerid, 3275, DIALOG_STYLE_INPUT, "What is the correct answer?", "Write the answer below:", "Submit", "Cancel");
        return 1;
    }
    return 0;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{  
    if(dialogid == 3275)
    {
        if(response)
        {
            if(inputtext[playerid] == "Hannes")
            {
                SendClientMessage(playerid, 0xFFFFFFFF, "You won $500!");
                GivePlayerMoney(playerid, 500);
            }
            else
            {
                SendClientMessage(playerid, 0xFFFFFFFF, "Wrong answer!");
            }
        }
        if(!response) return SendClientMessage(playerid, 0xFFFFFFFF, "You canceled!");
        return 1;
    }
    return 0;
}
Reply
#3

Make sure all OnDialogResponse >CALLBACK< returns 0.

and use:

pawn Код:
if(!strcmp(inputtext, "Hannes", true))
{
//Do something if the input text was Hannes, it ignores case, so you can use hannes, HANNES, Hannes, HanNeS.
}
I don't know what fangoth was trying to do- but this should work.
Reply
#4

Quote:
Originally Posted by Joe_
Посмотреть сообщение
Make sure all OnDialogResponse >CALLBACK< returns 0.

and use:

pawn Код:
if(!strcmp(inputtext, "Hannes", true))
{
//Do something if the input text was Hannes, it ignores case, so you can use hannes, HANNES, Hannes, HanNeS.
}
I don't know what fangoth was trying to do- but this should work.
Thanks, this worked, but if i write nothing in (box is empty) and press submit it says i won
Reply
#5

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == 3275)
    {
        if(response)
        {
            if(!strcmp(inputtext, "hannes", true))
            {
                SendClientMessage(playerid, 0xFFFFFFFF, "You won $500!");
                GivePlayerMoney(playerid, 500);
                return 1;
            }
            SendClientMessage(playerid, 0xFFFFFFFF, "Wrong answer!");
            return 1;
        }
        return SendClientMessage(playerid, 0xFFFFFFFF, "Wrong answer!");
    }
    return 0;
}
That should work, you don't need to use 'else' in some cases, tidies up the code
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)