Skip to main content

Introduction

The RSG Inventory system (rsg-inventory) is a comprehensive, weight-based inventory management system for RedM. It provides players with persistent inventory storage, item management, drops, stashes, and shops. Version: 2.7.1
RSG Inventory is tightly integrated with rsg-core and rsg-weapons. All three work together to provide a complete item and weapon management system.

Core Features

πŸ“Š Weight & Slot System

  • Weight-Based: Every item has a weight value, and players have a maximum carry capacity
  • Slot-Based: Inventory is divided into slots (default: 25 slots)
  • Configurable: Weight and slots can be adjusted per player via PlayerData

πŸŽ’ Inventory Types

The system supports multiple inventory types:
  1. Player Inventory - Personal inventory for each player
  2. Stashes - Persistent storage locations (houses, gang storage, etc.)
  3. Drops - Ground items that can be picked up
  4. Shops - Vendor inventories for purchasing items

πŸ”„ Item Management

  • Add/Remove Items: Server-side functions to modify inventory
  • Item Transfer: Move items between inventories
  • Item Info: Custom metadata for items (serial numbers, quality, etc.)
  • Item Decay: Time-based item quality degradation

βš”οΈ Weapon Integration

  • Weapons are stored as inventory items with type 'weapon'
  • Weapon-specific data (serial number, quality, ammo) stored in item info
  • Seamless integration with rsg-weapons for durability and repair

How It Works

Item Structure

Every item in the inventory follows this structure:

Weapon Item Structure

Weapons have additional information:

Weight System

How Weight Works

  • Items have a base weight value (in grams)
  • Total weight = item.weight * item.amount
  • Player carry capacity defined in PlayerData.weight (default: 35000g = 35kg)

Example Weight Calculation

If a player’s inventory is full (weight or slots), the system will automatically drop items on the ground instead of deleting them!

Slot System

How Slots Work

  • Each inventory has a maximum number of slots
  • Each item occupies one slot, regardless of quantity
  • Exception: Unique items always take one slot each

Checking Slots


Item Decay System

The inventory supports time-based item quality degradation.

How Decay Works

Items with the decay property in shared/items.lua will lose quality over time:
  • Quality: Ranges from 0-100
  • Decay Rate: Time it takes for quality to reach 0
  • Auto-Remove: Items at 0 quality are automatically removed on inventory load

Quality Effects

  • 100-75%: Fresh/Good condition
  • 74-50%: Decent condition
  • 49-25%: Poor condition
  • 24-1%: Very poor condition
  • 0%: Item is destroyed/unusable
Decayed items (0% quality) are permanently deleted when the inventory is loaded. Players cannot recover them!

Ground Drops

How Drops Work

When items are dropped (or forced out of full inventory), they spawn on the ground as physical objects. Features:
  • Visual Object: A physical bag/satchel spawns at the location
  • Persistence: Drops remain until picked up or server restart
  • Network Synced: All players can see and interact with drops
  • Weight Limit: Drops can hold multiple items up to weight limit

Drop Properties


Stashes

Stashes are persistent storage locations that can be accessed by multiple players (with proper permissions).

Stash Types

  1. Player Stashes: Personal storage (houses, apartments)
  2. Job Stashes: Shared storage for job members
  3. Gang Stashes: Shared storage for gang members
  4. Public Stashes: Accessible by anyone

Stash Properties

Creating a Stash

Opening a Stash


Shops

The shop system allows players to purchase items from vendors.

Shop Features

  • Item Pricing: Each item has a defined price
  • Stock Management: Items can have limited or unlimited stock
  • Job Restrictions: Shops can be restricted to specific jobs
  • Gang Restrictions: Shops can be restricted to specific gangs

Shop Structure

Shops are defined server-side and opened via exports:

Database Storage

Player Inventory

Player inventories are stored in the players table:
The inventory column stores a JSON array of items.

Stash Inventory

Stashes are stored in the inventories table:

Common Use Cases

Example 1: Give Player an Item

Example 2: Remove Item from Player

Example 3: Check Player’s Items

Example 4: Create House Stash


Best Practices

Always check capacity before adding items: Use CanAddItem to prevent errors
Never trust client data: Always validate on server before modifying inventory
Use reasons for logging: Always provide a reason parameter for auditing

Performance Considerations

  1. Batch operations when possible: Don’t add items in a loop, accumulate and add once
  2. Cache item checks: Don’t repeatedly call HasItem for the same item
  3. Clean up stashes: Remove unused stashes to prevent database bloat
  4. Optimize drops: Limit the number of simultaneous drops on the server

Integration with Other Resources

Creating Useable Items

Items can be made useable in rsg-core:

Inventory Events

Listen for inventory events in your resources:

Troubleshooting

Inventory Not Saving

Ensure oxmysql is properly configured and connected
Look in server console for SQL errors or Lua errors
Make sure the item is defined in rsg-core/shared/items.lua

Items Disappearing

Common causes:
  • Item quality reached 0% (decay)
  • Item not defined in shared items
  • Database not saving properly
  • Server crash before save

Inventory Full Errors

When inventory is full:
  • Items are automatically dropped on the ground
  • Check ground drops near player
  • Increase player weight/slots if needed

Next Steps


Need more help? Join the RSG Framework Discord!