NightZoom LogoNightZoom
BJJ Racing Core/BJJ Racing Core v7/Vehicle

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.isOwned

Core Vehicle States

Essential Vehicle Information

StateTypeDescription
ownernumberPlayer source ID of the vehicle owner
isOwnedbooleanWhether the vehicle is owned by a player
classstringVehicle class (e.g., "super", "sports", "sedan")
platestringVehicle license plate
vinstringVehicle identification number
fuelnumberFuel 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")
end

Vehicle Identification States

StateTypeDescription
fakeplatestringFake license plate (if applied)
vinscratchbooleanWhether 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)
end

Vehicle Type States

Police & Job Vehicles

StateTypeDescription
isPDbooleanWhether the vehicle is a police vehicle
isJobVehiclebooleanWhether the vehicle is a job vehicle
jobGroupstringJob 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)
end

Electric Vehicle States

StateTypeDescription
isChargingbooleanWhether electric vehicle is charging
isDeadbooleanWhether 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
end

Performance & Modification States

Transmission & Engine States

StateTypeDescription
gearnumberCurrent gear (for manual transmission vehicles)
disableRepairbooleanWhether 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")
end

NOS System States

StateTypeDescription
nosnumberCurrent NOS level
nosActivebooleanWhether NOS is currently active
nosModestringNOS 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
end

Tuning & Modification States

StateTypeDescription
stancerDatatableVehicle stance modification data
turboDatatableTurbo 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))
end

Towing & Recovery States

Towing System States

StateTypeDescription
isHookedbooleanWhether vehicle is hooked to a tow truck
isTowingbooleanWhether this vehicle is towing another
isTowedbooleanWhether this vehicle is being towed
towvehnumberEntity 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")
end

Tickets & Violations

StateTypeDescription
ticketstableArray 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
end

Chop Shop States

StateTypeDescription
chopStagestableChop 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
end

State 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
end

State-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.