Introduction
This page documents all server-side exports available fromrsg-inventory. These functions allow you to interact with player inventories, stashes, and items.
Player Inventory Functions
Load Inventory
Loads a player’s inventory from the database.source(number) - Player’s server IDcitizenid(string) - Player’s citizen ID
table - Loaded inventory items
Example:
This function is automatically called by rsg-core when a player logs in. You rarely need to call it manually.
Save Inventory
Saves a player’s inventory to the database.source(number|table) - Player’s server ID or PlayerData tableoffline(boolean) - If true, source parameter is PlayerData object
Player inventories are auto-saved every 5 minutes by rsg-core. Manual saves are only needed for special cases.
Set Inventory
Sets the entire inventory of a player.source(number) - Player’s server IDitems(table) - Complete items table
Clear Inventory
Clears all items from a player’s inventory, with optional filter.source(number) - Player’s server IDfilterItems(string|table|nil) - Items to keep (optional)
This function is commonly used for jail systems or admin commands
Item Management Functions
Add Item
Adds an item to a player’s inventory or another inventory.identifier(number|string) - Player source, stash ID, or drop IDitem(string) - Item nameamount(number) - Quantity to addslot(number|nil) - Specific slot (optional, auto-finds if nil)info(table|nil) - Item metadata (optional)reason(string|nil) - Reason for logging (optional)
boolean - True if successful, false if failed
Example:
If inventory is full, the item will automatically be dropped on the ground near the player!
Remove Item
Removes an item from a player’s inventory.identifier(number|string) - Player source, stash ID, or drop IDitem(string) - Item nameamount(number) - Quantity to removeslot(number|nil) - Specific slot (optional, removes from any if nil)reason(string|nil) - Reason for logging (optional)isMove(boolean|nil) - Internal flag for item moves (optional)
boolean - True if successful, false if failed
Example:
Has Item
Checks if a player has a specific item or items.source(number) - Player’s server IDitems(string|table) - Item name or array of itemsamount(number|nil) - Required amount (optional)
boolean - True if player has the item(s)
Example:
When checking multiple items, ALL items must be present for the function to return true
Get Item Count
Gets the total count of a specific item or items.source(number) - Player’s server IDitems(string|table) - Item name or array of item names
number - Total count of items
Example:
Get Item By Name
Gets the first item with a specific name from inventory.source(number) - Player’s server IDitem(string) - Item name
table|nil - Item data or nil
Example:
Get Items By Name
Gets all items with a specific name from inventory.source(number) - Player’s server IDitem(string) - Item name
table - Array of item data
Example:
Useful for unique items like weapons where a player might have multiple
Get Item By Slot
Gets an item from a specific slot.source(number) - Player’s server IDslot(number) - Slot number
table|nil - Item data or nil
Example:
Set Item Data
Sets a specific key-value pair in an item’s data.source(number) - Player’s server IDitemName(string) - Item namekey(string) - Data key to setval(any) - Value to set
boolean - True if successful
Example:
Slot & Weight Functions
Get Slots
Gets the number of used and free slots for an inventory.identifier(number|string) - Player source, stash ID, or drop ID
number, number - Used slots, Free slots
Example:
Get Slots By Item
Gets all slot numbers that contain a specific item.items(table) - Items table (PlayerData.items)itemName(string) - Item name to search for
table - Array of slot numbers
Example:
Get First Slot By Item
Gets the first slot number containing a specific item.items(table) - Items table (PlayerData.items)itemName(string) - Item name
number|nil - Slot number or nil
Example:
Get Total Weight
Gets the total weight of all items in an inventory.items(table) - Items table
number - Total weight in grams
Example:
Get Free Weight
Gets the available weight capacity for a player.source(number) - Player’s server ID
number - Free weight in grams
Example:
Get Item Weight
Gets the weight of a specific item from the item definition.itemName(string) - Item name
number|nil - Item weight or nil
Example:
Can Add Item
Checks if an item can be added to an inventory.source(number|string) - Player source or stash IDitem(string) - Item nameamount(number) - Quantity
boolean, string|nil - Can add, Reason if false
Example:
Always check before adding items to provide proper feedback to players!
Stash Functions
Open Inventory
Opens an inventory (player, stash, or drop) for a player.source(number) - Player’s server IDidentifier(string|nil) - Stash/drop ID (nil for player inventory)data(table|nil) - Stash configuration (optional)
Close Inventory
Closes an open inventory for a player.source(number) - Player’s server IDidentifier(string|nil) - Stash/drop ID (optional)
Open Inventory By ID
Opens another player’s inventory (for searching/robbing).source(number) - Viewer’s server IDtargetId(number) - Target player’s server ID
Create Inventory
Creates or updates a stash inventory.identifier(string) - Unique stash IDdata(table) - Stash configuration
Delete Inventory
Deletes a stash inventory from memory.identifier(string) - Stash ID
boolean - True if deleted
Example:
Clear Stash
Clears all items from a stash and updates the database.identifier(string) - Stash ID
Save Stash
Manually saves a stash to the database.identifier(string) - Stash ID
Stashes are automatically saved when closed. Manual save is rarely needed.
Get Inventory
Gets a stash inventory data.identifier(string) - Stash ID
table|nil - Inventory data or nil
Example:
Utility Functions
Use Item
Triggers the usage of an item (calls the useable item callback).itemName(string) - Item name...- Additional arguments passed to callback
Force Drop Item
Forces an item to be dropped on the ground (used when inventory is full).source(number) - Player’s server IDitem(string) - Item nameamount(number) - Quantityinfo(table) - Item metadatareason(string) - Reason for logging
number|boolean - Network ID of drop or false
Example:
Complete Examples
Example 1: Crafting System
Example 2: Shop System
Example 3: Gang Stash with Logs
Best Practices Summary
Provide reasons: Always include reason parameter for audit logs
Common Patterns
- Always validate before actions:
- Check capacity before adding:
- Handle failures gracefully:
- Use proper logging:
For more information, see: