esx_cruisecontrol
esx_cruisecontrol adds cruise control and a seatbelt with ejection to ESX Legacy. Covers keybinds, config keys, the isSeatbeltOn export and HUD integration.
esx_cruisecontrol is a client-only ESX Legacy addon that adds two driving features: cruise control that holds your current speed, and a seatbelt that blocks exiting the vehicle and prevents you from being thrown through the windshield in a crash. It pushes both states to esx_hud by default.
Overview
| Resource | esx_cruisecontrol (version 1.2) |
| Side | client only |
| Dependencies | esx_lib, es_extended |
| Optional | esx_hud (or any HUD set in Config.HudResource) |
| Export | isSeatbeltOn (client) |
Cruise control engages only when you are the driver, the engine runs and you are moving forward. It then applies throttle to hold the speed, with reduced throttle while steering. Each speed step is 10 mph and the maximum target is 120 mph; stepping down to 0 turns it off. It disengages on brake, handbrake, leaving the seat, engine off, standing still or reversing, or a sudden engine damage hit (more than 10 engine health in one frame).
Seatbelt blocks the exit control while buckled. Unbuckled, a frontal crash at more than EjectCheckSpeed mph with a strong deceleration throws the player out of the vehicle and ragdolls them. The seatbelt unbuckles automatically when you leave the vehicle. Ejection only applies to regular vehicle classes (classes 0-7, 9-12 and 17-20; motorcycles, bicycles, boats, helicopters, planes and trains are excluded).
Installation
No SQL is needed.
ensure esx_lib
ensure es_extended
ensure esx_hud
ensure esx_cruisecontrolConfiguration
| Key | Default | Description |
|---|---|---|
Config.Locale | GetConvar('esx:locale', 'en') | Language. |
Config.HudResource | 'esx_hud' | HUD resource that receives the state. Skipped if it is not started. |
Config.Cruise.Enable | true | Enables cruise control and its keybinds. |
Config.Cruise.Key | 'CAPITAL' | Default key to toggle cruise control (Caps Lock). |
Config.Cruise.Export | exports[Config.HudResource]:CruiseControlState(state) | Function called with true/false when cruise control changes. |
Config.Seatbelt.Enable | true | Enables the seatbelt and ejection. |
Config.Seatbelt.Key | 'B' | Default key to toggle the seatbelt. |
Config.Seatbelt.EjectCheckSpeed | 45 | Minimum speed in mph before an unbuckled player can be ejected. |
Config.Seatbelt.RagdollTime | 1 | How long the player ragdolls after ejection. The code multiplies it by 1000, so the value is in seconds (the config comment says MS). |
Config.Seatbelt.Export | exports[Config.HudResource]:SeatbeltState(state) | Function called with true/false when the seatbelt changes. |
The increase and decrease speed keys are not in the config; their defaults are ADD and SUBTRACT (numpad plus and minus).
Using another HUD
Replace the two Export functions with whatever your HUD expects:
Config = {
Locale = GetConvar('esx:locale', 'en'),
HudResource = 'my_hud',
Cruise = {
Enable = true,
Key = 'CAPITAL',
Export = function(state)
exports['my_hud']:setCruise(state)
end,
},
Seatbelt = {
Enable = true,
Key = 'B',
EjectCheckSpeed = 45,
RagdollTime = 1,
Export = function(state)
exports['my_hud']:setBelt(state)
end,
},
}If the export call errors, the resource prints the error and a hint, but keeps working.
Keybinds
Registered through xLib.addKeybind, so players can rebind them in Settings > Key Bindings > FiveM.
| Name | Default | Action |
|---|---|---|
esx_cruisecontrol:Enable | Config.Cruise.Key | Toggle cruise control |
esx_cruisecontrol:IncreaseSpeed | ADD | Raise target speed by 10 mph |
esx_cruisecontrol:DecreaseSpeed | SUBTRACT | Lower target speed by 10 mph |
esx_cruisecontrol:ToggleSeatbelt | Config.Seatbelt.Key | Toggle seatbelt |
Exports
isSeatbeltOn (client)
local buckled = exports.esx_cruisecontrol:isSeatbeltOn()Returns true when the local player's seatbelt is fastened. Useful for police fines or a custom HUD:
RegisterCommand('checkbelt', function()
local buckled = exports.esx_cruisecontrol:isSeatbeltOn()
ESX.ShowNotification(buckled and 'Seatbelt on' or 'Seatbelt off')
end, false)The resource registers no server events or callbacks.
Common issues
- Cruise control will not engage: you must be the driver, moving forward with the engine running.
- Keys changed in config have no effect: FiveM stores key mappings per player after the first bind. Existing players keep their old key until they rebind it.
- Console error about
CruiseControlState:Config.HudResourcepoints to a resource that does not provide these exports. Adjust theExportfunctions. - Players never get ejected: ejection needs a frontal crash above
EjectCheckSpeedmph with a very sharp deceleration, in a supported vehicle class.
Related
Frequently asked questions
Independent documentation
Last updated on
esx_clotheshop
esx_clotheshop adds 14 clothing stores to ESX Legacy. Configure prices, per-piece charging and saved outfits, and learn the server callback and its checks.
esx_datastore
esx_datastore stores JSON data per player or per society in ESX Legacy. Learn the tables, the get/set store API, server events and autosave behavior.