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 ID

  • amount (number): Quantity

  • item_data (table, optional): Item metadata (e.g., quality, serial)

Returns

  • true on success, or false, reason on failure


remove_item

Removes item(s) by slot, ID, or metadata.

Params

  • lookup (number|string|table): Slot number, item ID, or metadata table

  • amount (number): Amount to remove

Returns

  • true on success, false otherwise


has_item

Checks if inventory contains item by slot, ID, or metadata.

Params

  • lookup (number|string|table): Slot number, item ID, or metadata table

  • amount (number): Amount required (default: 1)

Returns

  • true if found, otherwise false


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 name

  • value (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

  • true if exists, false otherwise


update_item_data

Updates the metadata for a specific slot.

Params

  • slot (number|string): Slot number

  • new_data (table): New metadata to merge in

Returns

  • true on success, false on failure


split_item

Splits a stack in one slot into a new one.

Params

  • slot (number|string): Source slot

  • amount (number): Amount to split

Returns

  • true on success, false otherwise


clear_items

Removes all items from the inventory.

Returns

  • true


save

Saves the current inventory state to the database.

Returns

  • true on success, false on failure


sync

Syncs the inventory with the client.

Last updated