API ReferenceGE Extensionscorevehicle
Vehicle Manager
Central vehicle lifecycle manager: spawning, loading, physics, colors, and data access.
Central vehicle lifecycle manager: spawning, loading, physics, colors, and data access.
Overview
Extension: core_vehicle_manager - The primary vehicle management system. Handles the C++ spawn callback, JBeam loading (stage 1), physics initialization, material loading, vehicle data storage, color/paint updates, and debug tooling.
Public Functions
| Function | Description |
|---|---|
M.getPlayerVehicleData() | Returns the vehicle bundle for player 0 |
M.getVehicleData(id) | Returns the vehicle bundle for any vehicle ID |
M.spawnPhysicsForVehicle(objID, vehicleObj, vehicleBundle) | Sends vehicle data to physics engine |
M.liveUpdateVehicleColors(objID, vehicleObj, index, paint) | Applies paint to vehicle object and emits hook |
M.setVehicleColorsNames(id, paintNames, optional) | Sets paints by name from model paint definitions |
M.queueAdditionalVehicleData(data, vehId) | Queues extra data to be included in next spawn |
M._spawnCCallback(objID, vehicleDir, configDataIn, reloading) | Internal: C++ spawn callback |
M.reloadVehicle(playerId) | Reloads player vehicle |
M.reloadAllVehicles() | Reloads all vehicles |
M.toggleModifyKey() | Toggles the in-place edit window |
M.getDebug() / M.setDebug(enabled) / M.toggleDebug() | Debug spawn mode |
M.setVehiclePaintsNames(id, paintNames, optional) | Alias for setVehicleColorsNames |
Event Handlers
| Handler | Description |
|---|---|
M.onVehicleSwitched(oldID, newID, player) | Tracks active player, releases clutch |
M.onDespawnObject(id, isReloading) | Clears vehicle data unless reloading |
M.onClientEndMission() | Invalidates materials cache |
M.onFileChanged(filename, type) | Invalidates JBeam/material caches |
M.onSerialize() / M.onDeserialized(data) | Persists vehicle data across Lua reloads |
M.onUpdate() | Clears spawn cache each frame |
Vehicle Bundle Structure
Returned by getVehicleData():
{
vdata = { ... }, -- JBeam processed vehicle data
config = {
parts = {}, -- part slot assignments
paints = {}, -- paint table (up to 3 slots)
partConfigFilename = "" -- source config path
},
mainPartName = "...", -- root JBeam part name
chosenParts = {}, -- slot → part name mapping
activePlayer = 0, -- active player index (or nil)
ioCtx = { ... } -- JBeam I/O context
}Spawn Flow
- C++ calls
_spawnCCallback(objID, vehicleDir, configData) - Materials loaded from vehicle directory +
/vehicles/common/ - Config built via
core_vehicle_partmgmt.buildConfigFromString() - JBeam stage 1 loaded via
jbeam/loader.loadVehicleStage1() vehicleObj:finishConstructionGESide()completes mesh setupspawnPhysicsForVehicle()sends data to physics (unlessNoPhysics)- Vehicle auto-entered if
autoEnterVehiclenot"false"
Usage Examples
-- Get player vehicle data
local vd = core_vehicle_manager.getPlayerVehicleData()
if vd then
log('I', '', 'Vehicle: ' .. tostring(vd.vdata.vehicleDirectory))
end
-- Live update paint
local paint = createVehiclePaint({x=1, y=0, z=0, w=1}, {})
core_vehicle_manager.liveUpdateVehicleColors(vehId, nil, 1, paint)
-- Reload current vehicle
core_vehicle_manager.reloadVehicle(0)Hooks Emitted
| Hook | When |
|---|---|
onSpawnCCallback | During spawn, before JBeam loading |
onVehicleColorChanged | After live color update |
Editor Integration
| Handler | Description |
|---|---|
M.onEditorInitialized() | Registers the Vehicle Manager editor window |
M.onEditorGui() | Renders obsolete editor window with deprecation notice |
Module Properties
| Property | Default | Description |
|---|---|---|
M.autoSpawnPhysics | true | Whether physics auto-starts on spawn |
See Also
- Vehicle Colors - Color/paint utilities
- Vehicle In-Place Edit - Part editing tool
- Vehicle Mirror - Mirror angle management