NightZoom LogoNightZoom
BJJ Racing Core/BJJ Racing Core v7/Player

LocalPlayer States

Client-side LocalPlayer states for BJJ Racing Core v7

This page covers all LocalPlayer states used in BJJ Racing Core v7. LocalPlayer states track the current player's status and properties on the client side.

Core System States

Player Identity & Loading

StateTypeDescription
isLoadedbooleanPlayer has fully loaded into the server
charIdnumberCharacter ID for the current player
namestringPlayer's display name
racernamestringPlayer's racing alias/name

Authentication & Permissions

StateTypeDescription
groupstablePlayer's group memberships (police, admin, etc.)
crewstablePlayer's crew memberships
bjj_servicebooleanService status for police/job system
pdModebooleanPolice duty mode status (on/off duty)

Health & Status States

Life & Physical States

StateTypeDescription
isdeadbooleanPlayer is dead
isDeadbooleanAlternative death state
canEmotebooleanPlayer can use emotes
interactBusybooleanPlayer is busy with interactions

Restraint & Control States

StateTypeDescription
cuffStatebooleanPlayer is handcuffed
cuffTypenumberType of restraints (1=handcuffs, 2=zipties)
escortStatebooleanBeing escorted by another player
tackledbooleanPlayer has been tackled

Activity & Game States

Racing & Wanted System

StateTypeDescription
inRacebooleanPlayer is in a race
raceIdstringID of the current race
wantedtableWanted status {active: boolean, level: number}

Inventory & Items

StateTypeDescription
invBusybooleanInventory system busy state
invOpenbooleanInventory UI is open
invHotkeysbooleanInventory hotkeys enabled/disabled
inv_busybooleanAlternative inventory busy state
canUseWeaponsbooleanPlayer can use weapons
carry_itemstableItems being carried (prop carry system)
carry_loopbooleanCarry animation loop state

UI & Display States

Interface Controls

StateTypeDescription
hideHudbooleanHide the HUD display
cinematicmodebooleanCinematic camera mode active
cinematicOverridebooleanOverride for cinematic mode
streamermodebooleanStreamer-safe mode for content creators

World & Instance

StateTypeDescription
instancenumberCurrent world instance/dimension
proximitytableVoice chat proximity settings
hide_propsbooleanHide carried props from view

Voice & Communication States

Voice System

StateTypeDescription
assignedChannelnumberMumble voice channel assignment
callChannelnumberPhone call channel
radioChannelnumberRadio frequency
disableProximitybooleanDisable proximity voice chat
disableRadiobooleanDisable radio communications
submixtableAudio submix settings
isTalkingbooleanCurrently talking/transmitting

System States

Time & Environment

StateTypeDescription
freezeTimebooleanTime freeze status
currentTimetableCurrent game time
blackOutbooleanScreen blackout state

Player Controls

StateTypeDescription
walkstringWalking style/gait
playerCamtablePlayer camera state

Usage Examples

Basic State Access

-- Check if player is loaded before proceeding
if LocalPlayer.state.isLoaded then
    -- Safe to proceed with player operations
    local charId = LocalPlayer.state.charId
    local playerName = LocalPlayer.state.name
    print("Player loaded:", playerName, "ID:", charId)
end

-- Set player as busy during interaction
LocalPlayer.state:set('interactBusy', true, false)

-- Check if player can use emotes
if LocalPlayer.state.canEmote and not LocalPlayer.state.interactBusy then
    -- Allow emote execution
    TriggerEvent('emotes:play', emoteName)
end

Wanted System Integration

-- Access wanted status
local wantedData = LocalPlayer.state.wanted
if wantedData and wantedData.active then
    print("Player has wanted level:", wantedData.level)
    -- Update UI to show wanted status
    SendNUIMessage({
        type = 'updateWanted',
        level = wantedData.level,
        active = true
    })
end

Voice System Integration

-- Monitor voice states
local function updateVoiceDisplay()
    local radioChannel = LocalPlayer.state.radioChannel
    local assignedChannel = LocalPlayer.state.assignedChannel
    local isTalking = LocalPlayer.state.isTalking
    
    -- Update voice UI
    SendNUIMessage({
        type = 'updateVoice',
        radio = radioChannel,
        channel = assignedChannel,
        talking = isTalking
    })
end

-- Listen for voice state changes
AddStateBagChangeHandler('isTalking', 'player:' .. GetPlayerServerId(PlayerId()), function(bagName, key, value)
    updateVoiceDisplay()
end)

Racing System Integration

-- Monitor race status
CreateThread(function()
    local lastRaceState = false
    
    while true do
        local inRace = LocalPlayer.state.inRace
        local raceId = LocalPlayer.state.raceId
        
        if inRace and not lastRaceState then
            -- Player joined a race
            print("Joined race:", raceId)
            TriggerEvent('hud:showRaceUI', true)
        elseif not inRace and lastRaceState then
            -- Player left/finished race
            print("Left race")
            TriggerEvent('hud:showRaceUI', false)
        end
        
        lastRaceState = inRace
        Wait(1000)
    end
end)

Inventory System Integration

-- Safe inventory operations
local function canUseInventory()
    local state = LocalPlayer.state
    return not (state.invBusy or state.inv_busy or state.interactBusy or state.isdead)
end

-- Open inventory with state check
RegisterCommand('inventory', function()
    if canUseInventory() then
        LocalPlayer.state:set('invOpen', true, false)
        -- Open inventory UI
        TriggerEvent('inventory:client:openInventory')
    else
        print("Cannot open inventory - player is busy")
    end
end)

Police System Integration

-- Monitor police duty status
AddStateBagChangeHandler('pdMode', 'player:' .. GetPlayerServerId(PlayerId()), function(bagName, key, value)
    if value then
        print("Went on duty")
        -- Enable police equipment
        TriggerEvent('police:enableEquipment')
        -- Update UI
        SendNUIMessage({type = 'updateDutyStatus', onDuty = true})
    else
        print("Went off duty")
        -- Disable police equipment
        TriggerEvent('police:disableEquipment')
        -- Update UI
        SendNUIMessage({type = 'updateDutyStatus', onDuty = false})
    end
end)

-- Check if player can use police actions
local function canUsePoliceActions()
    local state = LocalPlayer.state
    return state.pdMode and state.groups and state.groups.police
end

State Change Handlers

Monitoring State Changes

-- Death state handler
AddStateBagChangeHandler('isdead', 'player:' .. GetPlayerServerId(PlayerId()), function(bagName, key, value)
    if value then
        -- Player died
        print("Player died")
        TriggerEvent('medical:playerDied')
        LocalPlayer.state:set('canEmote', false, false)
    else
        -- Player revived
        print("Player revived")
        TriggerEvent('medical:playerRevived')
        LocalPlayer.state:set('canEmote', true, false)
    end
end)

-- Cuff state handler
AddStateBagChangeHandler('cuffState', 'player:' .. GetPlayerServerId(PlayerId()), function(bagName, key, value)
    if value then
        -- Player was cuffed
        local cuffType = LocalPlayer.state.cuffType or 1
        TriggerEvent('police:playerCuffed', cuffType)
        DisableAllControlActions(0) -- Disable controls
    else
        -- Player was uncuffed
        TriggerEvent('police:playerUncuffed')
        EnableAllControlActions(0) -- Re-enable controls
    end
end)

Initialization Patterns

-- Wait for player to load before initializing systems
CreateThread(function()
    -- Wait for player load
    while not LocalPlayer.state.isLoaded do
        Wait(100)
    end
    
    print("Player fully loaded, initializing systems")
    
    -- Initialize your resource systems
    TriggerEvent('myresource:initialize')
    
    -- Set up state monitoring
    setupStateHandlers()
    
    -- Enable resource features
    LocalPlayer.state:set('myresource_loaded', true, false)
end)

local function setupStateHandlers()
    -- Set up all your state change handlers here
    AddStateBagChangeHandler('interactBusy', 'player:' .. GetPlayerServerId(PlayerId()), function(bagName, key, value)
        -- Handle interaction busy state changes
        if value then
            TriggerEvent('myresource:disableControls')
        else
            TriggerEvent('myresource:enableControls')
        end
    end)
end

LocalPlayer states are specific to the current player's client and are used for managing local player status, UI states, and system interactions.

Always check if LocalPlayer.state.isLoaded is true before accessing other player data to ensure the player has fully initialized.

State change handlers provide real-time reactions to player state changes, enabling seamless integration with game systems and UI updates.