Vehicle Entity States
Shared entity states for vehicle synchronization in BJJ Racing Core v7
This page covers the entity state system for vehicles in BJJ Racing Core v7. Entity states provide synchronized data between client and server for active vehicles.
Accessing Vehicle States
Vehicle entity states are accessed through the FiveM entity state system:
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
local vehicleState = Entity(vehicle).state
-- Access specific states
local owner = vehicleState.owner
local fuel = vehicleState.fuel
local isOwned = vehicleState.isOwnedCore Vehicle States
Essential Vehicle Information
| State | Type | Description |
|---|---|---|
owner | number | Player source ID of the vehicle owner |
isOwned | boolean | Whether the vehicle is owned by a player |
class | string | Vehicle class (e.g., "super", "sports", "sedan") |
plate | string | Vehicle license plate |
vin | string | Vehicle identification number |
fuel | number | Fuel level (0-100) |
Example Usage:
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
local state = Entity(vehicle).state
if state.isOwned then
print("This vehicle is owned by player:", state.owner)
print("License plate:", state.plate)
print("Fuel level:", state.fuel .. "%")
else
print("This vehicle is not owned")
endVehicle Identification States
| State | Type | Description |
|---|---|---|
fakeplate | string | Fake license plate (if applied) |
vinscratch | boolean | Whether the VIN has been scratched/removed |
Example Usage:
local state = Entity(vehicle).state
-- Check for VIN tampering
if state.vinscratch then
print("WARNING: VIN has been scratched on this vehicle")
end
-- Check for fake plates
if state.fakeplate then
print("Vehicle has fake plate:", state.fakeplate)
print("Real plate:", state.plate)
endVehicle Type States
Police & Job Vehicles
| State | Type | Description |
|---|---|---|
isPD | boolean | Whether the vehicle is a police vehicle |
isJobVehicle | boolean | Whether the vehicle is a job vehicle |
jobGroup | string | Job group ID for job vehicles |
Example Usage:
local state = Entity(vehicle).state
if state.isPD then
print("This is a police vehicle")
-- Only PD players can drive
end
if state.isJobVehicle then
print("Job vehicle for group:", state.jobGroup)
endElectric Vehicle States
| State | Type | Description |
|---|---|---|
isCharging | boolean | Whether electric vehicle is charging |
isDead | boolean | Whether electric vehicle battery is dead |
Example Usage:
local state = Entity(vehicle).state
if state.isDead then
print("Electric vehicle battery is dead")
-- Disable engine functions
elseif state.isCharging then
print("Electric vehicle is charging")
-- Show charging indicators
endPerformance & Modification States
Transmission & Engine States
| State | Type | Description |
|---|---|---|
gear | number | Current gear (for manual transmission vehicles) |
disableRepair | boolean | Whether repairs are disabled on this vehicle |
Example Usage:
local state = Entity(vehicle).state
-- Manual transmission display
if state.gear then
print("Current gear:", state.gear)
end
-- Check repair status
if state.disableRepair then
print("Repairs disabled on this vehicle")
endNOS System States
| State | Type | Description |
|---|---|---|
nos | number | Current NOS level |
nosActive | boolean | Whether NOS is currently active |
nosMode | string | NOS mode ("PURGE", "SPRAY", etc.) |
Example Usage:
local state = Entity(vehicle).state
-- NOS system monitoring
if state.nos then
print("NOS level:", state.nos)
if state.nosActive then
print("NOS is active! Mode:", state.nosMode)
end
if state.nos <= 10 then
print("Low NOS warning!")
end
endTuning & Modification States
| State | Type | Description |
|---|---|---|
stancerData | table | Vehicle stance modification data |
turboData | table | Turbo system configuration data |
Example Usage:
local state = Entity(vehicle).state
-- Check for stance modifications
if state.stancerData then
print("Vehicle has stance modifications:", json.encode(state.stancerData))
end
-- Check for turbo modifications
if state.turboData then
print("Vehicle has turbo system:", json.encode(state.turboData))
endTowing & Recovery States
Towing System States
| State | Type | Description |
|---|---|---|
isHooked | boolean | Whether vehicle is hooked to a tow truck |
isTowing | boolean | Whether this vehicle is towing another |
isTowed | boolean | Whether this vehicle is being towed |
towveh | number | Entity handle of the tow vehicle |
Example Usage:
local state = Entity(vehicle).state
-- Towing status checks
if state.isTowed then
print("This vehicle is being towed by:", state.towveh)
elseif state.isTowing then
print("This vehicle is towing another vehicle")
elseif state.isHooked then
print("This vehicle is hooked to a tow truck")
endLegal & Administrative States
Tickets & Violations
| State | Type | Description |
|---|---|---|
tickets | table | Array of unpaid tickets/violations |
Example Usage:
local state = Entity(vehicle).state
-- Check for outstanding tickets
if state.tickets then
local ticketCount = #state.tickets
if ticketCount > 0 then
print("Vehicle has", ticketCount, "unpaid tickets")
for i, ticket in ipairs(state.tickets) do
print("Ticket", i, ":", ticket.violation, "- $" .. ticket.amount)
end
end
endChop Shop States
| State | Type | Description |
|---|---|---|
chopStages | table | Chop shop processing stages/data |
Example Usage:
local state = Entity(vehicle).state
-- Check chop status
if state.chopStages then
print("Vehicle chop data:", json.encode(state.chopStages))
-- This vehicle is involved in chop shop activities
endState Monitoring Examples
Real-time State Monitoring
-- Monitor vehicle state changes
RegisterNetEvent('bjj_core:client:enteredVehicle', function ()
local isInVehicle = true
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
if not vehicle or vehicle == 0 then return end
local VehicleState = Entity(vehicle)?.state
while isInVehicle do
VehicleState = Entity(vehicle)?.state
local fuel = VehicleState?.fuel
if fuel and fuel < 50 then
print("Warning: Low fuel level - " .. fuel .. "%")
end
isInVehicle = GetVehiclePedIsIn(PlayerPedId(), false) == vehicle
Wait(1000)
end
end)State-Based Vehicle Restrictions
-- Example: Implement vehicle access restrictions
RegisterNetEvent('bjj_core:client:enteredVehicle', function ()
local isInVehicle = true
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
if not vehicle or vehicle == 0 then return end
local VehicleState = Entity(vehicle)?.state
while isInVehicle do
VehicleState = Entity(vehicle)?.state
local seat = cache.seat -- or: GetPedInVehicleSeat(vehicle, ped)
-- Check if this is a police vehicle
if VehicleState and VehicleState.isPD and seat == -1 then -- Driver seat
local player = exports.bjj_racingcore:getCore().getPlayerData()
if not player.groups.pd then
-- Non-PD player in police vehicle
print("Access denied: Police vehicle")
TaskLeaveVehicle(ped, vehicle, 0)
end
end
-- Check if electric vehicle is dead
if state.isDead and seat == -1 then
if GetIsVehicleEngineRunning(vehicle) then
SetVehicleEngineOn(vehicle, false, true, true)
print("Battery dead - engine disabled")
end
end
end
Wait(1000)
end
end)Integration Patterns
State Synchronization with Vehicle Objects
-- Sync entity states with vehicle object data
local function syncVehicleStates(vehicle)
local state = Entity(vehicle).state
local vehicleObj = exports.bjj_racingcore:getActiveVehicle(NetworkGetNetworkIdFromEntity(vehicle))
if vehicleObj then
-- Sync fuel
if state.fuel ~= vehicleObj.getFuel() then
vehicleObj.setFuel(state.fuel, false)
end
-- Sync NOS
if state.nos ~= vehicleObj.getNos() then
vehicleObj.setNos(state.nos, false)
end
-- Save changes
vehicleObj.save()
end
endState-Based UI Updates
-- Update UI based on vehicle states
RegisterNetEvent('vehicle:updateUI', function()
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
if vehicle == 0 then return end
local state = Entity(vehicle).state
-- Update fuel display
if state.fuel then
SendNUIMessage({
type = 'updateFuel',
fuel = state.fuel
})
end
-- Update NOS display
if state.nos then
SendNUIMessage({
type = 'updateNOS',
nos = state.nos,
active = state.nosActive or false
})
end
-- Update gear display for manual vehicles
if state.gear then
SendNUIMessage({
type = 'updateGear',
gear = state.gear
})
end
end)Entity states are automatically synchronized between all clients. Changes made on the server are instantly visible to all clients.
Entity states are temporary and are lost when the vehicle despawns. Use the Vehicle object system for persistent data storage.
The entity state system provides real-time synchronization for all vehicle systems including fuel, NOS, electric charging, and towing status.