ug-inventory shows the items and calls the client functions below. Owners can swap the UI without weakening security.
Containers
Stashes, vehicle trunks and gloveboxes, ground drops, and opening them.
Client and UI
Client functions, building an inventory UI, and what the server checks.
Concepts
- Slots and weight. Each inventory has a number of slots and a maximum weight in grams. Each slot holds one stack. Player inventories use
playerSlotsandplayerWeightfromconfig/inventory.lua. - All or nothing. Every change either applies fully or not at all. Adding 12 water that only fits 10 adds none and returns
cannot_carry. - Stacking. Units stack up to the item’s
maxStack, only with the same name and equal metadata. Existing stacks fill first, then empty slots, lowest slot first. - Targets.
targetis a player source, for that player’s inventory, or an inventory id. Functions act on loaded inventories: player inventories while their character is loaded, others once opened or loaded. Unknown ids returnnot_found. - Idle unloading. Saved inventories nobody owns or has open unload after 5 minutes idle, and are saved first.
- Audit log. Every change writes a row to
ug_item_logs, in the same database transaction as the inventory. See GetLog.
Adding and removing
AddItem
Checked by the item’s rule.
RemoveItem
metadata, only stacks whose metadata has those keys and values count.
RemoveFromSlot
count defaults to the whole stack.
SetMetadata
0.
Clear
Moving
Between two inventories, the target’s weight is checked, and both sides get an audit row pointing to the other.
Reading
GetSource returns the player who owns an inventory id, or nil.
Use
- The slot has an item with a use handler. Otherwise
not_foundorinvalid_args. - The player is alive, unless the handler allows otherwise. Otherwise
no_permission. - The item’s cooldown passed. Otherwise
rate_limited. Items:BeforeUseallows it. Otherwiseno_permission.- The handler runs. Returning
falserefuses the use withno_permission. An error returnsinternal_error. consumeunits leave the slot, andug-core:Items:Usedfires.
GetLog
Errors
Wrong argument types, counts out of range and long reasons raise.
Events
Use
GetSource(inventoryId) to find the player of a player inventory.
Hooks
They allow or cancel. Changes to the payload are ignored.
Death
Items stay when a player dies. WithclearOnRespawn = true in config/inventory.lua, respawning empties the inventory, except items with keepOnRespawn. Inventory:BeforeClearOnRespawn can cancel it, for example in an arena.
Player object
Player objects have shortcuts:player:AddItem, RemoveItem, GetItemCount, HasItem, CanCarry, GetItems, UseItem.