Skip to main content

Introduction

This page documents all server-side exports available from rsg-inventory. These functions allow you to interact with player inventories, stashes, and items.
All inventory functions should be called from the server-side only. Client-side inventory manipulation is not supported for security reasons.

Player Inventory Functions

Load Inventory

Loads a player’s inventory from the database.
Parameters:
  • source (number) - Player’s server ID
  • citizenid (string) - Player’s citizen ID
Returns: 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.
Parameters:
  • source (number|table) - Player’s server ID or PlayerData table
  • offline (boolean) - If true, source parameter is PlayerData object
Example:
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.
Parameters:
  • source (number) - Player’s server ID
  • items (table) - Complete items table
Example:
This completely replaces the player’s inventory. Use with caution!

Clear Inventory

Clears all items from a player’s inventory, with optional filter.
Parameters:
  • source (number) - Player’s server ID
  • filterItems (string|table|nil) - Items to keep (optional)
Example:
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.
Parameters:
  • identifier (number|string) - Player source, stash ID, or drop ID
  • item (string) - Item name
  • amount (number) - Quantity to add
  • slot (number|nil) - Specific slot (optional, auto-finds if nil)
  • info (table|nil) - Item metadata (optional)
  • reason (string|nil) - Reason for logging (optional)
Returns: 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.
Parameters:
  • identifier (number|string) - Player source, stash ID, or drop ID
  • item (string) - Item name
  • amount (number) - Quantity to remove
  • slot (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)
Returns: boolean - True if successful, false if failed Example:

Has Item

Checks if a player has a specific item or items.
Parameters:
  • source (number) - Player’s server ID
  • items (string|table) - Item name or array of items
  • amount (number|nil) - Required amount (optional)
Returns: 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.
Parameters:
  • source (number) - Player’s server ID
  • items (string|table) - Item name or array of item names
Returns: number - Total count of items Example:

Get Item By Name

Gets the first item with a specific name from inventory.
Parameters:
  • source (number) - Player’s server ID
  • item (string) - Item name
Returns: table|nil - Item data or nil Example:

Get Items By Name

Gets all items with a specific name from inventory.
Parameters:
  • source (number) - Player’s server ID
  • item (string) - Item name
Returns: 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.
Parameters:
  • source (number) - Player’s server ID
  • slot (number) - Slot number
Returns: table|nil - Item data or nil Example:

Set Item Data

Sets a specific key-value pair in an item’s data.
Parameters:
  • source (number) - Player’s server ID
  • itemName (string) - Item name
  • key (string) - Data key to set
  • val (any) - Value to set
Returns: boolean - True if successful Example:

Slot & Weight Functions

Get Slots

Gets the number of used and free slots for an inventory.
Parameters:
  • identifier (number|string) - Player source, stash ID, or drop ID
Returns: number, number - Used slots, Free slots Example:

Get Slots By Item

Gets all slot numbers that contain a specific item.
Parameters:
  • items (table) - Items table (PlayerData.items)
  • itemName (string) - Item name to search for
Returns: table - Array of slot numbers Example:

Get First Slot By Item

Gets the first slot number containing a specific item.
Parameters:
  • items (table) - Items table (PlayerData.items)
  • itemName (string) - Item name
Returns: number|nil - Slot number or nil Example:

Get Total Weight

Gets the total weight of all items in an inventory.
Parameters:
  • items (table) - Items table
Returns: number - Total weight in grams Example:

Get Free Weight

Gets the available weight capacity for a player.
Parameters:
  • source (number) - Player’s server ID
Returns: number - Free weight in grams Example:

Get Item Weight

Gets the weight of a specific item from the item definition.
Parameters:
  • itemName (string) - Item name
Returns: number|nil - Item weight or nil Example:

Can Add Item

Checks if an item can be added to an inventory.
Parameters:
  • source (number|string) - Player source or stash ID
  • item (string) - Item name
  • amount (number) - Quantity
Returns: 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.
Parameters:
  • source (number) - Player’s server ID
  • identifier (string|nil) - Stash/drop ID (nil for player inventory)
  • data (table|nil) - Stash configuration (optional)
Data Table:
Example:

Close Inventory

Closes an open inventory for a player.
Parameters:
  • source (number) - Player’s server ID
  • identifier (string|nil) - Stash/drop ID (optional)
Example:

Open Inventory By ID

Opens another player’s inventory (for searching/robbing).
Parameters:
  • source (number) - Viewer’s server ID
  • targetId (number) - Target player’s server ID
Example:

Create Inventory

Creates or updates a stash inventory.
Parameters:
  • identifier (string) - Unique stash ID
  • data (table) - Stash configuration
Example:

Delete Inventory

Deletes a stash inventory from memory.
Parameters:
  • identifier (string) - Stash ID
Returns: boolean - True if deleted Example:
This only removes from memory, not the database! Use ClearStash to empty it.

Clear Stash

Clears all items from a stash and updates the database.
Parameters:
  • identifier (string) - Stash ID
Example:

Save Stash

Manually saves a stash to the database.
Parameters:
  • identifier (string) - Stash ID
Example:
Stashes are automatically saved when closed. Manual save is rarely needed.

Get Inventory

Gets a stash inventory data.
Parameters:
  • identifier (string) - Stash ID
Returns: table|nil - Inventory data or nil Example:

Utility Functions

Use Item

Triggers the usage of an item (calls the useable item callback).
Parameters:
  • itemName (string) - Item name
  • ... - Additional arguments passed to callback
Example:

Force Drop Item

Forces an item to be dropped on the ground (used when inventory is full).
Parameters:
  • source (number) - Player’s server ID
  • item (string) - Item name
  • amount (number) - Quantity
  • info (table) - Item metadata
  • reason (string) - Reason for logging
Returns: 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

Check before modifying: Always use HasItem, CanAddItem before operations
Server-side only: Never attempt inventory operations on client
Provide reasons: Always include reason parameter for audit logs

Common Patterns

  1. Always validate before actions:
  1. Check capacity before adding:
  1. Handle failures gracefully:
  1. Use proper logging:

For more information, see: