SA-MP Forums Archive
Help with dialogs (inputtext) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Help with dialogs (inputtext) (/showthread.php?tid=196327)



Help with dialogs (inputtext) - [NWA]Hannes - 05.12.2010

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;
}



Re: Help with dialogs (inputtext) - fangoth1 - 05.12.2010

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;
}



Re: Help with dialogs (inputtext) - Joe_ - 05.12.2010

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.


Re: Help with dialogs (inputtext) - [NWA]Hannes - 05.12.2010

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


Re: Help with dialogs (inputtext) - Joe_ - 05.12.2010

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