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
get_player
Returns the inventory object for the given player.
Params
source(number): The player source
Returns
Player inventory object or
nil
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
trueon success, orfalse, reasonon failure
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
trueon success,falseotherwise
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
trueif found, otherwisefalse
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
get_items
Returns a table of all items in the inventory.
Returns
table: All items indexed by slot
set_data
Sets a custom data field on the inventory.
Params
key(string): Field namevalue(any): Value to store
Returns
true
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
has_data
Checks whether a custom data key exists.
Params
key(string): Field name
Returns
trueif exists,falseotherwise
update_item_data
Updates the metadata for a specific slot.
Params
slot(number|string): Slot numbernew_data(table): New metadata to merge in
Returns
trueon success,falseon failure
split_item
Splits a stack in one slot into a new one.
Params
slot(number|string): Source slotamount(number): Amount to split
Returns
trueon success,falseotherwise
clear_items
Removes all items from the inventory.
Returns
true
save
Saves the current inventory state to the database.
Returns
trueon success,falseon failure
sync
Syncs the inventory with the client.
Last updated