SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 28/03/2019, 01:42 PM   #1
SaiyanZ
Little Clucker
 
SaiyanZ's Avatar
 
Join Date: Nov 2015
Posts: 43
Reputation: 0
Default Inventory dialog response

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)
        {
        
        }
        }
        }
    } 
__________________

Last edited by SaiyanZ; 28/03/2019 at 02:13 PM.
SaiyanZ is offline   Reply With Quote
Old 28/03/2019, 02:16 PM   #2
NaS
High-roller
 
NaS's Avatar
 
Join Date: Mar 2008
Location: 🇩🇪
Posts: 1,652
Reputation: 559
Default Re: Inventory dialog response

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.
NaS is offline   Reply With Quote
Old 28/03/2019, 03:22 PM   #3
SaiyanZ
Little Clucker
 
SaiyanZ's Avatar
 
Join Date: Nov 2015
Posts: 43
Reputation: 0
Default Re: Inventory dialog response

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?
__________________
SaiyanZ is offline   Reply With Quote
Old 28/03/2019, 03:56 PM   #4
NaS
High-roller
 
NaS's Avatar
 
Join Date: Mar 2008
Location: 🇩🇪
Posts: 1,652
Reputation: 559
Default Re: Inventory dialog response

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 ******' 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.
NaS is offline   Reply With Quote
Old 28/03/2019, 05:33 PM   #5
SaiyanZ
Little Clucker
 
SaiyanZ's Avatar
 
Join Date: Nov 2015
Posts: 43
Reputation: 0
Default Re: Inventory dialog response

Thanks for the help, i found another way to do it
__________________
SaiyanZ is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help Me! Dialog No Response Langky Scripting Help 16 03/03/2017 02:54 PM
Dialog inventory Cepillado300 Scripting Help 2 02/05/2015 12:47 AM
response a dialog with another defined dialog gotwarzone Scripting Help 17 07/10/2013 08:57 PM
DIALOG Inventory Help Ciandlah Scripting Help 3 20/04/2013 09:29 AM
Dialog response not Sending Message [Input Dialog] Deal-or-die Scripting Help 8 08/05/2012 02:10 PM


All times are GMT. The time now is 03:35 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.