HasInventoryItem with amount of items?

Right now we are only having the predicate of if the specific item is in the Inventory. But what if we want to have a stackable item like for example chickens and want to check if we have 20 of those chickens (with the same ID to have them stackable) in the Inventory?

case "HasInventoryItem":
                return HasItem(InventoryItem.GetFromID(parameters[0]));

that’s what we have right now. But we somehow need to get the GetNumberInSlot function right? or is there a simple and easy solution for that?

Here’s my method for that:

                case EPredicate.HasItems: //Only works for stackable items.
                    InventoryItem item = InventoryItem.GetFromID(parameters[0]);
                    int stack = FindStack(item);
                    if (stack == -1) return false;
                    if (int.TryParse(parameters[1], out int result))
                    {
                        return slots[stack].number >= result;
                    }
                    return false;

Thank you Brian :slight_smile:

But where is this EPredicate comes from? and do I need that? Or is it possible to have it without?

LOL, oops, you don’t, unless you’re using my improved Condition property editor: Improving Conditions: A Property Editor
Just replace that with your string parameter, looks like in your case “HasInventoryItems”

Okai, so before making this work I need to actually implement your improved Condition property?

No, just change that case to

case "HasInventoryItem":

Okai so I think I got it right?

 switch (predicate)
            {
                case "HasInventoryItem":
                return HasItem(InventoryItem.GetFromID(parameters[0]));
                case "HasInventoryItems":
                InventoryItem item = InventoryItem.GetFromID(parameters[0]);
                    int stack = FindStack(item);
                    if (stack == -1) return false;
                    if (int.TryParse(parameters[1], out int result))
                    {
                        return slots[stack].number >= result;
                    }
                    return false;
            }
            return null;

But how do I set this up in the Dialogue right now? With HasInventoryItem and the right ID I can ask for the right Item but how do I make this correspond with the amount? Like I need to somewhere writte the amount of this specific item that should be In the Inventory right? Or do I simply need to make another AND statement and put in HasInventoryItems and instead of the ID the amount?

The Predicate will be HasInventoryItems
Make two parameters, one will be the itemID, the other will be the quantity required.

If you implement my Editor, the extra parameter is added automagically.

So I put in the itemID and a quantity of 3 but he is doing nothing. Even if I picked up 3 of the asked items. Am I so stupid and doing something super wrong here? :confused:

I see there is a second element to the And, but it’s collapsed, so I have no idea what it is. For testing, try it with only the HasInventoryItems predicate.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms