Inventory Library
Comprehensive inventory system management with multiple storage types for the Lilia framework.
Overview
The inventory library provides comprehensive functionality for managing inventory systems in the Lilia framework. It handles inventory type registration, instance creation, storage management, and database persistence. The library operates on both server and client sides, with the server managing inventory data persistence, loading, and storage registration, while the client handles inventory panel display and user interaction. It supports multiple inventory types, storage containers, vehicle trunks, and character-based inventory management. The library ensures proper data validation, caching, and cleanup for optimal performance.
lia.inventory.newType
Purpose
Registers a new inventory type with the system
When Called
During module initialization or when defining custom inventory types
Returns
- None
Realm
Shared
Example Usage
Low Complexity:
```lua
-- Simple: Register a basic inventory type
lia.inventory.newType("player", {
className = "PlayerInventory",
typeID = "player",
config = {w = 10, h = 5}
})
**Medium Complexity:**
```lua
```lua
-- Medium: Register inventory type with custom methods
local playerInvType = {
className = "PlayerInventory",
typeID = "player",
config = {w = 10, h = 5},
add = function(self, item) -- custom add method
-- custom logic here
end
}
lia.inventory.newType("player", playerInvType)
**High Complexity:**
```lua
```lua
-- High: Register complex inventory type with validation
local complexInvType = {
className = "ComplexInventory",
typeID = "complex",
config = {
w = 20, h = 10,
maxWeight = 100,
restrictions = {"weapons", "drugs"}
},
add = function(self, item)
if self:canAddItem(item) then
return self:doAddItem(item)
end
return false
end,
remove = function(self, item)
return self:doRemoveItem(item)
end
}
lia.inventory.newType("complex", complexInvType)
---
### lia.inventory.new
**Purpose**
Creates a new inventory instance of the specified type
**When Called**
When creating inventory instances for players, storage containers, or vehicles
**Returns**
* Inventory instance (table) with items and config properties
**Realm**
Shared
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Create a basic player inventory
local playerInv = lia.inventory.new("player")
**Medium Complexity:**
```lua
```lua
-- Medium: Create inventory and configure it
local storageInv = lia.inventory.new("storage")
storageInv.config.w = 15
storageInv.config.h = 8
**High Complexity:**
```lua
```lua
-- High: Create inventory with custom configuration
local customInv = lia.inventory.new("player")
customInv.config.w = 12
customInv.config.h = 6
customInv.config.maxWeight = 50
customInv.items = {}
---
### lia.loadInventorySafely
**Purpose**
Loads an inventory instance by its ID from storage or cache
**When Called**
When accessing an existing inventory that may be cached or needs to be loaded from database
**Returns**
* Deferred promise that resolves to inventory instance
**Realm**
Server
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Load inventory by ID
lia.inventory.loadByID(123):next(function(inv)
print("Loaded inventory:", inv.id)
end)
**Medium Complexity:**
```lua
```lua
-- Medium: Load inventory with error handling
lia.inventory.loadByID(123):next(function(inv)
if inv then
print("Successfully loaded inventory:", inv.id)
end
end):catch(function(err)
print("Failed to load inventory:", err)
end)
**High Complexity:**
```lua
```lua
-- High: Load inventory with cache bypass and validation
local function loadInventorySafely(id)
return lia.inventory.loadByID(id, true):next(function(inv)
if not inv then
return deferred.reject("Inventory not found")
end
-- Validate inventory data
if not inv.data or not inv.items then
return deferred.reject("Invalid inventory data")
end
return inv
end)
end
---
### lia.inventory.loadByID
**Purpose**
Loads an inventory instance by its ID from storage or cache
**When Called**
When accessing an existing inventory that may be cached or needs to be loaded from database
**Returns**
* Deferred promise that resolves to inventory instance
**Realm**
Server
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Load inventory by ID
lia.inventory.loadByID(123):next(function(inv)
print("Loaded inventory:", inv.id)
end)
**Medium Complexity:**
```lua
```lua
-- Medium: Load inventory with error handling
lia.inventory.loadByID(123):next(function(inv)
if inv then
print("Successfully loaded inventory:", inv.id)
end
end):catch(function(err)
print("Failed to load inventory:", err)
end)
**High Complexity:**
```lua
```lua
-- High: Load inventory with cache bypass and validation
local function loadInventorySafely(id)
return lia.inventory.loadByID(id, true):next(function(inv)
if not inv then
return deferred.reject("Inventory not found")
end
-- Validate inventory data
if not inv.data or not inv.items then
return deferred.reject("Invalid inventory data")
end
return inv
end)
end
---
### lia.loadFromDatabase
**Purpose**
Loads an inventory from the default database storage system
**When Called**
When loadByID cannot find a custom loader and needs to use default storage
**Returns**
* Deferred promise that resolves to inventory instance
**Realm**
Server
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Load inventory from default storage
lia.inventory.loadFromDefaultStorage(123):next(function(inv)
print("Loaded from database:", inv.id)
end)
**Medium Complexity:**
```lua
```lua
-- Medium: Load with cache bypass
lia.inventory.loadFromDefaultStorage(123, true):next(function(inv)
if inv then
print("Fresh load from database:", inv.id)
end
end)
**High Complexity:**
```lua
```lua
-- High: Load with comprehensive error handling and validation
local function loadFromDatabase(id)
return lia.inventory.loadFromDefaultStorage(id, true):next(function(inv)
if not inv then
lia.error("Failed to load inventory " .. id .. " from database")
return deferred.reject("Inventory not found in database")
end
-- Validate inventory structure
if not inv.data or not inv.items then
lia.error("Invalid inventory structure for ID: " .. id)
return deferred.reject("Corrupted inventory data")
end
-- Log successful load
lia.log("Successfully loaded inventory " .. id .. " from database")
return inv
end):catch(function(err)
lia.error("Database load error for inventory " .. id .. ": " .. tostring(err))
return deferred.reject(err)
end)
end
---
### lia.inventory.loadFromDefaultStorage
**Purpose**
Loads an inventory from the default database storage system
**When Called**
When loadByID cannot find a custom loader and needs to use default storage
**Returns**
* Deferred promise that resolves to inventory instance
**Realm**
Server
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Load inventory from default storage
lia.inventory.loadFromDefaultStorage(123):next(function(inv)
print("Loaded from database:", inv.id)
end)
**Medium Complexity:**
```lua
```lua
-- Medium: Load with cache bypass
lia.inventory.loadFromDefaultStorage(123, true):next(function(inv)
if inv then
print("Fresh load from database:", inv.id)
end
end)
**High Complexity:**
```lua
```lua
-- High: Load with comprehensive error handling and validation
local function loadFromDatabase(id)
return lia.inventory.loadFromDefaultStorage(id, true):next(function(inv)
if not inv then
lia.error("Failed to load inventory " .. id .. " from database")
return deferred.reject("Inventory not found in database")
end
-- Validate inventory structure
if not inv.data or not inv.items then
lia.error("Invalid inventory structure for ID: " .. id)
return deferred.reject("Corrupted inventory data")
end
-- Log successful load
lia.log("Successfully loaded inventory " .. id .. " from database")
return inv
end):catch(function(err)
lia.error("Database load error for inventory " .. id .. ": " .. tostring(err))
return deferred.reject(err)
end)
end
---
### lia.createInventorySafely
**Purpose**
Creates a new inventory instance and initializes it in storage
**When Called**
When creating new inventories that need to be persisted to database
**Returns**
* Deferred promise that resolves to the created inventory instance
**Realm**
Server
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Create a new inventory instance
lia.inventory.instance("player"):next(function(inv)
print("Created inventory:", inv.id)
end)
**Medium Complexity:**
```lua
```lua
-- Medium: Create inventory with initial data
local initialData = {owner = "player123", maxWeight = 50}
lia.inventory.instance("storage", initialData):next(function(inv)
print("Created storage inventory:", inv.id)
print("Owner:", inv.data.owner)
end)
**High Complexity:**
```lua
```lua
-- High: Create inventory with validation and error handling
local function createInventorySafely(typeID, data)
if not lia.inventory.types[typeID] then
return deferred.reject("Invalid inventory type: " .. typeID)
end
return lia.inventory.instance(typeID, data):next(function(inv)
if not inv or not inv.id then
return deferred.reject("Failed to create inventory instance")
end
-- Validate created inventory
if not inv.data or not inv.items then
return deferred.reject("Invalid inventory structure")
end
lia.log("Successfully created inventory " .. inv.id .. " of type " .. typeID)
return inv
end):catch(function(err)
lia.error("Failed to create inventory: " .. tostring(err))
return deferred.reject(err)
end)
end
---
### lia.inventory.instance
**Purpose**
Creates a new inventory instance and initializes it in storage
**When Called**
When creating new inventories that need to be persisted to database
**Returns**
* Deferred promise that resolves to the created inventory instance
**Realm**
Server
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Create a new inventory instance
lia.inventory.instance("player"):next(function(inv)
print("Created inventory:", inv.id)
end)
**Medium Complexity:**
```lua
```lua
-- Medium: Create inventory with initial data
local initialData = {owner = "player123", maxWeight = 50}
lia.inventory.instance("storage", initialData):next(function(inv)
print("Created storage inventory:", inv.id)
print("Owner:", inv.data.owner)
end)
**High Complexity:**
```lua
```lua
-- High: Create inventory with validation and error handling
local function createInventorySafely(typeID, data)
if not lia.inventory.types[typeID] then
return deferred.reject("Invalid inventory type: " .. typeID)
end
return lia.inventory.instance(typeID, data):next(function(inv)
if not inv or not inv.id then
return deferred.reject("Failed to create inventory instance")
end
-- Validate created inventory
if not inv.data or not inv.items then
return deferred.reject("Invalid inventory structure")
end
lia.log("Successfully created inventory " .. inv.id .. " of type " .. typeID)
return inv
end):catch(function(err)
lia.error("Failed to create inventory: " .. tostring(err))
return deferred.reject(err)
end)
end
---
### lia.loadCharacterInventories
**Purpose**
Loads all inventories associated with a specific character ID
**When Called**
When a character logs in or when accessing all character inventories
**Returns**
* Deferred promise that resolves to array of inventory instances
**Realm**
Server
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Load all inventories for a character
lia.inventory.loadAllFromCharID(123):next(function(inventories)
print("Loaded", #inventories, "inventories")
end)
**Medium Complexity:**
```lua
```lua
-- Medium: Load inventories with error handling
lia.inventory.loadAllFromCharID(123):next(function(inventories)
if inventories and #inventories > 0 then
print("Successfully loaded", #inventories, "inventories")
for _, inv in ipairs(inventories) do
print("Inventory ID:", inv.id, "Type:", inv.data.invType)
end
end
end):catch(function(err)
print("Failed to load character inventories:", err)
end)
**High Complexity:**
```lua
```lua
-- High: Load inventories with validation and processing
local function loadCharacterInventories(charID)
return lia.inventory.loadAllFromCharID(charID):next(function(inventories)
if not inventories then
return deferred.reject("No inventories found for character " .. charID)
end
local validInventories = {}
for _, inv in ipairs(inventories) do
if inv and inv.id and inv.data then
-- Validate inventory structure
if inv.items and inv.config then
table.insert(validInventories, inv)
else
lia.warning("Invalid inventory structure for ID: " .. inv.id)
end
end
end
lia.log("Loaded " .. #validInventories .. " valid inventories for character " .. charID)
return validInventories
end):catch(function(err)
lia.error("Failed to load inventories for character " .. charID .. ": " .. tostring(err))
return deferred.reject(err)
end)
end
---
### lia.inventory.loadAllFromCharID
**Purpose**
Loads all inventories associated with a specific character ID
**When Called**
When a character logs in or when accessing all character inventories
**Returns**
* Deferred promise that resolves to array of inventory instances
**Realm**
Server
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Load all inventories for a character
lia.inventory.loadAllFromCharID(123):next(function(inventories)
print("Loaded", #inventories, "inventories")
end)
**Medium Complexity:**
```lua
```lua
-- Medium: Load inventories with error handling
lia.inventory.loadAllFromCharID(123):next(function(inventories)
if inventories and #inventories > 0 then
print("Successfully loaded", #inventories, "inventories")
for _, inv in ipairs(inventories) do
print("Inventory ID:", inv.id, "Type:", inv.data.invType)
end
end
end):catch(function(err)
print("Failed to load character inventories:", err)
end)
**High Complexity:**
```lua
```lua
-- High: Load inventories with validation and processing
local function loadCharacterInventories(charID)
return lia.inventory.loadAllFromCharID(charID):next(function(inventories)
if not inventories then
return deferred.reject("No inventories found for character " .. charID)
end
local validInventories = {}
for _, inv in ipairs(inventories) do
if inv and inv.id and inv.data then
-- Validate inventory structure
if inv.items and inv.config then
table.insert(validInventories, inv)
else
lia.warning("Invalid inventory structure for ID: " .. inv.id)
end
end
end
lia.log("Loaded " .. #validInventories .. " valid inventories for character " .. charID)
return validInventories
end):catch(function(err)
lia.error("Failed to load inventories for character " .. charID .. ": " .. tostring(err))
return deferred.reject(err)
end)
end
---
### lia.deleteInventory
**Purpose**
Permanently deletes an inventory and all its associated data from the database
**When Called**
When removing inventories that are no longer needed or during cleanup operations
**Returns**
* None
**Realm**
Server
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Delete an inventory by ID
lia.inventory.deleteByID(123)
**Medium Complexity:**
```lua
```lua
-- Medium: Delete inventory with validation
local function deleteInventory(id)
if not isnumber(id) or id <= 0 then
lia.error("Invalid inventory ID for deletion: " .. tostring(id))
return false
end
lia.inventory.deleteByID(id)
lia.log("Deleted inventory ID: " .. id)
return true
end
**High Complexity:**
```lua
```lua
-- High: Delete inventory with comprehensive cleanup
local function deleteInventorySafely(id)
if not isnumber(id) or id <= 0 then
return deferred.reject("Invalid inventory ID: " .. tostring(id))
end
-- Check if inventory exists before deletion
return lia.inventory.loadByID(id):next(function(inv)
if not inv then
lia.warning("Attempted to delete non-existent inventory: " .. id)
return false
end
-- Clean up any items in the inventory
if inv.items then
for _, item in pairs(inv.items) do
if item and item.destroy then
item:destroy()
end
end
end
-- Delete from database
lia.inventory.deleteByID(id)
lia.log("Successfully deleted inventory " .. id .. " and all associated data")
return true
end):catch(function(err)
lia.error("Failed to delete inventory " .. id .. ": " .. tostring(err))
return false
end)
end
---
### lia.deleteInventorySafely
**Purpose**
Permanently deletes an inventory and all its associated data from the database
**When Called**
When removing inventories that are no longer needed or during cleanup operations
**Returns**
* None
**Realm**
Server
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Delete an inventory by ID
lia.inventory.deleteByID(123)
**Medium Complexity:**
```lua
```lua
-- Medium: Delete inventory with validation
local function deleteInventory(id)
if not isnumber(id) or id <= 0 then
lia.error("Invalid inventory ID for deletion: " .. tostring(id))
return false
end
lia.inventory.deleteByID(id)
lia.log("Deleted inventory ID: " .. id)
return true
end
**High Complexity:**
```lua
```lua
-- High: Delete inventory with comprehensive cleanup
local function deleteInventorySafely(id)
if not isnumber(id) or id <= 0 then
return deferred.reject("Invalid inventory ID: " .. tostring(id))
end
-- Check if inventory exists before deletion
return lia.inventory.loadByID(id):next(function(inv)
if not inv then
lia.warning("Attempted to delete non-existent inventory: " .. id)
return false
end
-- Clean up any items in the inventory
if inv.items then
for _, item in pairs(inv.items) do
if item and item.destroy then
item:destroy()
end
end
end
-- Delete from database
lia.inventory.deleteByID(id)
lia.log("Successfully deleted inventory " .. id .. " and all associated data")
return true
end):catch(function(err)
lia.error("Failed to delete inventory " .. id .. ": " .. tostring(err))
return false
end)
end
---
### lia.inventory.deleteByID
**Purpose**
Permanently deletes an inventory and all its associated data from the database
**When Called**
When removing inventories that are no longer needed or during cleanup operations
**Returns**
* None
**Realm**
Server
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Delete an inventory by ID
lia.inventory.deleteByID(123)
**Medium Complexity:**
```lua
```lua
-- Medium: Delete inventory with validation
local function deleteInventory(id)
if not isnumber(id) or id <= 0 then
lia.error("Invalid inventory ID for deletion: " .. tostring(id))
return false
end
lia.inventory.deleteByID(id)
lia.log("Deleted inventory ID: " .. id)
return true
end
**High Complexity:**
```lua
```lua
-- High: Delete inventory with comprehensive cleanup
local function deleteInventorySafely(id)
if not isnumber(id) or id <= 0 then
return deferred.reject("Invalid inventory ID: " .. tostring(id))
end
-- Check if inventory exists before deletion
return lia.inventory.loadByID(id):next(function(inv)
if not inv then
lia.warning("Attempted to delete non-existent inventory: " .. id)
return false
end
-- Clean up any items in the inventory
if inv.items then
for _, item in pairs(inv.items) do
if item and item.destroy then
item:destroy()
end
end
end
-- Delete from database
lia.inventory.deleteByID(id)
lia.log("Successfully deleted inventory " .. id .. " and all associated data")
return true
end):catch(function(err)
lia.error("Failed to delete inventory " .. id .. ": " .. tostring(err))
return false
end)
end
---
### lia.cleanupCharacterInventories
**Purpose**
Destroys all inventory instances associated with a character
**When Called**
When a character is deleted or during character cleanup operations
**Returns**
* None
**Realm**
Server
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Clean up character inventories
lia.inventory.cleanUpForCharacter(character)
**Medium Complexity:**
```lua
```lua
-- Medium: Clean up with validation
local function cleanupCharacterInventories(character)
if not character or not character.getInv then
lia.error("Invalid character object for cleanup")
return false
end
lia.inventory.cleanUpForCharacter(character)
lia.log("Cleaned up inventories for character: " .. character:getName())
return true
end
**High Complexity:**
```lua
```lua
-- High: Clean up with comprehensive logging and validation
local function cleanupCharacterInventoriesSafely(character)
if not character or not character.getInv then
lia.error("Invalid character object for inventory cleanup")
return false
end
local inventories = character:getInv(true)
if not inventories or table.IsEmpty(inventories) then
lia.log("No inventories to clean up for character: " .. character:getName())
return true
end
local count = 0
for _, inv in pairs(inventories) do
if inv and inv.destroy then
inv:destroy()
count = count + 1
end
end
lia.log("Cleaned up " .. count .. " inventories for character: " .. character:getName())
return true
end
---
### lia.cleanupCharacterInventoriesSafely
**Purpose**
Destroys all inventory instances associated with a character
**When Called**
When a character is deleted or during character cleanup operations
**Returns**
* None
**Realm**
Server
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Clean up character inventories
lia.inventory.cleanUpForCharacter(character)
**Medium Complexity:**
```lua
```lua
-- Medium: Clean up with validation
local function cleanupCharacterInventories(character)
if not character or not character.getInv then
lia.error("Invalid character object for cleanup")
return false
end
lia.inventory.cleanUpForCharacter(character)
lia.log("Cleaned up inventories for character: " .. character:getName())
return true
end
**High Complexity:**
```lua
```lua
-- High: Clean up with comprehensive logging and validation
local function cleanupCharacterInventoriesSafely(character)
if not character or not character.getInv then
lia.error("Invalid character object for inventory cleanup")
return false
end
local inventories = character:getInv(true)
if not inventories or table.IsEmpty(inventories) then
lia.log("No inventories to clean up for character: " .. character:getName())
return true
end
local count = 0
for _, inv in pairs(inventories) do
if inv and inv.destroy then
inv:destroy()
count = count + 1
end
end
lia.log("Cleaned up " .. count .. " inventories for character: " .. character:getName())
return true
end
---
### lia.inventory.cleanUpForCharacter
**Purpose**
Destroys all inventory instances associated with a character
**When Called**
When a character is deleted or during character cleanup operations
**Returns**
* None
**Realm**
Server
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Clean up character inventories
lia.inventory.cleanUpForCharacter(character)
**Medium Complexity:**
```lua
```lua
-- Medium: Clean up with validation
local function cleanupCharacterInventories(character)
if not character or not character.getInv then
lia.error("Invalid character object for cleanup")
return false
end
lia.inventory.cleanUpForCharacter(character)
lia.log("Cleaned up inventories for character: " .. character:getName())
return true
end
**High Complexity:**
```lua
```lua
-- High: Clean up with comprehensive logging and validation
local function cleanupCharacterInventoriesSafely(character)
if not character or not character.getInv then
lia.error("Invalid character object for inventory cleanup")
return false
end
local inventories = character:getInv(true)
if not inventories or table.IsEmpty(inventories) then
lia.log("No inventories to clean up for character: " .. character:getName())
return true
end
local count = 0
for _, inv in pairs(inventories) do
if inv and inv.destroy then
inv:destroy()
count = count + 1
end
end
lia.log("Cleaned up " .. count .. " inventories for character: " .. character:getName())
return true
end
---
### lia.registerStorageContainers
**Purpose**
Registers a storage container model with inventory configuration
**When Called**
During module initialization to register storage containers like crates, lockers, etc.
**Returns**
* The registered storage data table
**Realm**
Server
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Register a basic storage container
lia.inventory.registerStorage("models/props_c17/lockers001a.mdl", {
name = "Locker",
invType = "storage",
invData = {w = 5, h = 3}
})
**Medium Complexity:**
```lua
```lua
-- Medium: Register storage with custom configuration
local storageData = {
name = "Medical Cabinet",
invType = "medical",
invData = {
w = 8,
h = 4,
maxWeight = 30,
restrictions = {"medical", "drugs"}
}
}
lia.inventory.registerStorage("models/props_c17/furnituremedicinecabinet001a.mdl", storageData)
**High Complexity:**
```lua
```lua
-- High: Register multiple storage types with validation
local function registerStorageContainers()
local storages = {
{
model = "models/props_c17/lockers001a.mdl",
data = {
name = "Security Locker",
invType = "security",
invData = {w = 6, h = 4, maxWeight = 50, restricted = true}
}
},
{
model = "models/props_c17/furnituremedicinecabinet001a.mdl",
data = {
name = "Medical Cabinet",
invType = "medical",
invData = {w = 8, h = 4, maxWeight = 30, medicalOnly = true}
}
}
}
for _, storage in ipairs(storages) do
if storage.model and storage.data then
lia.inventory.registerStorage(storage.model, storage.data)
lia.log("Registered storage: " .. storage.data.name)
end
end
end
---
### lia.inventory.registerStorage
**Purpose**
Registers a storage container model with inventory configuration
**When Called**
During module initialization to register storage containers like crates, lockers, etc.
**Returns**
* The registered storage data table
**Realm**
Server
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Register a basic storage container
lia.inventory.registerStorage("models/props_c17/lockers001a.mdl", {
name = "Locker",
invType = "storage",
invData = {w = 5, h = 3}
})
**Medium Complexity:**
```lua
```lua
-- Medium: Register storage with custom configuration
local storageData = {
name = "Medical Cabinet",
invType = "medical",
invData = {
w = 8,
h = 4,
maxWeight = 30,
restrictions = {"medical", "drugs"}
}
}
lia.inventory.registerStorage("models/props_c17/furnituremedicinecabinet001a.mdl", storageData)
**High Complexity:**
```lua
```lua
-- High: Register multiple storage types with validation
local function registerStorageContainers()
local storages = {
{
model = "models/props_c17/lockers001a.mdl",
data = {
name = "Security Locker",
invType = "security",
invData = {w = 6, h = 4, maxWeight = 50, restricted = true}
}
},
{
model = "models/props_c17/furnituremedicinecabinet001a.mdl",
data = {
name = "Medical Cabinet",
invType = "medical",
invData = {w = 8, h = 4, maxWeight = 30, medicalOnly = true}
}
}
}
for _, storage in ipairs(storages) do
if storage.model and storage.data then
lia.inventory.registerStorage(storage.model, storage.data)
lia.log("Registered storage: " .. storage.data.name)
end
end
end
---
### lia.getStorageInfo
**Purpose**
Retrieves storage configuration data for a specific model
**When Called**
When checking if a model has registered storage or accessing storage configuration
**Returns**
* Storage data table if found, nil otherwise
**Realm**
Server
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Get storage data for a model
local storageData = lia.inventory.getStorage("models/props_c17/lockers001a.mdl")
if storageData then
print("Storage name:", storageData.name)
end
**Medium Complexity:**
```lua
```lua
-- Medium: Get storage with validation
local function getStorageInfo(model)
if not model or not isstring(model) then
return nil
end
local storageData = lia.inventory.getStorage(model)
if storageData then
return {
name = storageData.name,
type = storageData.invType,
size = storageData.invData.w * storageData.invData.h
}
end
return nil
end
**High Complexity:**
```lua
```lua
-- High: Get storage with comprehensive validation and processing
local function getStorageConfiguration(model)
if not model or not isstring(model) then
lia.warning("Invalid model provided to getStorageConfiguration: " .. tostring(model))
return nil
end
local storageData = lia.inventory.getStorage(model)
if not storageData then
lia.log("No storage configuration found for model: " .. model)
return nil
end
-- Validate storage data structure
if not storageData.name or not storageData.invType or not storageData.invData then
lia.error("Invalid storage data structure for model: " .. model)
return nil
end
-- Process and return validated data
return {
name = storageData.name,
type = storageData.invType,
width = storageData.invData.w or 5,
height = storageData.invData.h or 3,
maxWeight = storageData.invData.maxWeight,
restrictions = storageData.invData.restrictions,
isTrunk = storageData.isTrunk or false
}
end
---
### lia.getStorageConfiguration
**Purpose**
Retrieves storage configuration data for a specific model
**When Called**
When checking if a model has registered storage or accessing storage configuration
**Returns**
* Storage data table if found, nil otherwise
**Realm**
Server
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Get storage data for a model
local storageData = lia.inventory.getStorage("models/props_c17/lockers001a.mdl")
if storageData then
print("Storage name:", storageData.name)
end
**Medium Complexity:**
```lua
```lua
-- Medium: Get storage with validation
local function getStorageInfo(model)
if not model or not isstring(model) then
return nil
end
local storageData = lia.inventory.getStorage(model)
if storageData then
return {
name = storageData.name,
type = storageData.invType,
size = storageData.invData.w * storageData.invData.h
}
end
return nil
end
**High Complexity:**
```lua
```lua
-- High: Get storage with comprehensive validation and processing
local function getStorageConfiguration(model)
if not model or not isstring(model) then
lia.warning("Invalid model provided to getStorageConfiguration: " .. tostring(model))
return nil
end
local storageData = lia.inventory.getStorage(model)
if not storageData then
lia.log("No storage configuration found for model: " .. model)
return nil
end
-- Validate storage data structure
if not storageData.name or not storageData.invType or not storageData.invData then
lia.error("Invalid storage data structure for model: " .. model)
return nil
end
-- Process and return validated data
return {
name = storageData.name,
type = storageData.invType,
width = storageData.invData.w or 5,
height = storageData.invData.h or 3,
maxWeight = storageData.invData.maxWeight,
restrictions = storageData.invData.restrictions,
isTrunk = storageData.isTrunk or false
}
end
---
### lia.inventory.getStorage
**Purpose**
Retrieves storage configuration data for a specific model
**When Called**
When checking if a model has registered storage or accessing storage configuration
**Returns**
* Storage data table if found, nil otherwise
**Realm**
Server
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Get storage data for a model
local storageData = lia.inventory.getStorage("models/props_c17/lockers001a.mdl")
if storageData then
print("Storage name:", storageData.name)
end
**Medium Complexity:**
```lua
```lua
-- Medium: Get storage with validation
local function getStorageInfo(model)
if not model or not isstring(model) then
return nil
end
local storageData = lia.inventory.getStorage(model)
if storageData then
return {
name = storageData.name,
type = storageData.invType,
size = storageData.invData.w * storageData.invData.h
}
end
return nil
end
**High Complexity:**
```lua
```lua
-- High: Get storage with comprehensive validation and processing
local function getStorageConfiguration(model)
if not model or not isstring(model) then
lia.warning("Invalid model provided to getStorageConfiguration: " .. tostring(model))
return nil
end
local storageData = lia.inventory.getStorage(model)
if not storageData then
lia.log("No storage configuration found for model: " .. model)
return nil
end
-- Validate storage data structure
if not storageData.name or not storageData.invType or not storageData.invData then
lia.error("Invalid storage data structure for model: " .. model)
return nil
end
-- Process and return validated data
return {
name = storageData.name,
type = storageData.invType,
width = storageData.invData.w or 5,
height = storageData.invData.h or 3,
maxWeight = storageData.invData.maxWeight,
restrictions = storageData.invData.restrictions,
isTrunk = storageData.isTrunk or false
}
end
---
### lia.registerVehicleTrunks
**Purpose**
Registers a vehicle class with trunk inventory configuration
**When Called**
During module initialization to register vehicle trunks
**Returns**
* The registered trunk data table
**Realm**
Server
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Register a basic vehicle trunk
lia.inventory.registerTrunk("prop_vehicle_jeep", {
name = "Jeep Trunk",
invType = "trunk",
invData = {w = 8, h = 3}
})
**Medium Complexity:**
```lua
```lua
-- Medium: Register trunk with custom configuration
local trunkData = {
name = "Police Car Trunk",
invType = "police_trunk",
invData = {
w = 10,
h = 4,
maxWeight = 100,
restricted = true,
allowedItems = {"weapons", "evidence"}
}
}
lia.inventory.registerTrunk("prop_vehicle_police", trunkData)
**High Complexity:**
```lua
```lua
-- High: Register multiple vehicle trunks with validation
local function registerVehicleTrunks()
local vehicles = {
{
class = "prop_vehicle_jeep",
data = {
name = "Civilian Vehicle Trunk",
invType = "civilian_trunk",
invData = {w = 8, h = 3, maxWeight = 50}
}
},
{
class = "prop_vehicle_police",
data = {
name = "Police Vehicle Trunk",
invType = "police_trunk",
invData = {w = 10, h = 4, maxWeight = 100, restricted = true}
}
},
{
class = "prop_vehicle_ambulance",
data = {
name = "Ambulance Storage",
invType = "medical_trunk",
invData = {w = 12, h = 5, maxWeight = 75, medicalOnly = true}
}
}
}
for _, vehicle in ipairs(vehicles) do
if vehicle.class and vehicle.data then
lia.inventory.registerTrunk(vehicle.class, vehicle.data)
lia.log("Registered trunk for vehicle: " .. vehicle.data.name)
end
end
end
---
### lia.inventory.registerTrunk
**Purpose**
Registers a vehicle class with trunk inventory configuration
**When Called**
During module initialization to register vehicle trunks
**Returns**
* The registered trunk data table
**Realm**
Server
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Register a basic vehicle trunk
lia.inventory.registerTrunk("prop_vehicle_jeep", {
name = "Jeep Trunk",
invType = "trunk",
invData = {w = 8, h = 3}
})
**Medium Complexity:**
```lua
```lua
-- Medium: Register trunk with custom configuration
local trunkData = {
name = "Police Car Trunk",
invType = "police_trunk",
invData = {
w = 10,
h = 4,
maxWeight = 100,
restricted = true,
allowedItems = {"weapons", "evidence"}
}
}
lia.inventory.registerTrunk("prop_vehicle_police", trunkData)
**High Complexity:**
```lua
```lua
-- High: Register multiple vehicle trunks with validation
local function registerVehicleTrunks()
local vehicles = {
{
class = "prop_vehicle_jeep",
data = {
name = "Civilian Vehicle Trunk",
invType = "civilian_trunk",
invData = {w = 8, h = 3, maxWeight = 50}
}
},
{
class = "prop_vehicle_police",
data = {
name = "Police Vehicle Trunk",
invType = "police_trunk",
invData = {w = 10, h = 4, maxWeight = 100, restricted = true}
}
},
{
class = "prop_vehicle_ambulance",
data = {
name = "Ambulance Storage",
invType = "medical_trunk",
invData = {w = 12, h = 5, maxWeight = 75, medicalOnly = true}
}
}
}
for _, vehicle in ipairs(vehicles) do
if vehicle.class and vehicle.data then
lia.inventory.registerTrunk(vehicle.class, vehicle.data)
lia.log("Registered trunk for vehicle: " .. vehicle.data.name)
end
end
end
---
### lia.getVehicleTrunk
**Purpose**
Retrieves trunk configuration data for a specific vehicle class
**When Called**
When checking if a vehicle has a trunk or accessing trunk configuration
**Returns**
* Trunk data table if found, nil otherwise
**Realm**
Server
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Get trunk data for a vehicle
local trunkData = lia.inventory.getTrunk("prop_vehicle_jeep")
if trunkData then
print("Trunk name:", trunkData.name)
end
**Medium Complexity:**
```lua
```lua
-- Medium: Get trunk with validation
local function getVehicleTrunk(vehicleClass)
if not vehicleClass or not isstring(vehicleClass) then
return nil
end
local trunkData = lia.inventory.getTrunk(vehicleClass)
if trunkData then
return {
name = trunkData.name,
type = trunkData.invType,
size = trunkData.invData.w * trunkData.invData.h,
maxWeight = trunkData.invData.maxWeight
}
end
return nil
end
**High Complexity:**
```lua
```lua
-- High: Get trunk with comprehensive validation and processing
local function getVehicleTrunkConfiguration(vehicleClass)
if not vehicleClass or not isstring(vehicleClass) then
lia.warning("Invalid vehicle class provided: " .. tostring(vehicleClass))
return nil
end
local trunkData = lia.inventory.getTrunk(vehicleClass)
if not trunkData then
lia.log("No trunk configuration found for vehicle: " .. vehicleClass)
return nil
end
-- Validate trunk data structure
if not trunkData.name or not trunkData.invType or not trunkData.invData then
lia.error("Invalid trunk data structure for vehicle: " .. vehicleClass)
return nil
end
-- Process and return validated data
return {
name = trunkData.name,
type = trunkData.invType,
width = trunkData.invData.w or 10,
height = trunkData.invData.h or 2,
maxWeight = trunkData.invData.maxWeight,
restrictions = trunkData.invData.restrictions,
isTrunk = trunkData.isTrunk or true,
trunkKey = trunkData.trunkKey
}
end
---
### lia.getVehicleTrunkConfiguration
**Purpose**
Retrieves trunk configuration data for a specific vehicle class
**When Called**
When checking if a vehicle has a trunk or accessing trunk configuration
**Returns**
* Trunk data table if found, nil otherwise
**Realm**
Server
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Get trunk data for a vehicle
local trunkData = lia.inventory.getTrunk("prop_vehicle_jeep")
if trunkData then
print("Trunk name:", trunkData.name)
end
**Medium Complexity:**
```lua
```lua
-- Medium: Get trunk with validation
local function getVehicleTrunk(vehicleClass)
if not vehicleClass or not isstring(vehicleClass) then
return nil
end
local trunkData = lia.inventory.getTrunk(vehicleClass)
if trunkData then
return {
name = trunkData.name,
type = trunkData.invType,
size = trunkData.invData.w * trunkData.invData.h,
maxWeight = trunkData.invData.maxWeight
}
end
return nil
end
**High Complexity:**
```lua
```lua
-- High: Get trunk with comprehensive validation and processing
local function getVehicleTrunkConfiguration(vehicleClass)
if not vehicleClass or not isstring(vehicleClass) then
lia.warning("Invalid vehicle class provided: " .. tostring(vehicleClass))
return nil
end
local trunkData = lia.inventory.getTrunk(vehicleClass)
if not trunkData then
lia.log("No trunk configuration found for vehicle: " .. vehicleClass)
return nil
end
-- Validate trunk data structure
if not trunkData.name or not trunkData.invType or not trunkData.invData then
lia.error("Invalid trunk data structure for vehicle: " .. vehicleClass)
return nil
end
-- Process and return validated data
return {
name = trunkData.name,
type = trunkData.invType,
width = trunkData.invData.w or 10,
height = trunkData.invData.h or 2,
maxWeight = trunkData.invData.maxWeight,
restrictions = trunkData.invData.restrictions,
isTrunk = trunkData.isTrunk or true,
trunkKey = trunkData.trunkKey
}
end
---
### lia.inventory.getTrunk
**Purpose**
Retrieves trunk configuration data for a specific vehicle class
**When Called**
When checking if a vehicle has a trunk or accessing trunk configuration
**Returns**
* Trunk data table if found, nil otherwise
**Realm**
Server
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Get trunk data for a vehicle
local trunkData = lia.inventory.getTrunk("prop_vehicle_jeep")
if trunkData then
print("Trunk name:", trunkData.name)
end
**Medium Complexity:**
```lua
```lua
-- Medium: Get trunk with validation
local function getVehicleTrunk(vehicleClass)
if not vehicleClass or not isstring(vehicleClass) then
return nil
end
local trunkData = lia.inventory.getTrunk(vehicleClass)
if trunkData then
return {
name = trunkData.name,
type = trunkData.invType,
size = trunkData.invData.w * trunkData.invData.h,
maxWeight = trunkData.invData.maxWeight
}
end
return nil
end
**High Complexity:**
```lua
```lua
-- High: Get trunk with comprehensive validation and processing
local function getVehicleTrunkConfiguration(vehicleClass)
if not vehicleClass or not isstring(vehicleClass) then
lia.warning("Invalid vehicle class provided: " .. tostring(vehicleClass))
return nil
end
local trunkData = lia.inventory.getTrunk(vehicleClass)
if not trunkData then
lia.log("No trunk configuration found for vehicle: " .. vehicleClass)
return nil
end
-- Validate trunk data structure
if not trunkData.name or not trunkData.invType or not trunkData.invData then
lia.error("Invalid trunk data structure for vehicle: " .. vehicleClass)
return nil
end
-- Process and return validated data
return {
name = trunkData.name,
type = trunkData.invType,
width = trunkData.invData.w or 10,
height = trunkData.invData.h or 2,
maxWeight = trunkData.invData.maxWeight,
restrictions = trunkData.invData.restrictions,
isTrunk = trunkData.isTrunk or true,
trunkKey = trunkData.trunkKey
}
end
---
### lia.getAllTrunkInfo
**Purpose**
Retrieves all registered vehicle trunk configurations
**When Called**
When needing to iterate through all available vehicle trunks
**Returns**
* Table containing all trunk configurations indexed by vehicle class
**Realm**
Server
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Get all trunks
local trunks = lia.inventory.getAllTrunks()
for vehicleClass, trunkData in pairs(trunks) do
print("Vehicle:", vehicleClass, "Trunk:", trunkData.name)
end
**Medium Complexity:**
```lua
```lua
-- Medium: Get trunks with processing
local function getAllTrunkInfo()
local trunks = lia.inventory.getAllTrunks()
local trunkList = {}
for vehicleClass, trunkData in pairs(trunks) do
table.insert(trunkList, {
vehicleClass = vehicleClass,
name = trunkData.name,
size = trunkData.invData.w * trunkData.invData.h
})
end
return trunkList
end
**High Complexity:**
```lua
```lua
-- High: Get trunks with comprehensive validation and categorization
local function getCategorizedTrunks()
local trunks = lia.inventory.getAllTrunks()
local categorized = {
civilian = {},
emergency = {},
military = {},
other = {}
}
for vehicleClass, trunkData in pairs(trunks) do
if not trunkData or not trunkData.name or not trunkData.invData then
lia.warning("Invalid trunk data for vehicle: " .. vehicleClass)
goto continue
end
local trunkInfo = {
vehicleClass = vehicleClass,
name = trunkData.name,
type = trunkData.invType,
width = trunkData.invData.w,
height = trunkData.invData.h,
maxWeight = trunkData.invData.maxWeight,
restricted = trunkData.invData.restricted or false
}
-- Categorize based on vehicle class
if string.find(vehicleClass:lower(), "police") or string.find(vehicleClass:lower(), "ambulance") then
table.insert(categorized.emergency, trunkInfo)
elseif string.find(vehicleClass:lower(), "military") or string.find(vehicleClass:lower(), "tank") then
table.insert(categorized.military, trunkInfo)
elseif string.find(vehicleClass:lower(), "civilian") or string.find(vehicleClass:lower(), "jeep") then
table.insert(categorized.civilian, trunkInfo)
else
table.insert(categorized.other, trunkInfo)
end
::continue::
end
return categorized
end
---
### lia.getCategorizedTrunks
**Purpose**
Retrieves all registered vehicle trunk configurations
**When Called**
When needing to iterate through all available vehicle trunks
**Returns**
* Table containing all trunk configurations indexed by vehicle class
**Realm**
Server
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Get all trunks
local trunks = lia.inventory.getAllTrunks()
for vehicleClass, trunkData in pairs(trunks) do
print("Vehicle:", vehicleClass, "Trunk:", trunkData.name)
end
**Medium Complexity:**
```lua
```lua
-- Medium: Get trunks with processing
local function getAllTrunkInfo()
local trunks = lia.inventory.getAllTrunks()
local trunkList = {}
for vehicleClass, trunkData in pairs(trunks) do
table.insert(trunkList, {
vehicleClass = vehicleClass,
name = trunkData.name,
size = trunkData.invData.w * trunkData.invData.h
})
end
return trunkList
end
**High Complexity:**
```lua
```lua
-- High: Get trunks with comprehensive validation and categorization
local function getCategorizedTrunks()
local trunks = lia.inventory.getAllTrunks()
local categorized = {
civilian = {},
emergency = {},
military = {},
other = {}
}
for vehicleClass, trunkData in pairs(trunks) do
if not trunkData or not trunkData.name or not trunkData.invData then
lia.warning("Invalid trunk data for vehicle: " .. vehicleClass)
goto continue
end
local trunkInfo = {
vehicleClass = vehicleClass,
name = trunkData.name,
type = trunkData.invType,
width = trunkData.invData.w,
height = trunkData.invData.h,
maxWeight = trunkData.invData.maxWeight,
restricted = trunkData.invData.restricted or false
}
-- Categorize based on vehicle class
if string.find(vehicleClass:lower(), "police") or string.find(vehicleClass:lower(), "ambulance") then
table.insert(categorized.emergency, trunkInfo)
elseif string.find(vehicleClass:lower(), "military") or string.find(vehicleClass:lower(), "tank") then
table.insert(categorized.military, trunkInfo)
elseif string.find(vehicleClass:lower(), "civilian") or string.find(vehicleClass:lower(), "jeep") then
table.insert(categorized.civilian, trunkInfo)
else
table.insert(categorized.other, trunkInfo)
end
::continue::
end
return categorized
end
---
### lia.inventory.getAllTrunks
**Purpose**
Retrieves all registered vehicle trunk configurations
**When Called**
When needing to iterate through all available vehicle trunks
**Returns**
* Table containing all trunk configurations indexed by vehicle class
**Realm**
Server
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Get all trunks
local trunks = lia.inventory.getAllTrunks()
for vehicleClass, trunkData in pairs(trunks) do
print("Vehicle:", vehicleClass, "Trunk:", trunkData.name)
end
**Medium Complexity:**
```lua
```lua
-- Medium: Get trunks with processing
local function getAllTrunkInfo()
local trunks = lia.inventory.getAllTrunks()
local trunkList = {}
for vehicleClass, trunkData in pairs(trunks) do
table.insert(trunkList, {
vehicleClass = vehicleClass,
name = trunkData.name,
size = trunkData.invData.w * trunkData.invData.h
})
end
return trunkList
end
**High Complexity:**
```lua
```lua
-- High: Get trunks with comprehensive validation and categorization
local function getCategorizedTrunks()
local trunks = lia.inventory.getAllTrunks()
local categorized = {
civilian = {},
emergency = {},
military = {},
other = {}
}
for vehicleClass, trunkData in pairs(trunks) do
if not trunkData or not trunkData.name or not trunkData.invData then
lia.warning("Invalid trunk data for vehicle: " .. vehicleClass)
goto continue
end
local trunkInfo = {
vehicleClass = vehicleClass,
name = trunkData.name,
type = trunkData.invType,
width = trunkData.invData.w,
height = trunkData.invData.h,
maxWeight = trunkData.invData.maxWeight,
restricted = trunkData.invData.restricted or false
}
-- Categorize based on vehicle class
if string.find(vehicleClass:lower(), "police") or string.find(vehicleClass:lower(), "ambulance") then
table.insert(categorized.emergency, trunkInfo)
elseif string.find(vehicleClass:lower(), "military") or string.find(vehicleClass:lower(), "tank") then
table.insert(categorized.military, trunkInfo)
elseif string.find(vehicleClass:lower(), "civilian") or string.find(vehicleClass:lower(), "jeep") then
table.insert(categorized.civilian, trunkInfo)
else
table.insert(categorized.other, trunkInfo)
end
::continue::
end
return categorized
end
---
### lia.getStorageContainers
**Purpose**
Retrieves all registered storage configurations with optional trunk filtering
**When Called**
When needing to iterate through all available storage containers
**Returns**
* Table containing all storage configurations indexed by model/class
**Realm**
Server
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Get all storage (including trunks)
local allStorage = lia.inventory.getAllStorage()
for key, data in pairs(allStorage) do
print("Storage:", key, "Name:", data.name)
end
**Medium Complexity:**
```lua
```lua
-- Medium: Get storage excluding trunks
local function getStorageContainers()
local storageOnly = lia.inventory.getAllStorage(false)
local containers = {}
for model, data in pairs(storageOnly) do
table.insert(containers, {
model = model,
name = data.name,
type = data.invType,
size = data.invData.w * data.invData.h
})
end
return containers
end
**High Complexity:**
```lua
```lua
-- High: Get storage with comprehensive categorization and validation
local function getCategorizedStorage(includeTrunks)
local allStorage = lia.inventory.getAllStorage(includeTrunks)
local categorized = {
containers = {},
trunks = {},
invalid = {}
}
for key, data in pairs(allStorage) do
if not data or not data.name or not data.invData then
table.insert(categorized.invalid, {key = key, reason = "Invalid data structure"})
goto continue
end
local storageInfo = {
key = key,
name = data.name,
type = data.invType,
width = data.invData.w,
height = data.invData.h,
maxWeight = data.invData.maxWeight,
isTrunk = data.isTrunk or false
}
if data.isTrunk then
table.insert(categorized.trunks, storageInfo)
else
table.insert(categorized.containers, storageInfo)
end
::continue::
end
lia.log("Categorized " .. #categorized.containers .. " containers and " .. #categorized.trunks .. " trunks")
if #categorized.invalid > 0 then
lia.warning("Found " .. #categorized.invalid .. " invalid storage entries")
end
return categorized
end
---
### lia.getCategorizedStorage
**Purpose**
Retrieves all registered storage configurations with optional trunk filtering
**When Called**
When needing to iterate through all available storage containers
**Returns**
* Table containing all storage configurations indexed by model/class
**Realm**
Server
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Get all storage (including trunks)
local allStorage = lia.inventory.getAllStorage()
for key, data in pairs(allStorage) do
print("Storage:", key, "Name:", data.name)
end
**Medium Complexity:**
```lua
```lua
-- Medium: Get storage excluding trunks
local function getStorageContainers()
local storageOnly = lia.inventory.getAllStorage(false)
local containers = {}
for model, data in pairs(storageOnly) do
table.insert(containers, {
model = model,
name = data.name,
type = data.invType,
size = data.invData.w * data.invData.h
})
end
return containers
end
**High Complexity:**
```lua
```lua
-- High: Get storage with comprehensive categorization and validation
local function getCategorizedStorage(includeTrunks)
local allStorage = lia.inventory.getAllStorage(includeTrunks)
local categorized = {
containers = {},
trunks = {},
invalid = {}
}
for key, data in pairs(allStorage) do
if not data or not data.name or not data.invData then
table.insert(categorized.invalid, {key = key, reason = "Invalid data structure"})
goto continue
end
local storageInfo = {
key = key,
name = data.name,
type = data.invType,
width = data.invData.w,
height = data.invData.h,
maxWeight = data.invData.maxWeight,
isTrunk = data.isTrunk or false
}
if data.isTrunk then
table.insert(categorized.trunks, storageInfo)
else
table.insert(categorized.containers, storageInfo)
end
::continue::
end
lia.log("Categorized " .. #categorized.containers .. " containers and " .. #categorized.trunks .. " trunks")
if #categorized.invalid > 0 then
lia.warning("Found " .. #categorized.invalid .. " invalid storage entries")
end
return categorized
end
---
### lia.inventory.getAllStorage
**Purpose**
Retrieves all registered storage configurations with optional trunk filtering
**When Called**
When needing to iterate through all available storage containers
**Returns**
* Table containing all storage configurations indexed by model/class
**Realm**
Server
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Get all storage (including trunks)
local allStorage = lia.inventory.getAllStorage()
for key, data in pairs(allStorage) do
print("Storage:", key, "Name:", data.name)
end
**Medium Complexity:**
```lua
```lua
-- Medium: Get storage excluding trunks
local function getStorageContainers()
local storageOnly = lia.inventory.getAllStorage(false)
local containers = {}
for model, data in pairs(storageOnly) do
table.insert(containers, {
model = model,
name = data.name,
type = data.invType,
size = data.invData.w * data.invData.h
})
end
return containers
end
**High Complexity:**
```lua
```lua
-- High: Get storage with comprehensive categorization and validation
local function getCategorizedStorage(includeTrunks)
local allStorage = lia.inventory.getAllStorage(includeTrunks)
local categorized = {
containers = {},
trunks = {},
invalid = {}
}
for key, data in pairs(allStorage) do
if not data or not data.name or not data.invData then
table.insert(categorized.invalid, {key = key, reason = "Invalid data structure"})
goto continue
end
local storageInfo = {
key = key,
name = data.name,
type = data.invType,
width = data.invData.w,
height = data.invData.h,
maxWeight = data.invData.maxWeight,
isTrunk = data.isTrunk or false
}
if data.isTrunk then
table.insert(categorized.trunks, storageInfo)
else
table.insert(categorized.containers, storageInfo)
end
::continue::
end
lia.log("Categorized " .. #categorized.containers .. " containers and " .. #categorized.trunks .. " trunks")
if #categorized.invalid > 0 then
lia.warning("Found " .. #categorized.invalid .. " invalid storage entries")
end
return categorized
end
---
### lia.showInventoryInFrame
**Purpose**
Displays an inventory panel to the client
**When Called**
When a player opens an inventory (player inventory, storage container, etc.)
**Returns**
* The created inventory panel
**Realm**
Client
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Show inventory panel
local panel = lia.inventory.show(inventory)
**Medium Complexity:**
```lua
```lua
-- Medium: Show inventory with parent panel
local function showInventoryInFrame(inventory)
local frame = vgui.Create("DFrame")
frame:SetSize(400, 300)
frame:Center()
frame:MakePopup()
local invPanel = lia.inventory.show(inventory, frame)
return invPanel
end
**High Complexity:**
```lua
```lua
-- High: Show inventory with comprehensive validation and error handling
local function showInventorySafely(inventory, parent)
if not inventory or not inventory.id then
lia.notify("Invalid inventory provided", "error")
return nil
end
-- Check if inventory is already open
local globalName = "inv" .. inventory.id
if IsValid(lia.gui[globalName]) then
lia.gui[globalName]:Remove()
end
-- Validate parent panel
if parent and not IsValid(parent) then
lia.warning("Invalid parent panel provided to showInventorySafely")
parent = nil
end
-- Create inventory panel
local panel = lia.inventory.show(inventory, parent)
if not panel or not IsValid(panel) then
lia.error("Failed to create inventory panel for inventory " .. inventory.id)
return nil
end
-- Add custom styling and behavior
panel:SetPos(50, 50)
panel:SetSize(600, 400)
-- Add close button
local closeBtn = panel:Add("DButton")
closeBtn:SetText("Close")
closeBtn:SetPos(panel:GetWide() - 80, 10)
closeBtn:SetSize(70, 25)
closeBtn.DoClick = function()
panel:Remove()
end
lia.log("Successfully displayed inventory panel for inventory " .. inventory.id)
return panel
end
---
### lia.showInventorySafely
**Purpose**
Displays an inventory panel to the client
**When Called**
When a player opens an inventory (player inventory, storage container, etc.)
**Returns**
* The created inventory panel
**Realm**
Client
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Show inventory panel
local panel = lia.inventory.show(inventory)
**Medium Complexity:**
```lua
```lua
-- Medium: Show inventory with parent panel
local function showInventoryInFrame(inventory)
local frame = vgui.Create("DFrame")
frame:SetSize(400, 300)
frame:Center()
frame:MakePopup()
local invPanel = lia.inventory.show(inventory, frame)
return invPanel
end
**High Complexity:**
```lua
```lua
-- High: Show inventory with comprehensive validation and error handling
local function showInventorySafely(inventory, parent)
if not inventory or not inventory.id then
lia.notify("Invalid inventory provided", "error")
return nil
end
-- Check if inventory is already open
local globalName = "inv" .. inventory.id
if IsValid(lia.gui[globalName]) then
lia.gui[globalName]:Remove()
end
-- Validate parent panel
if parent and not IsValid(parent) then
lia.warning("Invalid parent panel provided to showInventorySafely")
parent = nil
end
-- Create inventory panel
local panel = lia.inventory.show(inventory, parent)
if not panel or not IsValid(panel) then
lia.error("Failed to create inventory panel for inventory " .. inventory.id)
return nil
end
-- Add custom styling and behavior
panel:SetPos(50, 50)
panel:SetSize(600, 400)
-- Add close button
local closeBtn = panel:Add("DButton")
closeBtn:SetText("Close")
closeBtn:SetPos(panel:GetWide() - 80, 10)
closeBtn:SetSize(70, 25)
closeBtn.DoClick = function()
panel:Remove()
end
lia.log("Successfully displayed inventory panel for inventory " .. inventory.id)
return panel
end
---
### lia.inventory.show
**Purpose**
Displays an inventory panel to the client
**When Called**
When a player opens an inventory (player inventory, storage container, etc.)
**Returns**
* The created inventory panel
**Realm**
Client
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Show inventory panel
local panel = lia.inventory.show(inventory)
**Medium Complexity:**
```lua
```lua
-- Medium: Show inventory with parent panel
local function showInventoryInFrame(inventory)
local frame = vgui.Create("DFrame")
frame:SetSize(400, 300)
frame:Center()
frame:MakePopup()
local invPanel = lia.inventory.show(inventory, frame)
return invPanel
end
**High Complexity:**
```lua
```lua
-- High: Show inventory with comprehensive validation and error handling
local function showInventorySafely(inventory, parent)
if not inventory or not inventory.id then
lia.notify("Invalid inventory provided", "error")
return nil
end
-- Check if inventory is already open
local globalName = "inv" .. inventory.id
if IsValid(lia.gui[globalName]) then
lia.gui[globalName]:Remove()
end
-- Validate parent panel
if parent and not IsValid(parent) then
lia.warning("Invalid parent panel provided to showInventorySafely")
parent = nil
end
-- Create inventory panel
local panel = lia.inventory.show(inventory, parent)
if not panel or not IsValid(panel) then
lia.error("Failed to create inventory panel for inventory " .. inventory.id)
return nil
end
-- Add custom styling and behavior
panel:SetPos(50, 50)
panel:SetSize(600, 400)
-- Add close button
local closeBtn = panel:Add("DButton")
closeBtn:SetText("Close")
closeBtn:SetPos(panel:GetWide() - 80, 10)
closeBtn:SetSize(70, 25)
closeBtn.DoClick = function()
panel:Remove()
end
lia.log("Successfully displayed inventory panel for inventory " .. inventory.id)
return panel
end
---
### lia.panel:OnRemove
**Purpose**
Displays an inventory panel to the client
**When Called**
When a player opens an inventory (player inventory, storage container, etc.)
**Returns**
* The created inventory panel
**Realm**
Client
**Example Usage**
**Low Complexity:**
```lua
```lua
-- Simple: Show inventory panel
local panel = lia.inventory.show(inventory)
**Medium Complexity:**
```lua
```lua
-- Medium: Show inventory with parent panel
local function showInventoryInFrame(inventory)
local frame = vgui.Create("DFrame")
frame:SetSize(400, 300)
frame:Center()
frame:MakePopup()
local invPanel = lia.inventory.show(inventory, frame)
return invPanel
end
**High Complexity:**
```lua
```lua
-- High: Show inventory with comprehensive validation and error handling
local function showInventorySafely(inventory, parent)
if not inventory or not inventory.id then
lia.notify("Invalid inventory provided", "error")
return nil
end
-- Check if inventory is already open
local globalName = "inv" .. inventory.id
if IsValid(lia.gui[globalName]) then
lia.gui[globalName]:Remove()
end
-- Validate parent panel
if parent and not IsValid(parent) then
lia.warning("Invalid parent panel provided to showInventorySafely")
parent = nil
end
-- Create inventory panel
local panel = lia.inventory.show(inventory, parent)
if not panel or not IsValid(panel) then
lia.error("Failed to create inventory panel for inventory " .. inventory.id)
return nil
end
-- Add custom styling and behavior
panel:SetPos(50, 50)
panel:SetSize(600, 400)
-- Add close button
local closeBtn = panel:Add("DButton")
closeBtn:SetText("Close")
closeBtn:SetPos(panel:GetWide() - 80, 10)
closeBtn:SetSize(70, 25)
closeBtn.DoClick = function()
panel:Remove()
end
lia.log("Successfully displayed inventory panel for inventory " .. inventory.id)
return panel
end