Vehicle-related events and callbacks for managing vehicle state and interactions
The Vehicles system provides events for vehicle lifecycle management, key synchronization, vehicle state changes, and player interactions with vehicles.
Triggered when client sends vehicle properties after first spawn.Parameters:
Name
Type
Description
veh
number
Vehicle entity ID
properties
table
Vehicle customization properties
Example:
-- Server sideRegisterNetEvent('Vehicles:Server:PlayerSetProperties', function(veh, properties) -- Framework handles this automatically -- Properties are saved to vehicle database recordend)
Notes:
Automatically triggered by framework when vehicle spawns without saved properties
Do not trigger manually unless creating custom vehicle spawning logic
Prevent a temporary vehicle from despawning.Parameters:
Name
Type
Description
vNet
number
Vehicle network ID
Example:
-- Client sidelocal vehicle = GetVehiclePedIsIn(PlayerPedId(), false)local vNet = NetworkGetNetworkIdFromEntity(vehicle)TriggerServerEvent('Vehicles:Server:StopDespawn', vNet)-- Server will keep the vehicle from despawning when player leaves
-- Client sideRegisterNetEvent('Vehicles:Client:UpdateKeys', function(keys) -- Update local keys table _vehicleKeys = keys -- Check if player has specific key if keys['ABC123456789'] then print('Player has keys to this vehicle') endend)
Seat index to switch to (-1=driver, 0=front passenger, etc.)
Example:
-- Server side - Move player to driver seatTriggerClientEvent('Vehicles:Client:Actions:SwitchSeat', source, -1)-- Move to back seatTriggerClientEvent('Vehicles:Client:Actions:SwitchSeat', source, 1)
-- Server side-- Open specific doorTriggerClientEvent('Vehicles:Client:Actions:ToggleDoor', source, 0) -- Front left-- Open all doorsTriggerClientEvent('Vehicles:Client:Actions:ToggleDoor', source, 'open')-- Close all doorsTriggerClientEvent('Vehicles:Client:Actions:ToggleDoor', source, 'shut')
Door Indices:
0 = Front Left Door1 = Front Right Door2 = Rear Left Door3 = Rear Right Door4 = Hood5 = Trunk
-- Server side-- Roll down driver windowTriggerClientEvent('Vehicles:Client:Actions:ToggleWindow', source, 0)-- Roll down all windowsTriggerClientEvent('Vehicles:Client:Actions:ToggleWindow', source, 'open')-- Roll up all windowsTriggerClientEvent('Vehicles:Client:Actions:ToggleWindow', source, 'shut')
-- Client sideRegisterNetEvent('Vehicles:Client:ToggleAnchor', function(vNet, toggle) local boat = NetworkGetEntityFromNetworkId(vNet) if DoesEntityExist(boat) then -- Set anchor state if toggle then print('Anchor dropped') else print('Anchor raised') end endend)
-- Client sideRegisterNetEvent('VehicleSync:Client:SyncNeons', function(veh, state) local vehicle = NetworkGetEntityFromNetworkId(veh) if DoesEntityExist(vehicle) then -- Enable/disable neons for i = 0, 3 do SetVehicleNeonLightEnabled(vehicle, i, state) end endend)
-- Client sideRegisterNetEvent('VehicleSync:Client:BodyRepair', function(vNet) local vehicle = NetworkGetEntityFromNetworkId(vNet) if DoesEntityExist(vehicle) then -- Play repair effects -- Update vehicle body damage endend)
-- Client sideAddEventHandler('Vehicles:Client:SwitchVehicleSeat', function(vehicle, seat, class) print('Switched to seat:', seat) -- Update UI based on seat if seat == -1 then -- Now driver else -- Now passenger endend)
Triggered when vehicle ignition state changes.Parameters:
Name
Type
Description
state
boolean
Ignition state (true=on, false=off)
Example:
-- Client sideAddEventHandler('Vehicles:Client:Ignition', function(state) if state then print('Engine started') -- Show engine on indicator else print('Engine stopped') -- Show engine off indicator endend)
Triggered when cruise control state changes.Parameters:
Name
Type
Description
state
boolean/number
Cruise control (false=off, number=speed)
Example:
-- Client sideAddEventHandler('Vehicles:Client:Cruise', function(state) if state then print('Cruise control set to:', state, 'MPH') -- Show cruise control indicator else print('Cruise control disabled') -- Hide cruise control indicator endend)
-- Client sideCallbacks:ServerCallback('Vehicles:GetVehiclesInStorage', 'legion_square', function(vehicles) if vehicles then print('Found', #vehicles, 'vehicles in garage') for k, v in ipairs(vehicles) do print(v.Make, v.Model, v.RegisteredPlate) end endend)
Get vehicles stored in property garage.Parameters:
Name
Type
Description
storageId
string
Property identifier
Returns:
Type
Description
table/boolean
Vehicle data, capacity, character ID, character info
Example:
-- Client sideCallbacks:ServerCallback('Vehicles:GetVehiclesInPropertyStorage', 'property_123', function(vehicles, capacity, charId, charInfo) if vehicles then print('Property has', capacity.current, '/', capacity.max, 'vehicles') for k, v in ipairs(vehicles) do local ownerInfo = charInfo[v.Owner.Id] print(v.Make, v.Model, 'owned by', ownerInfo.First, ownerInfo.Last) end endend)
-- Server sideAddEventHandler('rental:server:RentVehicle', function(vehicleModel, duration) local src = source local player = Fetch:Source(src) if not player then return end local char = player:GetData('Character') if not char then return end local stateId = char:GetData('SID') local rentalCost = 500 * duration -- $500 per hour local currentCash = char:GetData('Cash') if currentCash >= rentalCost then char:SetData('Cash', currentCash - rentalCost) local spawnCoords = GetRentalSpawnLocation() Vehicles:SpawnTemp( src, GetHashKey(vehicleModel), spawnCoords.coords, spawnCoords.heading, function(entityId, VIN, plate) -- Give keys Vehicles.Keys:Add(src, VIN) -- Set rental expiry RentalVehicles[VIN] = { entity = entityId, expires = os.time() + (duration * 3600) } TriggerClientEvent('mythic-notifications:client:Send', src, { message = string.format('Vehicle rented for %d hours. Plate: %s', duration, plate), type = 'success' }) end ) endend)
-- Server sideAddEventHandler('jobs:server:SpawnJobVehicle', function() local src = source local player = Fetch:Source(src) if not player then return end local char = player:GetData('Character') if not char then return end if not Jobs.Permissions:HasJob(src, 'police') then return end local jobGarage = 'mrpd_garage' local spawnLocation = GetJobSpawnLocation(jobGarage) -- Get available fleet vehicles Callbacks:ClientCallback(src, 'Vehicles:GetVehiclesInStorage', jobGarage, function(vehicles) if vehicles and #vehicles > 0 then -- Show vehicle selection menu TriggerClientEvent('police:client:ShowFleetMenu', src, vehicles, spawnLocation) end end)end)
-- Client sideAddEventHandler('Vehicles:Client:EnterVehicle', function(vehicle, seat, class) if seat == -1 then -- Driver local vState = Entity(vehicle).state if vState.Damage and (vState.Damage.Engine < 80 or vState.Damage.Body < 60) then TriggerEvent('mythic-notifications:client:Send', { message = 'This vehicle is damaged and needs repairs', type = 'warning' }) end endend)
Event Order: When entering a vehicle as driver, events fire in this order: EnterVehicle → BecameDriver → Ignition. Use BecameDriver for driver-specific logic.
Network IDs: Always verify entities exist before using network IDs. Use DoesEntityExist() after NetworkGetEntityFromNetworkId().