-
Notifications
You must be signed in to change notification settings - Fork 1
Game Inventories
Questie provides several inventories for storing items during gameplay:
-
Weighted Inventory: Allows players to add items from the
item databaseuntil the maximum weight capacity is reached. This inventory has infinite slots but is limited by the current weight of items (similar to the inventory system in Fallout). - Slot Based Inventory: Allows players to add items until a free slot is available. Each item occupies one slot, and if there are no available slots, the player must free up a slot before adding another item.
- Grid Inventory (Not yet ported): Similar to the slot-based inventory, but each slot has a maximum capacity (default 99) that must be reached before a new slot can be filled.
- Visual Grid Inventory (Not yet ported): Allows items to occupy one or more slots based on their size. If there is not enough space to accommodate an item, it will not be added to the inventory.
- Realistic Inventory: Has a limited capacity for each slot, allowing an infinite number of items to be added, but with several capacity limits. This inventory is called "realistic" because it mimics real life where the amount of items that can be carried is limited.
To add an inventory to your scene you follow these instructions:
- RMB on the root node /
CTRL+SHIFT+Awith root node selected - From the search panel type the inventory name (i.e., WeightedInventory, SlotInventory, ..., etc.)
- Select the inventory you want add
- Press
ok buttonor enter key on your keyboard
If all is done right, the inventory should be visible as sub-node of your root node.
All inventories are not providing any kind of interface. They contain only methods to store and remove items from the item database.
If you want to extend an inventory class to support any user interface, you can do it by using GDScript as follows:
class_name MyCustomInventory
extends WeightedInventory
# all variables and methods are inherited from the WeightedInventory class
export(Resource) var slot_template = preload("res://MyFolder/Slot.tscn")
# Override add_item function to support user interface update
func add_item(uuid, quantity: int = 1) -> void:
# Inherits from function declaration in parent class
.add_item(uuid, quantity)
# ... your code here ...
After you're done with your custom_inventory.gd, you can retrieve your custom node from the list using the same procedure as in the previous section, starting from step 2. Simply type the class_name (which is the same name you gave in the script) to retrieve your custom node.
When an item is added or removed from any inventory in Questie, certain events (signals in Godot) will be thrown, as shown below:
- push_item: called when an item is added to the inventory
- item_quantity_changed: called when an item quantity changes
- erase_item: called when an item is removed from the inventory
You can add functions to execute when these signals are emitted, as shown below:
# ... inside your class ...
func _enter_tree():
connect("push_item", self, "MyCallback")
func _exit_tree():
disconnect("push_item", self, "MyCallback")
# Will be called when push_item signal will be emitted
func MyCallback():
# ... you code here ...
If you want to emit these signals, use the following code:
# ... inside your class ...
func your_function():
emit_signal("push_item")
For further information about signals you can check the godot documentation
When working with the inventory, you can make changes to it during runtime using a set of common actions.
To access your inventory node from the scene hierarchy, you can use the following code: var inventory = get_parent().get_node(viewport_name)
Here, viewport_name should be replaced with the name of your inventory node.
To add an item to your inventory, use the following code: inventory.add_item(InventorySystem.weapons["Item Name"], 5)
The InventorySystem includes an item database, which organizes all items by category, such as weapons, armors, consumables, materials, and specials. You can add an item to your inventory by specifying its name and quantity.
Note: Make sure to add
InventorySystemto the scene as a subnode of the root node.
To remove an item from your inventory, use the following code: inventory.remove_item(Inventory.weapons["Item Name], 1)
This function is similar to the add_item function, but instead of adding an item, it removes a stored item from the inventory.
To remove all stored data from your inventory, use the following code: inventory.purge()
This function will delete all items currently stored in the inventory.
