Campaign Dealer
Vehicle and item stock management for campaign dealer/vendor locations. Tracks purchasable inventory with add/remove/buy operations and campaign save/resume support.
Vehicle and item stock management for campaign dealer/vendor locations. Tracks purchasable inventory with add/remove/buy operations and campaign save/resume support.
Overview
Maintains a stock inventory keyed by item type (e.g., $$$_VEHICLES). Supports both table-based items (vehicles with model/config) and numeric items (currency). Integrates with the campaign save system for persistence.
Public API
| Function | Args | Returns | Description |
|---|---|---|---|
M.addToStock | itemType, valueObj | - | Adds an item to stock (table) or increments count (number) |
M.getStock | itemType | table | Returns a deep copy of stock for the given item type |
M.removeFromStock | itemType, valueObj | - | Removes a matching item from stock or decrements count |
M.buy | itemType, index | - | Purchase stub (not implemented) |
M.onSerialize | - | table | Returns deep copy of dealer state |
M.onDeserialized | data | - | Logs deserialization (state not restored here) |
M.onSaveCampaign | saveCallback | - | Provides dealer state for campaign save |
M.onResumeCampaign | campaignInProgress, data | - | Restores dealer state from save data |
Stock Structure
M.state.stock = {
["$$$_VEHICLES"] = {
{ model = "pickup", config = "configs/pickup_stock.pc" },
{ model = "coupe", config = "configs/coupe_sport.pc" }
},
["$$$_MONEY"] = 5000 -- Numeric stock type
}Item Operations
-- Add a vehicle to dealer stock
campaign_dealer.addToStock("$$$_VEHICLES", { model = "pickup", config = "stock.pc" })
-- Get available vehicles (returns deep copy)
local vehicles = campaign_dealer.getStock("$$$_VEHICLES")
-- Remove after purchase
campaign_dealer.removeFromStock("$$$_VEHICLES", { model = "pickup", config = "stock.pc" })
-- Numeric items
campaign_dealer.addToStock("$$$_MONEY", 1000)
campaign_dealer.removeFromStock("$$$_MONEY", 500)Duplicate Detection
For table items, existItem checks if an identical entry already exists by comparing all key-value pairs:
-- Will not add duplicate if model+config already in stock
campaign_dealer.addToStock("$$$_VEHICLES", { model = "pickup", config = "stock.pc" })Notes
- Item type keys are uppercased internally (
string.upper) - The
buyfunction is a stub - purchase logic is handled incampaign_exploration.uiEventSelectVehicle - Table items are matched by
model+configfor removal - Stock persists across campaign saves via
onSaveCampaign/onResumeCampaign - Uses
deepcopyfor serialization to prevent reference issues goto continuepattern is used for early loop exit
See Also
- Campaign System - Overall campaign orchestration
- Campaign Exploration - Vendor/garage UI integration
Campaign Comics
Comic/cutscene playback system for campaign narrative sequences. Displays Spine-animated comic panels with background audio between campaign scenarios.
Campaign Exploration
Free-roam exploration mode between campaign scenarios. Manages trigger zones, location markers, road navigation, minimap UI, vehicle spawning, and transitions between exploration and scenarios.