C2 Vehicle Manager
Real-time vehicle data streaming plugin for the C2 WebSocket system. Subscribers receive position, rotation, and velocity updates each frame.
Real-time vehicle data streaming plugin for the C2 WebSocket system. Subscribers receive position, rotation, and velocity updates each frame.
Overview
WebSocket panel plugin that streams vehicle telemetry to connected peers. Supports single-vehicle (player) subscriptions and all-vehicle broadcasts including traffic/parked status detection.
Public API
| Function | Args | Returns | Description |
|---|---|---|---|
M.onC2WebSocketHandlerMessage | params | - | Handles subscribe/unsubscribe WebSocket messages |
M.onUpdate | dt | - | Sends vehicle data to all active subscribers each frame |
WebSocket Messages (Inbound)
| Message Type | Fields | Description |
|---|---|---|
subscribePlayer | vid (optional) | Subscribe peer to a specific vehicle (default: player 0) |
subscribeAllVehicles | - | Subscribe peer to all vehicle data |
unsubscribePlayer | - | Unsubscribe peer from vehicle data |
WebSocket Messages (Outbound)
| Message Type | Fields | Description |
|---|---|---|
playerData | pos, rot, vel, isPlayer, isTraffic, isParked | Single vehicle data (legacy format) |
allVehiclesData | vehicles[] | Array of all vehicle data objects |
Vehicle Data Fields
| Field | Type | Description |
|---|---|---|
id | number | Vehicle object ID |
pos | {x, y, z} | World position |
rot | {x, y, z, w} | Quaternion rotation (computed from direction + up vectors) |
vel | {x, y, z} | Velocity vector |
isPlayer | boolean | Whether this is the player's active vehicle |
isTraffic | boolean | Whether vehicle is AI traffic (via gameplay_traffic) |
isParked | boolean | Whether vehicle is parked (via gameplay_parking) |
Usage Example
-- Subscribe to player vehicle via WebSocket:
-- Send: {"type": "subscribePlayer", "vid": 12345}
-- Receive each frame: {"type": "playerData", "pos": {...}, "rot": {...}, ...}
-- Subscribe to all vehicles:
-- Send: {"type": "subscribeAllVehicles"}
-- Receive: {"type": "allVehiclesData", "vehicles": [{...}, {...}]}Notes
- Data is only gathered when there are active subscribers (performance optimization)
- If any subscriber wants all vehicles, the full vehicle list is fetched once and shared
- Duplicate vehicle data is avoided when multiple peers watch the same vehicle
- Traffic detection uses
gameplay_traffic.getTrafficList() - Parking detection uses
gameplay_parking.getParkedCarsData() - Rotation is computed from
getDirectionVectorXYZ()andgetDirectionVectorUpXYZ() - Sends are wrapped in
pcallfor resilience against disconnected peers
See Also
- C2 WebSocket Handler - WebSocket server routing
- C2 Tile Manager - Scene tile data streaming
C2 Tile Manager
Spatial hash tile index for scene objects, forest items, decals, road markings, and AI graph nodes. Provides tile-based scene queries with debug visualization and WebSocket data export.
Campaign System
Core campaign orchestration module. Manages campaign lifecycle, scenario sequencing, location status tracking, rewards, achievements, and UI flow between campaign scenarios and exploration.