Skip to content

Inventory

Inventory helpers for registering inventory types, creating and loading inventory instances, managing persistent storage definitions, and opening inventory panels.


Overview

The inventory library centralizes shared inventory behavior under `lia.inventory`. It registers inventory type structures, creates inventory objects, loads and deletes server-side inventory records, manages storage and vehicle trunk definitions, handles overflow after size changes, and opens single or dual inventory interfaces on the client.

lia.inventory.newType(typeID, invTypeStruct)View Source

Purpose

Registers a new inventory type structure under `lia.inventory.types`.

Realm

Shared

Parameters

string typeID Unique identifier used to reference the inventory type.

table invTypeStruct Inventory type structure containing the required metatable fields and server methods.

Returns

Example Usage

  lia.inventory.newType("grid", inventoryType)

lia.inventory.new(typeID)View Source

Purpose

Creates a new inventory object from a registered inventory type without loading or assigning persistent storage.

Realm

Shared

Parameters

string typeID Identifier of the registered inventory type to instantiate.

Returns

table A new inventory object with copied configuration and an empty item table.

Example Usage

  local inventory = lia.inventory.new("grid")

lia.inventory.loadByID(id, noCache)View Source

Purpose

Loads an inventory by its persistent ID, using the cached instance unless `noCache` is enabled.

Realm

Server

Parameters

number id Persistent inventory ID to load.

boolean noCache optional Whether to bypass an existing cached inventory instance.

Returns

Deferred A deferred that resolves with the loaded inventory instance.

Example Usage

  lia.inventory.loadByID(invID):next(function(inventory)
      if inventory then inventory:sync(client) end
  end)

lia.inventory.loadFromDefaultStorage(id, noCache)View Source

Purpose

Loads an inventory from the default database tables and restores its saved data and items.

Realm

Server

Parameters

number id Persistent inventory ID to load.

boolean noCache optional Whether to bypass an existing cached inventory instance.

Returns

Deferred A deferred that resolves with the loaded inventory instance, or nil if no record exists.

Example Usage

  lia.inventory.loadFromDefaultStorage(invID, true):next(function(inventory)
      if inventory then inventory:onLoaded() end
  end)

lia.inventory.instance(typeID, initialData)View Source

Purpose

Creates and persists a new inventory instance of the given type.

Realm

Server

Parameters

string typeID Identifier of the registered inventory type to create.

table initialData optional Optional data table assigned to the new inventory instance.

Returns

Deferred A deferred that resolves with the newly created inventory instance.

Example Usage

  lia.inventory.instance("grid", {char = character:getID()}):next(function(inventory)
      character:setInv(inventory)
  end)

lia.inventory.loadAllFromCharID(charID)View Source

Purpose

Loads every inventory associated with a character ID.

Realm

Server

Parameters

number|string charID Character ID whose inventories should be loaded.

Returns

Deferred A deferred that resolves with the loaded inventory instances.

Example Usage

  lia.inventory.loadAllFromCharID(character:getID()):next(function(inventories)
      for _, inventory in pairs(inventories) do
          inventory:sync(client)
      end
  end)

lia.inventory.deleteByID(id)View Source

Purpose

Deletes an inventory and its related data from persistent storage, then destroys the cached instance if present.

Realm

Server

Parameters

number id Persistent inventory ID to delete.

Returns

Example Usage

  lia.inventory.deleteByID(invID)

lia.inventory.cleanUpForCharacter(character)View Source

Purpose

Destroys all inventory instances currently associated with a character.

Realm

Server

Parameters

Character character Character whose inventories should be cleaned up.

Returns

Example Usage

  lia.inventory.cleanUpForCharacter(character)

lia.inventory.checkOverflow(inv, character, oldW, oldH)View Source

Purpose

Removes items that no longer fit in an inventory and stores them as character overflow data.

Realm

Server

Parameters

table inv Inventory instance being checked for overflow.

Character character Character that owns the inventory.

number oldW Previous inventory width used for overflow metadata.

number oldH Previous inventory height used for overflow metadata.

Returns

boolean True if one or more items overflowed and were stored, otherwise false.

Example Usage

  if lia.inventory.checkOverflow(inventory, character, oldW, oldH) then
      client:notifyWarning("Some items no longer fit in your inventory.")
  end

lia.inventory.registerStorage(model, data)View Source

Purpose

Registers a world storage definition for a model.

Realm

Server

Parameters

string model Model path used as the storage lookup key.

table data Storage definition containing `name`, `invType`, and `invData`, with optional description data.

Returns

table The registered storage definition.

Example Usage

  lia.inventory.registerStorage("models/props_junk/wood_crate001a.mdl", {
      name = "Crate",
      invType = "grid",
      invData = {w = 4, h = 4}
  })

lia.inventory.getStorage(model)View Source

Purpose

Retrieves a registered storage definition by model.

Realm

Server

Parameters

string model Model path used to look up storage data.

Returns

table|nil The matching storage definition, or nil if none exists.

Example Usage

  local storage = lia.inventory.getStorage(entity:GetModel())

lia.inventory.registerTrunk(vehicleClass, data)View Source

Purpose

Registers a vehicle trunk storage definition for a vehicle class.

Realm

Server

Parameters

string vehicleClass Vehicle class used as the trunk lookup key.

table data Trunk definition containing `name`, `invType`, and `invData`, with optional description data.

Returns

table The registered trunk definition.

Example Usage

  lia.inventory.registerTrunk("prop_vehicle_jeep", {
      name = "Vehicle Trunk",
      invType = "grid",
      invData = {w = 6, h = 3}
  })

lia.inventory.getTrunk(vehicleClass)View Source

Purpose

Retrieves a registered vehicle trunk definition by vehicle class.

Realm

Server

Parameters

string vehicleClass Vehicle class used to look up trunk data.

Returns

table|nil The matching trunk definition, or nil if the class is not registered as a trunk.

Example Usage

  local trunk = lia.inventory.getTrunk(vehicle:GetClass())

lia.inventory.getAllTrunks()View Source

Purpose

Returns every registered vehicle trunk definition.

Realm

Server

Returns

table Table of registered trunk definitions keyed by their lowercase trunk keys.

Example Usage

  local trunks = lia.inventory.getAllTrunks()

lia.inventory.getAllStorage(includeTrunks)View Source

Purpose

Returns registered storage definitions, optionally excluding vehicle trunks.

Realm

Server

Parameters

boolean includeTrunks optional Set to false to return only non-trunk storage definitions.

Returns

table Registered storage definitions keyed by lowercase model or vehicle class.

Example Usage

  local storageOnly = lia.inventory.getAllStorage(false)

lia.inventory.show(inventory, parent)View Source

Purpose

Creates and opens a clientside panel for an inventory.

Realm

Client

Parameters

table inventory Inventory instance to display.

Panel parent optional Optional parent panel for the created inventory panel.

Returns

Panel The created inventory panel.

Example Usage

  local panel = lia.inventory.show(inventory)

lia.inventory.showDual(inventory1, inventory2, parent)View Source

Purpose

Opens two inventory panels side by side and links their close behavior.

Realm

Client

Parameters

table inventory1 First inventory instance to display.

table inventory2 Second inventory instance to display.

Panel parent optional Optional parent panel for the created inventory panels.

Returns

table|nil A table containing both created panels, or nil if panel creation fails.

Example Usage

  local panels = lia.inventory.showDual(characterInv, storageInv)

Hooks

Library-specific hooks documented for this library.


CreateInventoryPanel(inventory, parent)View Source

Purpose

Allows the clientside inventory interface to be created for a specific inventory.

Realm

Client

Parameters

table inventory The inventory instance that needs a panel.

Panel parent optional Optional parent panel for the created inventory panel.

Returns

Panel The created inventory panel.


InventoryClosed(panel, inventory)View Source

Purpose

Called when an inventory panel is removed or closed.

Realm

Client

Parameters

Panel panel The inventory panel that was closed.

table inventory The inventory instance that was displayed by the panel.

Returns


InventoryOpened(panel, inventory)View Source

Purpose

Called after an inventory panel has been created and opened.

Realm

Client

Parameters

Panel panel The inventory panel that was opened.

table inventory The inventory instance displayed by the panel.

Returns


OnCreateDualInventoryPanels(panel1, panel2, inventory1, inventory2)View Source

Purpose

Called after two inventory panels have been created and positioned for a dual-inventory view.

Realm

Client

Parameters

Panel panel1 The panel displaying the first inventory.

Panel panel2 The panel displaying the second inventory.

table inventory1 The first inventory instance.

table inventory2 The second inventory instance.

Returns