Inventory
Simple key-value inventory system for tracking items (vehicles, parts, currency) during campaigns/scenarios. Supports adding, removing, and querying items by type, with campaign save/resume hooks.
Simple key-value inventory system for tracking items (vehicles, parts, currency) during campaigns/scenarios. Supports adding, removing, and querying items by type, with campaign save/resume hooks.
Public Functions
| Function | Signature | Description |
|---|---|---|
M.addItem | (itemType, valueObj) | Adds an item - numeric values accumulate, table values are appended if unique |
M.removeItem | (itemType, valueObj) | Removes an item - numeric values subtract, table entries matched by model+config |
M.getItem | (itemType, itemId) → item | Gets a single item by type and itemId, or the numeric total |
M.getItemList | (itemType) → table | Returns a deep copy of all items for a given type |
M.processOnEvent | (onEventData, earnedMedal) | Processes add/remove operations from event reward data |
M.onSaveCampaign | (saveCallback) | Serializes inventory for campaign save |
M.onResumeCampaign | (campaignInProgress, data) | Restores inventory from campaign data |
M.onSerialize | () → table | Returns deep copy of items table for serialization |
M.onDeserialized | (data) | Called on deserialization (no-op) |
M.itemsTable | Table. Stores all inventory items. |
Item Storage
| Item Type | Value Type | Behavior |
|---|---|---|
Numeric (e.g. "$$$_MONEY") | number | Accumulated via addition/subtraction |
Table (e.g. "$$$_VEHICLE") | table | Stored as array of unique objects |
Item types are automatically uppercased. The processTable helper prefixes keys with $$$_.
Module State
| Variable | Type | Default |
|---|---|---|
itemsTable | table | {} |
Usage Example
-- Add currency
core_inventory.addItem("$$$_MONEY", 200)
-- Add a vehicle to inventory
core_inventory.addItem("$$$_VEHICLE", {
model = "etk800",
config = "etk800_m",
color = "1 1 1 1"
})
-- Check currency balance
local balance = core_inventory.getItem("$$$_MONEY")
print("Balance: " .. balance)
-- Remove a vehicle
core_inventory.removeItem("$$$_VEHICLE", {
model = "etk800",
config = "etk800_m"
})
-- Get all vehicles
local vehicles = core_inventory.getItemList("$$$_VEHICLE")Event Processing
The processOnEvent function handles structured reward data with optional medal-based branching:
-- Medal-dependent rewards
local eventData = {
remove = {
gold = {
vehicles = {{model = "pickup", config = "v8_4wd_rusty"}},
money = 2500
}
}
}
core_inventory.processOnEvent(eventData, "gold")Notes
- Duplicate detection for table items compares all key-value pairs.
- Table items are removed by matching
modelandconfigfields specifically. - This is a legacy/scenario inventory system - career mode uses
career_modules_inventory.
See Also
- globals - Core engine API
Hotlapping
Full hotlapping / lap timing system. Supports creating custom circuits in freeroam (edit mode), running timed laps with checkpoint splits, best-lap tracking, and integration with both the old scenario
Job System
Coroutine-based job system for running background tasks without blocking the game. Jobs yield control back to the engine periodically, allowing frame rendering to continue during long operations.