Inventory dialog response
#1

So i made this: [it shows the correct list, i just need some ideas to make the dialog response work]

PHP Code:
CMD:inv(playeridparams[])
{
    new 
string[1000];
    new 
Pname[MAX_PLAYER_NAME];
    
slotsused[playerid]=0;
    for(new 
ii<41i++)
    {
    if(
PlayerItems[playerid][i] > 0)
    {
        
GetPlayerName(iPnameMAX_PLAYER_NAME);
        
format(stringsizeof(string), "{FFFFFF}%s\t%d\n%s"GetItemName(i), PlayerItems[playerid][i], string);
        
ShowPlayerDialog(playerid5024DIALOG_STYLE_TABLIST"Your Inventory"string"Okay","");
        
slotsused[playerid]++;
    }
    }
    if(
slotsused[playerid]==0) return ShowPlayerDialog(playerid5022DIALOG_STYLE_MSGBOX"Your Inventory""Your inventory is empty""Okay","");
    return 
1;

but i don't really know how to detect which item is 'slot' the player is choosing
PHP Code:
if(dialogid == 5024)
    {
        if(
response)
        {
        for(new 
islotsused[playerid]; i++)
        {
        if(
listitem == i)
        {
        
        }
        }
        }
    } 
Reply
#2

You should think about using an enum or defines for dialog IDs. It's gonna be a pain at some point to juggle with plain numbers. Also searching for a number will bring up duplicates at some point which won't happen with dialog names like "DIALOG_INVENTORY". But that just as a side note.

To detect the item the player clicked there are a few ways to do this.

You could include the Item Slot in the dialog text in the first position, which would then be assigned to "inputtext" from OnDialogResponse when the player selects an item.

So if you click a dialog row called "45\tBread\n", inputtext will contain "45" (it won't contain tabs or text after tabs). Convert this to a decimal using sscanf or strval and you have the slot ID the player clicked.

Alternatively you execute the same loop you used to generate the list, only this time you count down listitem instead of assembling the text. Once listitem is 0, the loop counter (i) will be at the slot the player clicked (this basically counts the number of valid items until the selection was found).

Your loop is close to it, but you need to add the check you did during show dialog (if the slot contains an item), and instead of comparing listitem to i, you subtract one and compare it with 0.
Reply
#3

Thanks for replying, I understood what you mean like adding slot number in the list names and then getting it with 'inputtext' at onplayerdialog response but i didn't quite get it how it's done, i have no idea how to use inputtext in list style dialogs can you please give a little example?
Reply
#4

For adding the slot to the dialog you can just format the number in your existing string (as first value):

Code:
format(string, sizeof(string), "%d\t{FFFFFF}%s\t%d\n%s", i, GetItemName(i), PlayerItems[playerid][i], string);
I added it before the color code, so it will be a bit darker (color codes are ignored in the response, so you can even color the slot differently if you want to).

For retrieving the ID, you can use sscanf.
So in OnDialogResponse you can do this:

Code:
new slot;
if(sscanf(inputtext, "i", slot) || slot < 0 || slot >= MAX_INVENTORY || PlayerItems[playerid][slot] <= 0)
{
// An invalid slot was passed, so don't continue. You could show the dialog again here.
// This can only happen if the data changed while the dialog was shown, or the dialog response was modified by the player. So it's important to verify the data here to avoid an invalid selection or array index out of bounds errors.
return 1;
}

// slot now contains the slot the player selected
I don't know the size of your inventory so I used MAX_INVENTORY as example. Change that to whatever your limit is.

You should still follow Y_Less' advice if possible. But I can see that it's a lot of work to change an underlying system if you already have a considerable amount of dialogs.

This is, at least in my opinion, still the easiest way of retrieving extra info from a dialog response the old school way. The only downside is that the number is visible in the dialog.
Reply
#5

Thanks for the help, i found another way to do it
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)