Jump to content

[Solved] How to check if inst is inventory has an item in inventory or if its inventory is empty


Recommended Posts

Hello, does someone know how I can check if inst has an item in their inventory or if their inventory is empty, if someone can help with that that'd be great, thanks for your time :wilson_dorky:!

Edited by SuperDavid
Link to comment
Share on other sites

17 hours ago, SuperDavid said:

Hello, does someone know how I can check if inst has an item in their inventory or if their inventory is empty, if someone can help with that that'd be great, thanks for your time :wilson_dorky:!

I know there's a few functions in the inventoryitem.lua components you can use to check your inventory. I don't have access to the files at the moment, but I would start there.

Link to comment
Share on other sites

Thanks for advice RedHairedHero :wilson_dorky:!

I looked and found "inst.components.inventoryitem:IsHeld()" though I don't know how to make it check if there's an item in inst is inventory or if that's what it does, I checked in inventory.lua and this didn't work either "not inst.components.inventory:NumItems(0)" so still need help from anyone smarter than me.

Link to comment
Share on other sites

Inventory is empty (doesn't check equip slots and backpack), when 

inst.components.inventory:NumItems() == 0

If you need to check equip slots and backpack:

#(inst.components.inventory:ReferenceAllItems()) == 0

If you want to check inventory for an item with specified prefab:

inst.components.inventory:Has("prefab", count)

For a specified item (inst is the item, owner is the inventory owner):

inst.components.inventoryitem:IsHeldBy(owner)

 

Edited by ksaab
fix
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...