If Statement to check if item already in inventory?

Is there an easy way to do this? I only want one item in inventory, once they find the item in the game they will always have access to it. So when I have this line of code,

Code:
m_Inventory.AddItem("BlackNightie", 1);
is there an easy way in script to check that? Thanks!
 
I would recommend you enter the Inventory and the ItemCollection scripts and read all the functions available.
They are all commented. This will give you an idea of all the kind of functions you can call to add, remove, check, etc...

For your paricular case there is the HasItem(...) function

It might not have a overload to accept the item name. So you may need to first get the itemDefinition from the item name:

I hope that guides in in the right direction
 
Thanks, I was traveling all day yesterday to get back home and I will begin work on this next and try to figure it out. Just a quick attempt here,
Code:
if (hit.collider.gameObject.name == "AlliClubDressGRD")
{
    var ClubDress = InventorySystemManager.GetItemDefinition("ClubDress");
    var ClubDressCheck = InventorySystemManager.CreateItem(ClubDress);
    if (m_Inventory.HasItem((1, ClubDressCheck)));
    {
        m_Inventory.AddItem("ClubDress", 1);
    }
    ClubDressGRD.SetActive(false);
    RemoveOutfit();
    StartCoroutine(WearAfterDelay("ClubDress"));
    return;
}
Im getting a warning on the if (m_Inventory.HasItem((1, ClubDressCheck))); that its a possible mistaken tempty statement? Does that look ok?
 
Last edited:
Is your ClubDress itemcategory set as Unique?
If so that is incorrect. If the ItemActegory is set to unique your item will have a unique ID.
Such that you won't confuse ClubDress A with ClubDress B if you have many instances of theat ItemDefinition.

So instead of creating the item. Check check if the Inventory has that itemdefinition directly. I will check all items and see if one matches the definition.
I hope that makes sense. If not I recommend you read the docs again on the differences on ItemDefinition and Item
 
I just checked and yes its checked unique. Now how I set this up and maybe I have mis read something, I have an item definition and an item category of ClubDress. Should I seperate those names then? And this is a warning not an error and it just states that is a possible mistaken empty statement. But if I continue and add all 25 items to my game that will be 25 warnings so just testing one of the first in the alphabet basically. FYI changing ClubDress to ClubDressItem in the item definitions didnt make the warning go away sadly. Thought Id try.
 
What I ended up using. One example. Thanks for the help again.
Code:
if (hit.collider.gameObject.name == "PoliceUniformGRD")
{
    var PoliceUniformCheck = InventorySystemManager.GetItemDefinition("PoliceUniform");
    if (m_Inventory.HasItem((0, PoliceUniformCheck)))
    {
        m_Inventory.AddItem("PoliceUniform", 1);
    }
 
Top