Inventory

The SD.Inventory module provides a comprehensive set of functionalities for inventory management across different frameworks, supporting operations like adding, removing, and checking items in player inventories. It is designed to be adaptable to multiple backend systems, including custom integrations like 'ox_inventory' and popular frameworks like 'ESX' and 'QB/QBX'.

Overview

Purpose: Facilitates the management of player inventory system, providing seamless integration with various inventory frameworks.

Inventory.HasItem

Purpose: Checks the quantity of a specific item in a player's inventory.

Parameters:

  • source (number): The player's server ID.

  • item (string): The item's name.

Returns:

  • (number): The quantity of the item present in the player's inventory.

Usage Example:

local itemCount = SD.Inventory.HasItem(source, 'water')
print(itemCount)

Inventory.AddItem

Purpose: Adds a specified quantity of an item to a player's inventory.

Parameters:

  • source (number): The player's server ID.

  • item (string): The item's name.

  • count (number): The quantity of the item to add.

  • slot (number|nil): The specific inventory slot to use, if applicable.

  • metadata (table|nil): Additional metadata for the item, if needed.

Usage Example:

SD.Inventory.AddItem(source, 'water', 10)

Inventory.RemoveItem

Purpose: Removes a specified quantity of an item from a player's inventory. Parameters:

  • source (number): The player's server ID.

  • item (string): The item's name.

  • count (number): The quantity of the item to remove.

  • slot (number|nil): The specific inventory slot to use, if applicable.

  • metadata (table|nil): Additional metadata for the item, if needed.

Usage Example:

SD.Inventory.RemoveItem(source, 'water', 5)

Inventory.AddWeapon

Purpose: Adds a weapon to a player's inventory along with specified ammunition. Parameters:

  • source (number): The player's server ID.

  • weapon (string): The weapon's name.

  • ammo (number): The amount of ammunition to add with the weapon.

Usage Example:

SD.Inventory.AddWeapon(source, 'pistol', 50)

Inventory.RegisterUsableItem

Purpose: Registers an item as usable within the game, associating it with a callback function that is triggered when the item is used. Parameters:

  • item (string): The item's name.

  • cb (function): The callback function to execute when the item is used.

Usage Example:

SD.Inventory.RegisterUsableItem('medkit', function(player)
    print('Medkit used by', player)
end)

Last updated