Case/Dialog identification issue
#1

Hi. I'm working on a dynamic dialog inventory system with a friend and we got stuck with something I'm not being able to solve.
When you type /inventory, you're supposed to get a list with the current items you're holding. It changes depending on the items. That's working fine.
However, if I have:
1. Cocaine
2. Hiking Bag
3. Marijuana
Number 1 and 2 work fine upon selection, but if I select item number 3, I'll get the option menu for Item 2, Hiking Bag.
I know what's wrong and why that's happening, but I have been breaking my back this weekend trying to go around it, but I haven't found a solution. Could anyone give me a hand with this?

http://pastebin.com/CXqwH58j

The problem starts at Line 74. I'm sure there is a better way to do what I'm trying to, but I wouldn't be posting here if I knew how to do it

Thanks for the attention and any help.
Reply
#2

Bump! Any ideas, please?
Reply
#3

Horrible indentation. I also have no idea what those while loops are doing there. I mean, what is this even?

PHP код:
if(PlayerInfo[playerid][pIHikingBag] >= 1)
{
    while(
PlayerInfo[playerid][pIAmphetamine] >= 1  || PlayerInfo[playerid][pIBackpack] >= || PlayerInfo[playerid][pICocaine] >= 1)
    {
        while(
PlayerInfo[playerid][pIBackpack] >= || PlayerInfo[playerid][pICocaine] >= 1)
        {
            return 
ShowPlayerDialog(playeridDIALOG_IHIKINGDIALOG_STYLE_LIST,""COL_WHITE"Hiking Bag""Use\nShow\nDrop""Select""Cancel"); // This is where my problem is, I know it's returning the Backpack twice, so it figures Hiking Bag is where it should be. I can't figure out how to go through this.
        
}
    }

A while loop within a while loop and both do jack shit.
Reply
#4

It's meant to check if the player has items on slot 1 or 2, in order for the "hiking bag menu" to show up at slot 3 of the item list.
It's working fine on case 0 and case 1, but when I get to case 2 it double checks "pIBackpack" because of the while loop (gives me the same result as case 1) and I know that's wrong. And that's where we can't figure out how to make it work.
We're looking at nxor trying to find out if that could be of any help but no success yet.
Reply
#5

Create an inventory array and than you could access the specific item without problems
This code only works if the order of the items is the same as in your inventory dialog
PHP код:
ShowItemDialog(playeriditem) {
    const
        
size 5
    
;
    if(
<= item size) {
        new
            
count,
            
inventory[size]
        ;
        if(
PlayerInfo[playerid][pIAmphetamine] >= 1inventory[count++] = 1;
        if(
PlayerInfo[playerid][pIBackpack] >= 1inventory[count++] = 2;
        if(
PlayerInfo[playerid][pICocaine] >= 1inventory[count++] = 3;
        if(
PlayerInfo[playerid][pIHikingBag] >= 1inventory[count++] = 4;
        if(
PlayerInfo[playerid][pIMarijuana] >= 1inventory[count++] = 5;
        static
            
info[] = "Use\nShow\nDrop",
            
button1[] = "Select",
            
button2[] = "Cancel"
        
;
        switch(
inventory[item]) {
            case 
1: return ShowPlayerDialog(playeridDIALOG_IAMPHETAMINEDIALOG_STYLE_LISTCOL_WHITE "Amphetamine Pill"infobutton1button2);
            case 
2: return ShowPlayerDialog(playeridDIALOG_IBACKPACKDIALOG_STYLE_LISTCOL_WHITE "Backpack"infobutton1button2);
            case 
3: return ShowPlayerDialog(playeridDIALOG_ICOCAINEDIALOG_STYLE_LISTCOL_WHITE "Ball of Cocaine"infobutton1button2);
            case 
4: return ShowPlayerDialog(playeridDIALOG_IHIKINGDIALOG_STYLE_LISTCOL_WHITE "Hiking Bag"infobutton1button2);
            case 
5: return ShowPlayerDialog(playeridDIALOG_IMARIJUANADIALOG_STYLE_LISTCOL_WHITE "Marijuana Cigarette"infobutton1button2);
        }
    }
    return 
false;

PHP код:
case DIALOG_INVENTORY:
{
    if(
response)
    {
        
ShowItemDialog(playeridlistitem);
    }

Reply
#6

It works! And it seems so easy haha
Thank you both for the attention and Nero for the code!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)