Forum rules - please read before posting.

Track number of items in inventory when interacting with a container

Hi, I need to limit the inventory items the player can carry. For this I have created a couple of action lists that count the items I take in and remove as described in this post:

https://adventurecreator.org/forum/discussion/4381/limited-inventory

Here is my action lists for reference
https://pasteboard.co/RcQhUuiDVgEZ.jpg

This works fine when I pick up items from scene hotspots but not when interacting with containers.

Is there any way I can call my take/drop action lists whenever I pick up or drop an item into a container?

Comments

  • There's a couple of ways you can achieve this.

    One is to rely on a custom script that overrides the default behaviour of the Inventory menu when placing items in from a Container. Such a script can be found on the AC wiki here:

    https://adventure-creator.fandom.com/wiki/Limited_Inventory

    The other way would be to rely on a Container - which can assigned a maximum capacity - for the Player's Inventory instead of the built-in inventory. To achieve this, attach a Container + Remember Container combo to the Player prefab, and then use the Container: Open Action's Open in set element? option to display its contents in your Inventory menu as the menu is turned on.

  • Hi, thank you for your reply.
    I have managed to get it working with the container method but I have found two problems.
    The first one is that when all the slots are occupied I can't keep adding items in the stackable slots that are incomplete.

    For example, in one of the slots I have 2 out of 4 possible carrots.
    When I have all 8 slots occupied, it doesn't let me complete the carrot slot with the two remaining carrots to reach the stackable limit.

    The other problem occurs when I select an item in the container that I use as inventory, I can't see it in an InventoryBox that I have configured as -Display Last Selected-.

    This is strange because if I set this InventoryBox to -Display Selected- it shows it while I have the item selected.

  • The first one is that when all the slots are occupied I can't keep adding items in the stackable slots that are incomplete.

    What is your AC version, and what Actions/settings are you using to add items? Any screenshots/steps you can share to help me recreate this will help me get to the bottom of this.

    The other problem occurs when I select an item in the container that I use as inventory, I can't see it in an InventoryBox that I have configured as -Display Last Selected-.

    "Display Last Selected" mode requires that the item be present in the Player's Inventory. Otherwise, it would be possible to display an item that the Player is no longer carrying.

    Did you try the other method, using the wiki script? That may be the better option, given your needs.

  • I have managed to get it work with the script :)
    I found something strange though.
    When I add stackable items from two different containers, they don't stack up and I can't stack them from the conainer menu inventory. However I can do it from the inventory menu.

    I'm using Unity 2021.3.4f1 and AC 1.75.3

    My settings:
    https://drive.google.com/file/d/18g6CqrEBXPQAk8WuP-pGfuH-M8ydCVIR/view?usp=share_link

  • The script overrides the handling of item combining. I've updated it on the wiki page to revert to the default behaviour in this instance.

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.