Forum rules - please read before posting.

Limited Player Inventory

Hello, I was wondering if there is a way to limit the player inventory through Adventure Creator? I would imagine there is a way to do this through scripting but I'm not very good at programming.

Thanks for your help!

Comments

  • edited May 2021
    Simplest way is to check the number of items the player is carrying, and prevent them picking something up when they’re at the limit. Set up as many inventory boxes as you need, then remove the scrolling arrow buttons (if you want to display everything with no scrolling)
    I can’t recall if you can check the number of total items carried through action lists, but if not, create a global variable and check that it is below a set limit (ie 10) with a check variable node, at the start of your action list that gives the player any items. Simply add 1 to it when picking something up with a set variable node at the end too.
    Then when removing an item, for whatever reason, be sure to add another set variable node into your action list and reduce it by 1.
    If you want to make it easier for yourself, set up an action list asset that you can reuse, and use parameters to add various items, remove item hotspots etc.
    That way you just create the one action list (or two I suppose since you’ll need one for removing items from the players inventory) and on a hotspot that gives an item, just run the action list asset using parameters - and change them for that particular item or whatever.
  • Thanks Mcdoll, I'll give that a try!

  • Hi Mcdoll, I'm having a hard time figuring out where to put the action lists, if I'm using a container and dragging and dropping items into the inventory I don't see where I would add the action list?

    Thanks again!

  • Mcdoll's approach is correct for the cases that you're adding Actions through gameplay interactions, i.e. the Inventory: Add or remove Action.

    In the case of menu interactions, such as transferring items from Containers, you need a custom script to override menu behaviour when the Player is carrying too many items.

    How this behaves exactly, though, depends on your interaction set up. Can you share your AC version, as well as screenshots of your Settings Manager, and the properties of the Container/InventoryBox elements you're working with?

  • Hello Chris, I'm using AC version 1.73.7. Here are some screenshots of the Settings manager and the inventory. Please let me know if you need anything else. Thanks very much for your help!

    https://ibb.co/NTNPHbS
    https://ibb.co/hyDPVzf
    https://ibb.co/vvYKTtv
    https://ibb.co/fCM9HT1
    https://ibb.co/gJcKVLN

  • Is this InventoryBox element the one that you're drag/dropping items into, or is that handled in the separate Container menu?

    If you're using the default Container menu, select the ContainerItems element and set its Click behaviour to Select Item Only. Then select the PlayerInventory element and set its Inventory box type to Custom Script.

    This script, added to the scene on an empty GameObject, should then let you limit how many items can be added to it:

    using UnityEngine;
    using AC;
    
    public class LimitItemsFromContainer : MonoBehaviour
    {
    
        public int maxItems = 5;
    
        private void OnEnable ()
        {
            EventManager.OnMenuElementClick += OnMenuElementClick;
        }
    
        private void OnDisable ()
        {
            EventManager.OnMenuElementClick -= OnMenuElementClick;
        }
    
        private void OnMenuElementClick (Menu menu, MenuElement element, int slot, int buttonPressed)
        {
            if (menu.title == "Container" && element.title == "PlayerInventory")
            {
                MenuInventoryBox inventoryBox = element as MenuInventoryBox;
                InvInstance selectedInstance = KickStarter.runtimeInventory.SelectedInstance;
                if (InvInstance.IsValid (selectedInstance))
                {
                    int numItems = KickStarter.runtimeInventory.PlayerInvCollection.GetCount ();
                    if (numItems < maxItems)
                    {
                        KickStarter.runtimeInventory.Add (selectedInstance);
                    }
                }
                else
                {
                    InvInstance clickedInstance = inventoryBox.GetInstance (slot);
                    if (InvInstance.IsValid (clickedInstance))
                    {
                        clickedInstance.Select ();
                    }
                }
            }
        }
    
    }
    
  • Thanks very much for this script :) I believe that I am using the default inventory and container menus. Does this script work for limiting the player's inventory amount or container inventory amount, or both? I will certainly give this script a try to today. Thanks!

    I like the idea of having a limited inventory or container storage. Sometimes with a limited inventory you can cause the player to make some interesting decisions. For example, the player is traveling to a far away land but can only take 5 items, what should they choose? Or a player reaches the end of the dungeon but realizes they can only carry out X amount of treasures and has to leave the rest. Which ones should they take? lol

  • The script limits how many items you can transfer from a Container. Containers themselves can be set a maximum capacity in their Inspectors.

  • Figured I’d ask here since it is pretty related - is there a way to check how many inventory slots have something in them, as opposed to the number of items carried - which I’m assuming, from playing around with it, includes stacked items.
    Idea is something like having, let’s say 10 slots, and if they’re full you can’t pick anything up - unless that thing is something you already have and is stackable - in which case you can pick up however many would max out the stack.

    I was playing around with action lists, but figured it’d be easier to script something in - I guess I just need to keep track of the number of filled inventory boxes because the rest of the functionality can be done with parameter overrides that would check that the item you are picking up is carried, stackable and less than the max count, then just adjust from there.
    Like if you were at max capacity except one of your items was peppermints, you had 15 and each stack could hold 20.
    If you tried to pick up a fish, you couldn’t, whereas if you tried to pick up eight peppermints you’d take 5 and either leave or waste the rest.

    I’ll start to tackle the idea tomorrow and share what I come up with if I succeed, but am interested to hear other’s thoughts!
  • If the InvCollection class's GetCount function is called with its "includeMultipleInSameSlot" parameter set to false, it'll return the number of filled slots - irrespective of how many items are actually in each slot.

    In hindsight, the above script should make use of that:

    int numItems = KickStarter.runtimeInventory.PlayerInvCollection.GetCount (false);
    
  • oh damn! you seriously thought of everything! Thanks a million - that's made it pretty trivial to keep track of inventory limitation stuff!

  • Sounds like a great addition. Will this be added to the AC wiki?

  • The AC wiki is for the community - you're welcome to add it.

  • Yeah I'll add it.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.