Vehicle Client
Client-side vehicle functionality and exports for BJJ Racing Core v7
This page covers client-side vehicle functionality for BJJ Racing Core v7. These functions handle vehicle properties, spawning, and live system monitoring.
Vehicle Client Access
Access vehicle client functions through the core:
local Core = exports.bjj_racingcore:getCore()
local VehicleClient = Core.VehicleClientVehicle Properties
VehicleClient.getVehicleProperties(vehicle)
Get complete vehicle properties including mods, colors, and customizations.
local properties = VehicleClient.getVehicleProperties(vehicle)Parameters:
vehicle:number- Vehicle entity handle
Returns: table - Complete vehicle properties object
model:string- Vehicle model hashplate:string- Vehicle license platecolor1:table- Primary color RGB valuescolor2:table- Secondary color RGB valuesmods:table- Vehicle modificationsextras:table- Vehicle extras statelivery:number- Vehicle livery index
Example:
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
local props = VehicleClient.getVehicleProperties(vehicle)
print('Vehicle plate:', props.plate)
print('Primary color:', json.encode(props.color1))VehicleClient.setVehicleProperties(vehicle, props)
Apply vehicle properties to a vehicle entity.
local success = VehicleClient.setVehicleProperties(vehicle, properties)Parameters:
vehicle:number- Vehicle entity handleprops:table- Vehicle properties to apply
Returns: boolean - Success status
Example:
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
local customProps = {
color1 = {255, 0, 0}, -- Red primary
color2 = {0, 0, 0}, -- Black secondary
livery = 1,
mods = {
[11] = 3, -- Engine upgrade level 3
[12] = 2, -- Brakes upgrade level 2
}
}
VehicleClient.setVehicleProperties(vehicle, customProps)Vehicle Spawning
VehicleClient.spawnVehicleById(id)
Request to spawn a vehicle by its database ID.
VehicleClient.spawnVehicleById(vehicleId)Parameters:
id:number- Vehicle database ID
Example:
-- Spawn vehicle with ID 123
VehicleClient.spawnVehicleById(123)This function triggers a server callback to validate ownership and spawn the vehicle. The spawned vehicle will be teleported to your location.
Vehicle Events
Receiving Events
| Event | Parameters | Description |
|---|---|---|
bjj_racingcore:client:vehicleSpawned | netId: number, vehicleData: table | Vehicle has been spawned and is ready |
Event Handlers
-- Listen for vehicle spawn events
RegisterNetEvent('bjj_racingcore:client:vehicleSpawned', function(netId, vehicleData)
local vehicle = NetworkGetEntityFromNetworkId(netId)
print('Vehicle spawned:', vehicleData.model)
print('Plate:', vehicleData.plate)
print('Fuel level:', vehicleData.fuel)
end)Vehicle State Monitoring
The system automatically monitors various vehicle states when you're in a vehicle:
Fuel System Monitoring
- Tracks fuel consumption and levels
- Triggers low fuel warnings
- Syncs fuel state with server
Electric Vehicle Monitoring
- Monitors battery charging state
- Handles battery dead states
- Provides charging notifications
Engine State Monitoring
- Tracks engine on/off state
- Handles manual transmission vehicles
- Monitors engine health
Damage Monitoring
- Tracks engine and body damage
- Syncs damage to server for persistence
- Provides damage warnings
NOS System Monitoring
- Tracks NOS consumption
- Provides low NOS warnings
- Syncs NOS levels with server
Vehicle Utility Functions
GetManualVehicles()
Get list of manual transmission vehicles.
local manualVehicles = exports.bjj_racingcore:GetManualVehicles()Returns: table - Array of manual vehicle model names
isVehicleManual(vehicle)
Check if a vehicle has manual transmission.
local isManual = exports.bjj_racingcore:isVehicleManual(vehicle)Parameters:
vehicle:number- Vehicle entity handle
Returns: boolean - True if vehicle is manual transmission
IsElectricVehicle(vehicle)
Check if a vehicle is electric.
local isElectric = exports.bjj_racingcore:IsElectricVehicle(vehicle)Parameters:
vehicle:number- Vehicle entity handle
Returns: boolean - True if vehicle is electric
IsBackEngine(vehicle)
Check if a vehicle has a rear-mounted engine.
local isBackEngine = exports.bjj_racingcore:IsBackEngine(vehicle)Parameters:
vehicle:number- Vehicle entity handle
Returns: boolean - True if vehicle has rear engine
vehAliasCheck(vehicle)
Get the proper vehicle name with alias checking.
local vehicleName = exports.bjj_racingcore:vehAliasCheck(vehicle)Parameters:
vehicle:number- Vehicle entity handle
Returns: string - Vehicle display name
Live System Events
The client automatically triggers events for live system changes:
Fuel Events
-- Fuel level changed
RegisterNetEvent('bjj_racingcore:client:fuelChanged', function(vehicle, oldFuel, newFuel)
if newFuel <= 10 then
-- Handle low fuel
print('Low fuel warning!')
end
end)Engine Events
-- Engine state changed
RegisterNetEvent('bjj_racingcore:client:engineStateChanged', function(vehicle, oldState, newState)
if newState then
print('Engine started')
else
print('Engine stopped')
end
end)Electric Vehicle Events
-- Charging state changed
RegisterNetEvent('bjj_racingcore:client:chargingStateChanged', function(vehicle, oldState, newState)
if newState then
print('Vehicle is now charging')
else
print('Vehicle charging stopped')
end
end)
-- Battery state changed
RegisterNetEvent('bjj_racingcore:client:batteryStateChanged', function(vehicle, oldState, newState)
if newState then
print('Battery is dead')
else
print('Battery restored')
end
end)Damage Events
-- Engine damage changed
RegisterNetEvent('bjj_racingcore:client:engineDamageChanged', function(vehicle, oldHealth, newHealth)
local damagePercent = (1000 - newHealth) / 10
print('Engine damage:', damagePercent .. '%')
end)
-- Body damage changed
RegisterNetEvent('bjj_racingcore:client:bodyDamageChanged', function(vehicle, oldHealth, newHealth)
local damagePercent = (1000 - newHealth) / 10
print('Body damage:', damagePercent .. '%')
end)NOS Events
-- NOS level changed
RegisterNetEvent('bjj_racingcore:client:nosChanged', function(vehicle, oldNos, newNos)
if newNos <= 10 then
print('Low NOS warning!')
end
end)Integration Example
-- Complete vehicle integration example
CreateThread(function()
-- Wait for player to be loaded
while not LocalPlayer.state.isLoaded do Wait(100) end
-- Monitor vehicle entry
local lastVehicle = nil
while true do
local ped = PlayerPedId()
local vehicle = GetVehiclePedIsIn(ped, false)
if vehicle ~= 0 and vehicle ~= lastVehicle then
lastVehicle = vehicle
-- Get vehicle properties
local props = VehicleClient.getVehicleProperties(vehicle)
print('Entered vehicle:', props.model)
-- Check vehicle type
if exports.bjj_racingcore:isVehicleManual(vehicle) then
print('This is a manual transmission vehicle')
end
if exports.bjj_racingcore:IsElectricVehicle(vehicle) then
print('This is an electric vehicle')
end
elseif vehicle == 0 then
lastVehicle = nil
end
Wait(1000)
end
end)The vehicle client system automatically handles state synchronization with the server. All monitoring systems start automatically when you enter a vehicle as the driver.
Vehicle properties and modifications are automatically saved when significant changes occur. Manual saves are not typically required.