item.gd
Item object, contains info and data about item. Can be stored in inventory, loot or trader.
extends Control
class_name item
var ID : String # Item ID from items.json
var keys : Dictionary # JSON data from item.json
var OWNER # Where this item is stored now, parent Node
var instance_id = "" # System info for searching currently this item between items with same ID's
var equipped : bool = false # State if item in slot and equipped
var selected : bool = false # State when mouse over item (then selection frame will be shown)
var _is_wipe : bool = false # State for locked weapons that can't be unequipped, used when game saved to clear the inventory
@export var equipped_text : Label # Exposed in editor inspector cut-off debug text
@export var stack_text : Label # Exposed in editor inspector cut-off debug text
@export var icon : TextureRect # Icon
var stack : int = 1 # Current items amount (cutt-off functional)
var max_stack : int = 1 # Max same items amount (cutt-off functional)
var weight : float = 0.0 # Item weight (it will automatically load from items.json)
func UseItem() # Will use items (Same as player clicked on item by mouse)
func AddStack(value: int) # cut-off functional, adds stack and update text of stack
func SetStack(value: int) # cut-off functional, set stack and update text of stack
func MinusStack(value: int) # cut-off functional, decrease stack and update text of stack
func DeleteItem() # cut-off functional, if stack > 1 then just decrease by 1 else it will destroy item
func SelfDestroy() # Delete item from inventory
func _select_item(b: bool) # Make item selected (When mouse hover item)
func _equip_item(equipment_slot : slot) # Equip item to the slot (see Inventory.gd variables with slot_*)
func _add_parameter_bar(ParameterWindow, param, weapon_id="") # Used in item description for parameters from items.json in key "on_use" in progress bar shape
func _add_parameter(ParameterWindow,param,weapon_id="",type="standard") # Used in item description for parameters from items.json in key "on_use" in icon shape plus text
func _update_selection_texts() # Updates selected item text
func _clear_selection_texts() # Clears selected item text
Examples:
# Get item ID
var new_item : item
func _ready():
print(new_item.ID) # will return ID
# Get item keys dictionary
func _ready():
print(new_item.keys) # will return dictionary from items.json
print(new_item.keys["price"]) # will return item price
# Use item from code
func _ready():
new_item.UseItem()
# Delete item from inventory
func _ready():
new_item.SelfDestroy()
Keep in mind that item class object can be get only when adding to inventory!
# How to correctly get item info in game
# Firstly add item to player in any function
# option 1
func _ready():
# this function return item class at the end
GameManager.Gui.InventoryWindow.AddItem("medkit")
# it will get first item with this ID and return it as item class
GameManager.Gui.InventoryWindow.Find("medkit").UseItem()
# option 2
func _ready():
var item_med = GameManager.Gui.InventoryWindow.AddItem("medkit")
item_med.UseItem()
# option 3
func _ready():
GameManager.Gui.InventoryWindow.AddItem("medkit").UseItem()
Last updated