Closed oOScuByOo closed 1 month ago
Hi,
You should be able to do that by overriding the can_hold_item
method of the ItemSlot
class and checking some item property in it. E.g.:
class_name MyItemSlot
extends ItemSlot
@export var slot_type: String
func can_hold_item(item: InventoryItem) -> bool:
return item.get_property("item_type") == slot_type
This seems to work, however I get the following errors in the console.
class_name ItemSlotExtended
extends ItemSlot
@export var slot_type: Array[String]
func can_hold_item(item: InventoryItem) -> bool:
return slot_type.any(check_allowable_item_types.bind(item))
func check_allowable_item_types(allowable_type:String,item:InventoryItem)->bool:
return item.get_property("item_type").contains(allowable_type)
The errors seem to happen if you inherit from ItemSlot
but don't declare your script as a @tool
script.
Most of the gloot scripts are declared as @tool
because they are also run in the editor. This make it possible to equip items in a slot from the editor, add items to inventories etc.
Therefore the example I listed above should be corrected to:
@tool
class_name MyItemSlot
extends ItemSlot
@export var slot_type: String
func can_hold_item(item: InventoryItem) -> bool:
return item.get_property("item_type") == slot_type
Hello there,
Thanks for your work Peter, it was awesome.
I'm currently looking for a way to add Item's type based slot, like any rpg, if item have the properties for exemple ItemType:String = Helmet, can only be equipped on item slot with property SlotType:String = Helmet.
Thanks for all =)