Dialog list - Identify players selection?
#1

Hey guys.

I'm gonna make an inventory for the player, using a dialog list.

I havn't done it yet, and I'm going to bed in few minutes, but I'm not quite sure how to do this, so I figured I'd ask now and recieve some input here for tomorrow.

When the player types a command, such as /inventory, a list will appear with all his belongings. However, they will only appear if he has any of them - ie., it will not show on the list if you have 0.

So something like:

Code:
Bread - 3
Painkillers - 1
Bottle - 2
So, when the list is made and the player selects one - how do I detect which one he selected?

Here's an example - We have 5 items. A, B, C, D and E.

Player1 has A, B, C, D and E in his inventory:
Code:
A
B
C
D
E
Player2 has only C and E in his inventory.
Code:
C
E
Now, OnDialogResponse - how do I tell which one the player chose? Normally, you'd go for "listitem" - but since that's the number from the top, that doesn't help me. "listitem == 0" would be A for Player1, but C for Player2.

Do you see what I mean? How do I detect which item was selected?

Also, I assume the list would be made with a loop that edits a string, something like:
-Loop through all the players items
-Every time the player has an item, edit a string with "%s\n%s" where the first string is the previous string(the string itself) and the second string is whatever item, for example "Bottle - 1".
-Show the list with that string as the list options.

Correct me if the above method is wrong please.

Thanks for any help, if anyone even understand what I meant.
Reply
#2

There has been a few inventory/bag scripts out there searching will help.
Reply
#3

Quote:
Originally Posted by Retardedwolf
View Post
There has been a few inventory/bag scripts out there searching will help.
But I don't like stealing or copy-pasting.

I might learn a thing or two though, good point. But I think I did search for it, and I couldn't find anything relevant. Maybe I'm just tired.

Any help is still appreciated. I'd rather not use others work.
Reply
#4

Yeah, the ones I found are either includes or not helpful at all.

So, I got the looping through shit to make the list work out alright, I think.

I just need someone to tell me a way to identify the players selection.
Reply
#5

pawn Code:
PlayerInventItems[MAX_PLAYERS][128]; // 128 is the maximum items, change if needed.

//When creating the dialog
for(new items; items <= 128; items++) // Again, 128 being the maximim items, change if needed.
{
    if(/*Item variable...*/ > 0) {
        //Add item name to list
        PlayerInventItems[playerid][items] = 1;
    }
}

//Once the player has selected the item...
new count;
for(new items; items <= 128) items++) // Again, 128 being the maximim items, change if needed.
{
    if(PlayerInventItems[playerid][items] > 0) count++;
    if(count == listitem) {
        // Do your code...
        break;
    }
}
Reply
#6

Quote:
Originally Posted by Conroy
View Post
pawn Code:
PlayerInventItems[MAX_PLAYERS][128]; // 128 is the maximum items, change if needed.

//When creating the dialog
for(new items; items <= 128; items++) // Again, 128 being the maximim items, change if needed.
{
    if(/*Item variable...*/ > 0) {
        //Add item name to list
        PlayerInventItems[playerid][items] = 1;
    }
}

//Once the player has selected the item...
new count;
for(new items; items <= 128) items++) // Again, 128 being the maximim items, change if needed.
{
    if(PlayerInventItems[playerid][items] > 0) count++;
    if(count == listitem) {
        // Do your code...
        break;
    }
}
....

wat

EDIT: Okay I obviously didn't understand the point of your code, anyway. I just need to know: OnDialogResponse - how do I tell which listitem was selected, if the list is in-definate?
Reply
#7

Post the enum where you defined PlayerItems and I will help you get closer to the code you need. Conroy has posted a solution that should work, I understand you just need some help adapting it to your code.
Reply
#8

Quote:
Originally Posted by samgreen
View Post
Post the enum where you defined PlayerItems and I will help you get closer to the code you need. Conroy has posted a solution that should work, I understand you just need some help adapting it to your code.
pawn Code:
enum pItems
{
    Ham,
    Beans,
    Bread,
    Sausage,
    Crisps,
    Water,
    Soda,
    Juice,
    Beer,
    Vodka,
    Cloth,
    Bottle,
    Paper,
    MetalScrap,
    Timber,
    Wire,
    PainKillers,
    Bandage,
    SmallMedkit,
    MediumMedkit,
    LargeMedkit,
    IPSL,
    Antidote,
    AntiRad,
    Fuelcan,
    EmptyFuelcan,
    Radio,
    SRPS,
    Mask,
}
new PlayerItems[MAX_PLAYERS][pItems];
There you go. Please help :P
Reply
#9

Quote:
Originally Posted by Y_Less
View Post
Using a script publically released for public use, when used by you (a member of the public) is not stealing or copy-pasting, especially when that script is a full filterscript or include for example. Using existing code is the universally accepted way of writing things faster.
Have to agree with Y_Less on this. There really is no reason to reinvent the wheel here. Why not find an inventory filterscript that meets your standards, and spend your time programming features that you are really excited about?
Reply
#10

Quote:
Originally Posted by samgreen
View Post
Have to agree with Y_Less on this. There really is no reason to reinvent the wheel here. Why not find an inventory filterscript that meets your standards, and spend your time programming features that you are really excited about?
Because downloading an include that I just use for my system would mean that the script is not 100% mine. Someone else made a part of it.

I'm not re-inventing the wheel, I'm just making my own.

And I don't learn anything by downloading an include. Which is why I'm here, to learn.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)