Player
Before using any player inventory methods (add_item
, has_item
, get_item
, etc.), you must first retrieve the player inventory object using the provided export:
local player = exports.list_inventory:get_player(source)
This returns the full player inventory object, with all public methods attached. Then you can use the methods below like so:
RegisterCommand("give_bread", function(source)
local player = exports.list_inventory:get_player(source)
if not player then
print("Inventory not found")
return
end
player:add_item("bread", 1)
end)
create_player_inventory
Create a player inventory object and attach methods/data.
Params
source
(number): The player source
Returns
Player inventory object or
false
local player = exports.list_inventory:create_player_inventory(source)
get_player
Returns the inventory object for the given player.
Params
source
(number): The player source
Returns
Player inventory object or
nil
local inv = exports.list_inventory:get_player(source)
add_item
Adds an item to the inventory, optionally with metadata.
Params
id
(string): Item IDamount
(number): Quantityitem_data
(table, optional): Item metadata (e.g., quality, serial)
Returns
true
on success, orfalse, reason
on failure
player:add_item("water", 2, { quality = 100 })
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
player:remove_item(1, 1) -- slot
player:remove_item("bread", 1) -- ID
player:remove_item({ quality = 50 }, 1) -- metadata
has_item
Checks if inventory contains 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
player:has_item("water", 2)
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 = player:get_item("water")
get_items
Returns a table of all items in the inventory.
Returns
table
: All items indexed by slot
local items = player:get_items()
set_data
Sets a custom data field on the inventory.
Params
key
(string): Field namevalue
(any): Value to store
Returns
true
player:set_data("weight", 500)
get_data
Gets a specific or all data values from the inventory.
Params
key
(string, optional): Field name
Returns
Value of the field or full data table
local weight = player:get_data("weight")
has_data
Checks whether a custom data key exists.
Params
key
(string): Field name
Returns
true
if exists,false
otherwise
if player:has_data("slots") then ... end
update_item_data
Updates the metadata for a specific slot.
Params
slot
(number|string): Slot numbernew_data
(table): New metadata to merge in
Returns
true
on success,false
on failure
player:update_item_data(1, { durability = 80 })
split_item
Splits a stack in one slot into a new one.
Params
slot
(number|string): Source slotamount
(number): Amount to split
Returns
true
on success,false
otherwise
player:split_item(1, 3)
clear_items
Removes all items from the inventory.
Returns
true
player:clear_items()
save
Saves the current inventory state to the database.
Returns
true
on success,false
on failure
player:save()
sync
Syncs the inventory with the client.
player:sync()
Last updated