Mess with dialog buttons
#1

Hi!


I have pretty much dialogs on my script...

But most of them are messed up with the buttons..



Code for them:


pawn Код:
ShowPlayerDialog(playerid, DIALOG_SELLBUY, DIALOG_STYLE_LIST, "Buy or sell something", "Sell\nBuy\t", "Ok", "Channel");
pawn Код:
if(dialogid == DIALOG_SELLBUY)
        {
            if(response)
            {
                ShowPlayerDialog(playerid, DIALOG_SELL, DIALOG_STYLE_LIST, "Sell something", "Meat\nOther\t", "Buy", "Close");
            }
            if(listitem == 1)
            {
             
            }
            if(listitem == 2)
            {
                //ShowPlayerDialog(playerid, DIALOG_SELL, DIALOG_STYLE_LIST, "Sell something", "Meat\nOther\t", "Buy", "Close");
            }
            return 1;
            }
           
        if(dialogid == DIALOG_SELL)
        {
            if(response) // Button 1
            {
                //OK button
            }
            if(listitem == 1)
            {
                //Close button
            }
            if(listitem == 2)
            {
                if(MeatRob[playerid] == 1)
                {
                GetPlayerMoney(playerid);
                GivePlayerMoney(playerid, 3000);
                SendClientMessage(playerid, Green, "You sold meet, you got 3000$!");
                MeatRob[playerid]=1;
                }
                else
                {
                    SendClientMessage(playerid, Green, "You don't have any meat");
                }
                return 1;
            }
            if(listitem == 3)
            {
                SendClientMessage(playerid, Green, "Should display the third altenative (Commands)");
            }
            return 1;
            }


pawn Код:
public meat (playerid)
{
    MeatRob[playerid]=1;
    SetPlayerWantedLevel(playerid, 3);
    GivePlayerMoney(playerid,5000);
    SendClientMessage(playerid, Green, "You successfully robbed 5000 and some meat");
}
And the script "sell meat" Won't work properly also that's why I posted
code for it also...
But I think it's because it messed up the buttons...


I have tired with putting the code in if(listitem == 2) or it 1 or 3

etc..

But it didn't wort neither...
Reply
#2

What do you mean "it won't work"?
Any compiler errors?
What happens ingame?
Have you tried to debug it?
Reply
#3

it always starts from 0.

Код:
if(listitem == 0)
            {
              
            }
            if(listitem == 1)
            {
                //ShowPlayerDialog(playerid, DIALOG_SELL, DIALOG_STYLE_LIST, "Sell something", "Meat\nOther\t", "Buy", "Close");
            }
Reply
#4

Be aware that listitem must start from "0" not "1".
Reply
#5

Use a switch, btw.
Reply
#6

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
Use a switch, btw.
Thanks alot guys!,
I'll try it.


Realcop: Do you mean instead of a variable ?.
Reply
#7

No... instead of doing this:

pawn Код:
if(..)
else if(..)
else if(..)
else if(..)
else
You can do this:

pawn Код:
switch(..)
case 0:
case 1:
case 2:
default:
https://sampwiki.blast.hk/wiki/Switch#switch
Reply
#8

pawn Код:
DIALOG_DIALOG:
{
    if(response)
    {
        switch(listitem)
        {
            case 0:
            {
                // code
            }
        }
    }
}
P.S: Try using that one above that I've given you, it'll work out easier and you'll be able to keep track of what's what.

EDIT: Or what RealCop has done.
Reply
#9

Sorry for bump but problem isn't fully solved yet..
And I were busy so I couldn't work with it but now I do..


Anyway:

I have a dialog but if you click the first item in the list it won't happen anything..
But all the others work...

Code:

pawn Код:
ShowPlayerDialog(playerid, DIALOG_HELP, DIALOG_STYLE_LIST, "Help", "Gameplay\nTurfs\nCommands\t", "Ok", "Close");
OnDialogResponse

pawn Код:
if(dialogid == DIALOG_HELP)
        {
            if(response) // Button 1
            {
               
            }
            if(listitem == 0)
            {
               
            }
            if (listitem == 1)
            {
                SendClientMessage(playerid, Green, "Test display, first should be first altenative(?)");
            }
            if(listitem == 2)
            {
                SendClientMessage(playerid, Green, "Test display, Secound(?)");
            }
            if(listitem == 3)
            {
                SendClientMessage(playerid, Green, "Test display turfs ?)");
            }
            return 1;
        }
        return 0;
    }

I have tired with I switch instead

(I knew what a switch were when I saw the function I just forgot the name...)

But if I use it, it will just show up:

Код:

D:\Davids\Scripting\Server Las Venturasmix\LV - Test.pwn(1584) : error 014: invalid statement; not in switch
D:\Davids\Scripting\Server Las Venturasmix\LV - Test.pwn(1584) : warning 215: expression has no effect
D:\Davids\Scripting\Server Las Venturas mix\LV - Test.pwn(1584) : error 001: expected token: ";", but found ":"
D:\Davids\Scripting\Server Las Venturasmix\LV - Test.pwn(1584) : error 029: invalid expression, assumed zero
D:\Davids\Scripting\Server Las Venturas mix\LV - Test.pwn(1584) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.

Code:

pawn Код:
case DIALOG_HELP:
                {
                    if(response) // Button 1
                    {
                        switch(listitem)
                       {
                        case 0:
                        {
                        SendClientMessage(playerid, Green, "Test display, first should be first altenative(?)");
                        }
                        case 1:
                        {
                        SendClientMessage(playerid, Green, "Test display, Secound(?)");
                        }
                        case 2:
                        {
                        SendClientMessage(playerid, Green, "Test display turfs ?)");
                        }
                        return 1;
                    }
                    return 0;
                }
Reply
#10

You don't use return inside of a switch.

pawn Код:
case DIALOG_HELP:
                {
                    if(response) // Button 1
                    {
                        switch(listitem)
                       {
                        case 0:
                        {
                        SendClientMessage(playerid, Green, "Test display, first should be first altenative(?)");
                        }
                        case 1:
                        {
                        SendClientMessage(playerid, Green, "Test display, Secound(?)");
                        }
                        case 2:
                        {
                        SendClientMessage(playerid, Green, "Test display turfs ?)");
                        }
                    }
                    return 0;
                }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)