Introduction
The RSG Inventory system features a sophisticated time-based decay mechanism that simulates realistic item deterioration. Food spoils, materials degrade, and items lose quality over time - adding depth and realism to your RedM economy and encouraging active gameplay. Version: 2.7.3+ (Updated November 2024)Item decay runs automatically on the server-side based on real-world time, not playtime. You can now control whether items decay offline!
New in v2.7.3: Offline decay control, custom stash decay rates, and default item metadata!
Core Features
📉 Quality-Based Degradation
- Quality Range: 0-100 (100 = perfect condition, 0 = destroyed)
- Linear Decay: Predictable degradation over time
- Item-Specific Rates: Each item defines its own decay speed
- Passive System: Automatic calculation, no manual intervention needed
🔄 Automatic Management
- Auto-Calculation: Decay computed on inventory load and item use
- Auto-Deletion: Items at 0% quality are automatically removed (optional)
- Timestamp Tracking: Uses Unix timestamps for accuracy
- Offline Decay Control: NEW! Configure whether items decay while player is offline
🎯 Flexible Configuration
- Per-Item Control: Each item has its own decay rate
- Optional Deletion: Choose whether items delete at 0% quality
- No Decay Option: Items without
decayproperty never degrade - Quality Info: Quality stored in item metadata for access
- Stash Decay Rates: NEW! Custom decay rates for specific stashes (coolers, freezers, etc.)
- Default Metadata: NEW! Set default item info values in item definitions
How It Works
Decay Calculation Formula
The system uses a linear decay formula with optional modifiers:- Time Elapsed: Calculate seconds since last update
- Base Decay Rate: Convert minutes to per-second decay rate
- Decay Rate Modifier: Apply stash-specific multiplier (default: 1.0)
- New Quality: Subtract modified decay from current quality (minimum 0)
1.0= Normal decay (100%)0.3= Slow decay (30% of normal) - refrigerator0.0= No decay (0%) - freezer50.0= Fast decay (5000% of normal) - composter
Decay Timeline Example
Item withdecay = 300 (5 hours):
- Decay rate: 100 / (300 * 60) = 0.00556% per second
- After 1 hour (3600s): 100 - (3600 × 0.00556) = 80%
- After 5 hours (18000s): 100 - (18000 × 0.00556) = 0%
Item Configuration
Item Definition Structure
Items with decay are defined inrsg-core/shared/items.lua:
Decay Properties
Items without a
decay property never lose quality and last forever.Decay Configuration
Offline Decay Setting
Configure whether items decay when players are offline inrsg-inventory/shared/config.lua:
false (recommended):
- Items only decay when player is online and playing
- More forgiving for casual players
- Prevents logging in to spoiled food after a few days offline
- Decay timer pauses when player disconnects
true:
- Items decay based on real-world time
- More realistic simulation
- Encourages regular login to manage inventory
- Food spoils even when offline
Default Item Metadata
You can now define default metadata for items inrsg-core/shared/items.lua:
info values are automatically included:
This dramatically simplifies item creation and ensures consistent metadata across all instances of an item type!
Custom Stash Decay Rates
Decay Rate Naming System
You can control decay rates for specific stashes using a special naming pattern:- Base stash name
- Followed by
-decayor_decay - Followed by percentage number (0-100+ allowed)
basement69-decay30→ 30% decay rate (slower)freezer111_decay0→ 0% decay rate (no decay)refrigerator_decay20→ 20% decay rate (very slow)composter333decay5000→ 5000% decay rate (50x faster!)
How Decay Rates Work
The percentage modifies the base decay rate:Practical Examples
Example 1: Freezer (No Decay)
Example 2: Refrigerator (Slow Decay)
- Normal bread lasts 5 hours
- Bread in fridge lasts 25 hours (5 ÷ 0.20)
Example 3: Root Cellar (Moderate Decay)
- Normal bread lasts 5 hours
- Bread in cellar lasts 10 hours
Example 4: Composter (Accelerated Decay)
- Normal bread takes 5 hours to decay
- Bread in composter decays in 6 minutes (5 hours ÷ 50)
- Use for converting organic matter to compost quickly
Example 5: Dynamic Decay Rates
Decay Rate Comparison Table
Decay Rate Guidelines
Fast Decay (Perishables)
Use for: Fresh food, organic materials, perishable goodsMedium Decay (Cooked Food)
Use for: Prepared meals, baked goods, processed foodSlow Decay (Durables)
Use for: Tools, medicine, preserved goodsNo Decay (Permanent)
Use for: Money, valuables, crafting materials, toolsQuality Metadata
Item Info Structure
Every item with decay has quality tracking in itsinfo table:
Initial Quality Assignment
When items are added without quality info, the system initializes it automatically:Manual Quality Setting
Decay Functions
CheckItemDecay
Manually check and update an item’s decay.item(table) - Item object with info tableitemInfo(table|nil) - Item definition from RSGCore.Shared.Items (optional)currentTime(number|nil) - Unix timestamp (optional, defaults to os.time())decayRateModifier(number|nil) - Decay rate multiplier (optional, defaults to 1.0)
shouldUpdate(boolean) - Whether item metadata was changednewQuality(number|nil) - New quality value after decayshouldDelete(boolean) - Whether item should be removed
CheckPlayerItemsDecay
Check and update all items in a player’s inventory.player(table) - Player object from RSGCore.Functions.GetPlayer
This function is automatically called when inventory is loaded. Manual calls are rarely needed.
CheckItemsDecay
Check decay for a table of items (for stashes, drops, etc.).items(table) - Table of items indexed by slotdecayRateModifier(number|nil) - Decay rate multiplier (optional, defaults to 1.0)
needsUpdate(boolean) - Whether any items were updatedremovedItems(table) - Table of items that should be deleted
Decay Timing
When Decay is Calculated
Decay calculations happen automatically at these times:- Player Login - All inventory items checked when player loads
- Inventory Open - Items checked when opening inventory UI
- Item Use - Individual item checked before use callback
- Stash Open - Stash items checked when accessed
- Drop Pickup - Ground drop items checked when picked up
Decay Check Flow
Quality Thresholds and Effects
Recommended Quality Ranges
Example: Quality-Based Food Effects
Example: Tool Durability
Common Use Cases
Example 1: Portable Cooler with Decay Rate
_decay30 to the stash ID!
Example 2: Quality-Based Pricing
Example 3: Repair System
Example 4: Preservation Items
Example 5: Visual Quality Indicators (Client)
Best Practices
Provide preservation options: Give players ways to maintain items (coolers, repair, preservation)
Design Guidelines
Decay Time Recommendations:- Perishables (Fresh Food): 30 minutes - 2 hours
- Cooked Food: 4 - 12 hours
- Preserved Food: 24 - 72 hours
- Medicine/Consumables: 24 - 48 hours
- Tools/Equipment: 3 - 7 days
- Valuables: No decay (gold, jewelry, money)
- Weapons: Use rsg-weapons durability instead
Testing Decay
Troubleshooting
Items not decaying
Items not decaying
Possible causes:
- Item doesn’t have
decayproperty in shared/items.lua info.lastUpdateis missing (should auto-initialize)- Decay check functions aren’t being called
Items decaying too fast/slow
Items decaying too fast/slow
Possible causes:
- Incorrect
decayvalue (remember: it’s in minutes) - Server time issues or clock skew
- Review decay value:
decay = 60means 1 hour - Use admin test command to verify decay rates
Items not deleting at 0%
Items not deleting at 0%
Possible causes:
delete = falseor missing in item definition- Items not being checked for decay
delete = true and ensure decay checks run on inventory loadQuality showing wrong values
Quality showing wrong values
Possible causes:
- Quality stored as decimal but displayed incorrectly
- lastUpdate timestamp is invalid
- Use
math.floor(quality)for display - Verify lastUpdate is a valid Unix timestamp (os.time())
Offline decay behavior
Offline decay behavior
Configuration: Check
Config.ItemsDecayWhileOffline in rsg-inventoryWhen true (v2.7.3+):- Items decay based on real-world time
- Decay calculated when player logs back in
- Quality reflects total elapsed time
false (recommended):- Items only decay when player is online
- Decay timer pauses on disconnect
- Prevents offline spoilage
Stash decay rates not working
Stash decay rates not working
Possible causes:
- Incorrect stash ID format (use
_decay30or-decay30) - Percentage value missing or malformed
- Using old inventory version (requires v2.7.3+)
- Verify stash ID format:
stashname_decay{NUMBER} - Check inventory version in fxmanifest.lua
- Examples:
freezer_decay0,fridge-decay20
Default metadata not applying
Default metadata not applying
Possible causes:
- Item definition missing
infotable - Using old rsg-core/rsg-inventory version
- Manually providing info that overrides defaults
- Add
info = { key = value }to item definition - Update to rsg-inventory v2.7.3+
- Remember: Provided info merges with defaults
Technical Details
Implementation Location
Decay functions are implemented in:rsg-inventory/server/functions.lua- Core decay calculation logicrsg-inventory/shared/helpers.lua-Helpers.ParseDecayRate()functionrsg-inventory/server/exports.lua- Default metadata mergingrsg-inventory/shared/config.lua-ItemsDecayWhileOfflinesetting
Decay Rate Parsing
Default Metadata Merging
Database Storage
Quality is stored in theinventory column as JSON:
Performance Considerations
- Decay calculations are O(1) per item
- Only calculated when needed (not every frame)
- Minimal performance impact even with many items
- Database writes only on player save (every 5 minutes)
- Stash decay rate parsing is cached (no repeated regex)
Version Compatibility
Next Steps
- Inventory Overview - Complete inventory system guide
- Inventory Functions - All inventory management functions
- Weapons System - Weapon durability (different from item decay)
- Item Configuration - How to define items
Need help? Join the RSG Framework Discord!