Core Checkpoints
Manages vehicle checkpoint saving and restoration for scenario races. Tracks waypoint progress, saves vehicle position/direction at each checkpoint, and handles automated AI vehicle resets when stuck.
Manages vehicle checkpoint saving and restoration for scenario races. Tracks waypoint progress, saves vehicle position/direction at each checkpoint, and handles automated AI vehicle resets when stuck.
Overview
The checkpoint system saves vehicle state (position, direction, up vector) when waypoints are reached during races. Players and AI can be reset to their last checkpoint. AI vehicles are automatically reset if stationary for 4+ seconds after leaving the start. Integrates with scenario_waypoints for race progress tracking.
Module State
| Field | Type | Description |
|---|---|---|
state.vehicleCheckpoints | table | Vehicle ID → checkpoint data |
state.aiVehiclePath | table | Vehicle ID → remaining AI path |
Public Functions
| Function | Signature | Description |
|---|---|---|
saveCheckpoint | (vehicleId, vehicleName, cpData) | Save position/direction for a vehicle |
saveAIPath | (vehicleName, arg) | Store AI path waypoints for a vehicle |
completeReset | (vehicleId, vehicleName) | Finalize reset - restore AI path, update waypoint data |
onRaceWaypointReached | (data) | Save checkpoint when waypoint is crossed |
onPreRender | (dt) | Check for stuck AI vehicles (every 4s) |
onVehicleSpawned | (vehId) | Initialize checkpoint data for new vehicles |
onVehicleDestroyed | (vid) | Remove checkpoint data |
onScenarioRestarted | (scenario) | Reset all data, reinitialize all vehicles |
onClientPreStartMission | (levelPath) | Clear data on mission start |
onClientEndMission | (levelPath) | Clear data on mission end |
onSerialize | () | Serialize state (vehicle name keys) |
onDeserialized | (data) | Deserialize state (restore vehicle ID keys) |
onSaveCampaign | (saveCallback) | Save checkpoint data for campaign |
onResumeCampaign | (campaignInProgress, data) | Restore from campaign save |
Checkpoint Data Structure
vehicleCheckpoints[vehicleId] = {
vehicleName = "vehicle_name",
checkTimer = 0, -- AI stuck detection timer
pos = vec3(), -- saved position
dirVec = vec3(), -- saved direction vector
upVec = vec3(), -- saved up vector
currentWpName = "wp_name", -- current waypoint name
currentWpIndex = 3, -- current waypoint index
nextWpIndex = 4, -- next waypoint index
initialPos = vec3(), -- spawn position (for AI stuck detection)
raceOver = false, -- vehicle finished the race
}Vehicle Reset Flow
-- 1. Reset vehicle to saved checkpoint
vehicle:resetBrokenFlexMesh()
vehicle:setPositionRotation(pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, rot.w)
-- 2. Queue autoplace + callback via round-trip through vehicle Lua
obj:queueGameEngineLua("getObjectByID(id):autoplace(false); core_checkpoints.completeReset(id, name)")
-- 3. completeReset restores AI path and updates waypoint tracking
helper.setAiPath(aiVehiclePath[vehicleId])
scenario_waypoints.updateResetVehicleData(vehicleId, currentWpIndex, nextWpIndex)AI Stuck Detection
-- Every 4 seconds, check if AI vehicle has moved
if (vehPos - data.prevVehPos):squaredLength() < 0.0016 then
-- Vehicle moved less than 4cm in 4 seconds → reset to checkpoint
ResetToSavedCheckpoint(vehicle, data.vehicleName)
endKey Notes
- Only active when scenario has
enableCheckpointsandlapConfigwith 2+ points - Checkpoint direction uses waypoint direction (directional WP) or vehicle velocity
- Serialization converts vehicle ID keys ↔ vehicle name keys for save compatibility
- Uses
convertVehicleIdKeysToVehicleNameKeys/convertVehicleNameKeysToVehicleIdKeys - AI vehicles skip stuck detection until they've left their initial position
- Race completion sets
raceOver = trueto prevent AI resets after finishing M.state- Table. Checkpoint state ({vehicleCheckpoints = {}}).M.onVehicleSpawned(id)- Hook: vehicle spawned.M.onVehicleDestroyed(id)- Hook: vehicle destroyed.M.onClientPreStartMission()- Hook: before mission start.M.onClientEndMission()- Hook: mission ended.M.completeReset(vehicleId, vehicleName)- Fully resets checkpoint state for a vehicle.M.onRaceWaypointReached(data)- Hook: race waypoint reached.M.onSerialize()- Serializes checkpoint state for save.M.onDeserialized(data)- Restores checkpoint state from save.M.onScenarioRestarted()- Hook: scenario restarted.M.onPreRender(dtReal, dtSim, dtRaw)- Hook: pre-render update.M.onSaveCampaign()- Hook: campaign save.M.onResumeCampaign()- Hook: campaign resumed.M.saveCheckpoint(vehicleId, vehicleName, cpData)- Saves a checkpoint for the given vehicle.M.saveAIPath(vehicleName, arg)- Saves the AI path for a vehicle.
Core Chat (IRC)
IRC-based in-game chat system connecting to `irc.beamng.com`. **Currently disabled** - the entire module is wrapped in a block comment.
Core Command Handler
Handles `beamng:` URL scheme commands for mod management, map loading, toolchain, debugger control, and other async tasks triggered via protocol URLs or startup arguments.