Containers
Before using any container methods (add_item
, remove_item
, has_item
, etc.), you must first retrieve the container object using the following export:
local container = exports.list_inventory:get_container(id)
This returns the active container object for the given id
, complete with all public methods.
Then you can use the methods below on the container like so:
local container = exports.list_inventory:get_container("some_container_id")
if not container then
print("No container found for that ID")
return
end
container:add_item("bandage", 2)
get_data
Get a specific field or the full container data.
Params
key
(string, optional): The key to fetch
Returns
Value of the key or full data table
local coords = container:get_data("coords")
set_data
Set a custom field on the container.
Params
key
(string): Field namevalue
(any): Value to store
Returns
true
container:set_data("custom_label", "Loot Crate")
get_items
Returns a table of all items in the container.
Returns
table
: All container items indexed by slot
local items = container:get_items()
get_item
Returns the first matching item by slot, ID, or metadata.
Params
lookup
(number|string|table): Slot number, item ID, or metadata table
Returns
Item object or
nil
local item = container:get_item("bandage")
has_item
Checks if container contains an item by slot, ID, or metadata.
Params
lookup
(number|string|table): Slot number, item ID, or metadata tableamount
(number): Amount required (default: 1)
Returns
true
if found, otherwisefalse
if container:has_item("weapon_pistol", 1) then ... end
add_item
Adds an item to the container.
Params
id
(string): Item IDamount
(number): Quantityitem_data
(table, optional): Item metadata (e.g., quality, custom props)
Returns
true
on success, orfalse, reason
on failure
container:add_item("ammo_pistol", 24)
remove_item
Removes item(s) by slot, ID, or metadata.
Params
lookup
(number|string|table): Slot number, item ID, or metadata tableamount
(number): Amount to remove
Returns
true
on success,false
otherwise
container:remove_item("bandage", 2)
split_item
Splits a stack in one slot into a new slot.
Params
slot
(number|string): Source slotamount
(number): Amount to split
Returns
true
on success,false
otherwise
container:split_item(1, 5)
clear_items
Removes all items from the container.
Returns
true
container:clear_items()
save
Persists the container to the database (if marked as persistent).
Returns
true
on success,false
on failure
container:save()
sync
Sends container inventory state to all clients.
container:sync()
Last updated