Vehicles
The Vehicles module provides comprehensive vehicle functionality for FiveM resources with advanced customization, tracking, and management capabilities.
setTuning
Applies comprehensive tuning modifications to a vehicle.
B2Lib.Vehicles.setTuning(vehicle, tuning)
Parameters:
vehicle
(number): Vehicle entity handletuning
(table): Tuning configurationengine
(number): Engine upgrade level (0-3)brakes
(number): Brake upgrade level (0-3)transmission
(number): Transmission upgrade level (0-3)suspension
(number): Suspension upgrade level (0-3)armor
(number): Armor upgrade level (0-4)turbo
(boolean): Enable turbospoiler
(number): Spoiler modificationfrontBumper
(number): Front bumper modificationrearBumper
(number): Rear bumper modificationsideSkirt
(number): Side skirt modificationexhaust
(number): Exhaust modificationframe
(number): Frame modificationgrille
(number): Grille modificationhood
(number): Hood modificationfender
(number): Fender modificationrightFender
(number): Right fender modificationroof
(number): Roof modificationxenonHeadlights
(boolean): Enable xenon headlightsxenonColor
(number): Xenon color (0-12)wheelType
(number): Wheel type categoryfrontWheels
(number): Front wheel designbackWheels
(number): Back wheel designlivery
(number): Primary liverylivery2
(number): Secondary liveryvanityPlate
(number): Vanity plate styletrimA
(number): Trim A modificationtrimB
(number): Trim B modification
Returns: boolean - True if tuning was applied successfully
Example:
local tuning = {
engine = 3,
brakes = 2,
transmission = 1,
turbo = true,
spoiler = 1,
livery = 2
}
local success = B2Lib.Vehicles.setTuning(vehicle, tuning)
getTuning
Gets the current tuning configuration of a vehicle.
B2Lib.Vehicles.getTuning(vehicle)
Parameters:
vehicle
(number): Vehicle entity handle
Returns: table - Current tuning configuration with all modification levels
setColors
Applies color configuration to a vehicle including primary, secondary, custom RGB, and neon colors.
B2Lib.Vehicles.setColors(vehicle, colors)
Parameters:
vehicle
(number): Vehicle entity handlecolors
(table): Color configurationprimary
(number): Primary color indexsecondary
(number): Secondary color indexpearl
(number): Pearl color indexwheel
(number): Wheel color indexcustomPrimary
(table): Custom primary RGB {r, g, b}customSecondary
(table): Custom secondary RGB {r, g, b}neon
(table): Neon RGB color {r, g, b}neonSides
(table): Neon sides enabled {left, right, front, back}interior
(number): Interior color indexdashboard
(number): Dashboard color indextyreSmokeColor
(table): Tire smoke RGB {r, g, b}
Returns: boolean - True if colors were applied successfully
Example:
local colors = {
primary = 12,
secondary = 0,
customPrimary = {r = 255, g = 0, b = 0},
neon = {r = 0, g = 255, b = 255},
neonSides = {true, true, true, true}
}
B2Lib.Vehicles.setColors(vehicle, colors)
getColors
Gets the current color configuration of a vehicle.
B2Lib.Vehicles.getColors(vehicle)
Parameters:
vehicle
(number): Vehicle entity handle
Returns: table - Current color configuration including all color types
setExtras
Configures vehicle extras (additional components).
B2Lib.Vehicles.setExtras(vehicle, extras)
Parameters:
vehicle
(number): Vehicle entity handleextras
(table): Extras configuration {[extraId] = enabled}
Returns: boolean - True if extras were configured successfully
Example:
local extras = {
[1] = true, -- Enable extra 1
[2] = false, -- Disable extra 2
[3] = true -- Enable extra 3
}
B2Lib.Vehicles.setExtras(vehicle, extras)
getExtras
Gets information about available and enabled vehicle extras.
B2Lib.Vehicles.getExtras(vehicle)
Parameters:
vehicle
(number): Vehicle entity handle
Returns: table - Extras information
available
(table): Array of available extra IDsextras
(table): Current extra states {[extraId] = enabled}count
(number): Total number of available extras
getProperties
Gets comprehensive vehicle properties including all modifications and states.
B2Lib.Vehicles.getProperties(vehicle)
Parameters:
vehicle
(number): Vehicle entity handle
Returns: table - Complete vehicle properties
model
(number): Vehicle model hashplate
(string): License plate textplateIndex
(number): License plate stylebodyHealth
(number): Body health (0-1000)engineHealth
(number): Engine health (0-1000)tankHealth
(number): Fuel tank health (0-1000)fuelLevel
(number): Fuel level (0-100)dirtLevel
(number): Dirt level (0-15)oilLevel
(number): Oil level (0-100)tuning
(table): All tuning modificationscolors
(table): All color configurationsextras
(table): Extra statesdoors
(table): Door stateswindows
(table): Window statestyres
(table): Tire statesneonEnabled
(table): Neon light states
setProperties
Applies comprehensive vehicle properties to restore or configure a vehicle.
B2Lib.Vehicles.setProperties(vehicle, properties)
Parameters:
vehicle
(number): Vehicle entity handleproperties
(table): Vehicle properties to apply
Returns: boolean - True if properties were applied successfully
spawn
Spawns a vehicle with optional customization properties.
B2Lib.Vehicles.spawn(model, coords, heading, properties)
Parameters:
model
(string|number): Vehicle model name or hashcoords
(vector3): Spawn coordinatesheading
(number): Vehicle heading in degreesproperties
(table, optional): Vehicle properties to apply after spawn
Returns: number|nil - Vehicle entity handle or nil if spawn failed
Example:
local vehicle = B2Lib.Vehicles.spawn('adder', vector3(0, 0, 72), 0.0, {
colors = {primary = 12, secondary = 0},
tuning = {engine = 3, turbo = true}
})
trackHealth
Starts tracking vehicle health changes with callback notifications.
B2Lib.Vehicles.trackHealth(vehicle, callback, options)
Parameters:
vehicle
(number): Vehicle entity handlecallback
(function): Function called on health changesoptions
(table, optional): Tracking optionsinterval
(number): Check interval in milliseconds (default: 1000)threshold
(number): Minimum change threshold (default: 10)trackDamage
(boolean): Track individual damage components (default: true)
Returns: string - Tracking ID for management
Example:
local trackingId = B2Lib.Vehicles.trackHealth(vehicle, function(health, damage)
print("Vehicle health:", health.body, health.engine)
if damage.newDamage then
print("New damage detected!")
end
end)
stopTracking
Stops health tracking for a vehicle.
B2Lib.Vehicles.stopTracking(trackingId)
Parameters:
trackingId
(string): Tracking ID to stop
Returns: boolean - True if tracking was stopped successfully
getTrackingInfo
Gets information about active health tracking.
B2Lib.Vehicles.getTrackingInfo(trackingId)
Parameters:
trackingId
(string): Tracking ID to get information for
Returns: table|nil - Tracking information or nil if not found
repair
Repairs vehicle damage with configurable options.
B2Lib.Vehicles.repair(vehicle, options)
Parameters:
vehicle
(number): Vehicle entity handleoptions
(table, optional): Repair optionsbody
(boolean): Repair body damage (default: true)engine
(boolean): Repair engine damage (default: true)tank
(boolean): Repair fuel tank (default: true)visual
(boolean): Repair visual damage (default: true)deformation
(boolean): Fix deformation (default: true)doors
(boolean): Repair doors (default: true)windows
(boolean): Repair windows (default: true)tyres
(boolean): Repair tires (default: true)lights
(boolean): Repair lights (default: true)
Returns: boolean - True if repair was successful
getVehicleType
Gets detailed vehicle type information and classification.
B2Lib.Vehicles.getVehicleType(vehicle)
Parameters:
vehicle
(number): Vehicle entity handle
Returns: table - Vehicle type information
class
(number): Vehicle class IDclassName
(string): Vehicle class nametype
(string): Vehicle type (car, bike, boat, plane, helicopter, etc.)category
(string): Vehicle categorycapabilities
(table): Vehicle capabilities
getClassName
Gets the vehicle class name.
B2Lib.Vehicles.getClassName(vehicle)
Parameters:
vehicle
(number): Vehicle entity handle
Returns: string - Vehicle class name
hasCapability
Checks if a vehicle has a specific capability.
B2Lib.Vehicles.hasCapability(vehicle, capability)
Parameters:
vehicle
(number): Vehicle entity handlecapability
(string): Capability to check (neon, siren, flight, etc.)
Returns: boolean - True if vehicle has the capability
getMaxSpeed
Gets the maximum speed of a vehicle in specified units.
B2Lib.Vehicles.getMaxSpeed(vehicle, unit)
Parameters:
vehicle
(number): Vehicle entity handleunit
(string, optional): Speed unit ('ms', 'kmh', 'mph') (default: 'ms')
Returns: number - Maximum speed in specified unit
getStats
Gets comprehensive vehicle system statistics.
B2Lib.Vehicles.getStats()
Returns: table - Vehicle system statistics
totalVehicles
(number): Total vehicles managedtrackedVehicles
(number): Vehicles being health trackedspawnedVehicles
(number): Vehicles spawned by systemtotalRepairs
(number): Total repairs performedtotalCustomizations
(number): Total customizations appliedaverageHealth
(number): Average vehicle healthmemoryUsage
(number): Estimated memory usageperformanceMetrics
(table): Performance statistics
Configuration
Configure the vehicles module in config.lua
:
Config.Vehicles = {
enableHealthTracking = true, -- Enable health tracking system
defaultTrackingInterval = 1000, -- Default tracking interval in ms
healthThreshold = 10, -- Minimum health change threshold
enableStatistics = true, -- Enable statistics tracking
enableDebugMode = false, -- Enable debug logging
maxTrackedVehicles = 100, -- Maximum vehicles to track simultaneously
autoRepairThreshold = 100, -- Auto-repair threshold
enablePerformanceMode = false, -- Enable performance optimizations
cacheVehicleData = true, -- Cache vehicle data for performance
enableDamageDetection = true, -- Enable damage detection
trackingCleanupInterval = 300000, -- Cleanup interval for tracking
maxSpawnDistance = 500, -- Maximum spawn distance from players
enableSpawnValidation = true, -- Validate spawn locations
defaultFuelLevel = 100, -- Default fuel level for spawned vehicles
enableCustomColors = true, -- Enable custom RGB colors
enableNeonLights = true, -- Enable neon light system
maxCustomizations = 50 -- Maximum customizations per vehicle
}
Troubleshooting
Vehicle Not Spawning
Check if model name/hash is valid
Verify spawn coordinates are valid and not obstructed
Ensure player has necessary permissions
Check if spawn distance limits are exceeded
Tuning Not Applying
Verify vehicle supports the modification type
Check if modification values are within valid ranges
Ensure vehicle entity is valid and exists
Validate tuning configuration structure
Health Tracking Issues
Check if tracking ID is valid and active
Verify callback function is properly defined
Ensure tracking interval is reasonable
Monitor for memory leaks with many tracked vehicles
Color Problems
Verify color indices are within valid ranges (0-159)
Check RGB values are between 0-255
Ensure vehicle supports custom colors
Validate neon light compatibility
Performance Issues
Limit number of simultaneously tracked vehicles
Increase tracking intervals for better performance
Enable performance mode for large vehicle counts
Use cleanup functions to remove old tracking data
Memory Leaks
Always stop tracking when vehicles are deleted
Use cleanup intervals to remove stale data
Monitor statistics for memory usage trends
Avoid creating too many simultaneous customizations
Last updated