I'm working with the corgi-engine/inventory engine and need help with a script.

Here is what I’m trying to accomplish, I have an item pickup that should only be found once, so I want the script to check the player’s inventory to make sure the player doesn’t already have the item.

If the player has the item the item should disable itself.

Here is the script I have, but I can’t figure out why it’s not working. It doesn’t seem to be actually finding the player’s inventory, but as far as I can see everything is right. I’ve been reading documentation and trying it different ways for about 5 days now with no joy.

Any help would be greatly appreciated.

using System.Collections;
using System.Collections.Generic;
using MoreMountains.Tools;
using MoreMountains.InventoryEngine;
using UnityEngine;

namespace MoreMountains.CorgiEngine
{
    public class PlayerHasItemChecker : MonoBehaviour
    {

        [Header("ItemName")]
        /// the string that holds the name given in the inspector, used to check for the item in the inventory
        public string ItemCheckID;
        /// the method that should be triggered when the item is checked
        public List<int> _ItemList;

          public void Start()
        {
            CharacterInventory CurrentInventory = LevelManager.Instance.Players[0].GetComponent<CharacterInventory> ();

            if (CurrentInventory == null)
            {
                return;
            }

            _ItemList.Clear();
            _ItemList = CurrentInventory.MainInventory.InventoryContains("ItemCheckID");
            if (_ItemList.Count == 0)
            {
                return;
            }
            else
            {
                gameObject.SetActive(false);
            }





        }
        
    }
}

Thanks.

Hi,

ItemCheckID is a variable in the inspector, here you are passing a static string for your check:

_ItemList = CurrentInventory.MainInventory.InventoryContains(“ItemCheckID”);

It should be:

_ItemList = CurrentInventory.MainInventory.InventoryContains(ItemCheckID);

without double quotes.

In any case, instead using a string as item pointer (ItemCheckID), you could expect in the ispector directly the target InventoryItem (ScriptableObject) to pick.

For instance:

public InventoryItem myUniqueItem;

It encapsulates also the TargetInventory referece that you can use to easly check if your item is already in that target inventory.

For this, it should be enough to check the item quantity inside the inventory:

if (myUniqueItem.TargetInventory.GetQuantity(myUniqueItem.ItemID)==0)