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
| State | Type | Description |
|---|---|---|
isLoaded | boolean | Player has fully loaded into the server |
charId | number | Character ID for the current player |
name | string | Player's display name |
racername | string | Player's racing alias/name |
Authentication & Permissions
| State | Type | Description |
|---|---|---|
groups | table | Player's group memberships (police, admin, etc.) |
crews | table | Player's crew memberships |
bjj_service | boolean | Service status for police/job system |
pdMode | boolean | Police duty mode status (on/off duty) |
Health & Status States
Life & Physical States
| State | Type | Description |
|---|---|---|
isdead | boolean | Player is dead |
isDead | boolean | Alternative death state |
canEmote | boolean | Player can use emotes |
interactBusy | boolean | Player is busy with interactions |
Restraint & Control States
| State | Type | Description |
|---|---|---|
cuffState | boolean | Player is handcuffed |
cuffType | number | Type of restraints (1=handcuffs, 2=zipties) |
escortState | boolean | Being escorted by another player |
tackled | boolean | Player has been tackled |
Activity & Game States
Racing & Wanted System
| State | Type | Description |
|---|---|---|
inRace | boolean | Player is in a race |
raceId | string | ID of the current race |
wanted | table | Wanted status {active: boolean, level: number} |
Inventory & Items
| State | Type | Description |
|---|---|---|
invBusy | boolean | Inventory system busy state |
invOpen | boolean | Inventory UI is open |
invHotkeys | boolean | Inventory hotkeys enabled/disabled |
inv_busy | boolean | Alternative inventory busy state |
canUseWeapons | boolean | Player can use weapons |
carry_items | table | Items being carried (prop carry system) |
carry_loop | boolean | Carry animation loop state |
UI & Display States
Interface Controls
| State | Type | Description |
|---|---|---|
hideHud | boolean | Hide the HUD display |
cinematicmode | boolean | Cinematic camera mode active |
cinematicOverride | boolean | Override for cinematic mode |
streamermode | boolean | Streamer-safe mode for content creators |
World & Instance
| State | Type | Description |
|---|---|---|
instance | number | Current world instance/dimension |
proximity | table | Voice chat proximity settings |
hide_props | boolean | Hide carried props from view |
Voice & Communication States
Voice System
| State | Type | Description |
|---|---|---|
assignedChannel | number | Mumble voice channel assignment |
callChannel | number | Phone call channel |
radioChannel | number | Radio frequency |
disableProximity | boolean | Disable proximity voice chat |
disableRadio | boolean | Disable radio communications |
submix | table | Audio submix settings |
isTalking | boolean | Currently talking/transmitting |
System States
Time & Environment
| State | Type | Description |
|---|---|---|
freezeTime | boolean | Time freeze status |
currentTime | table | Current game time |
blackOut | boolean | Screen blackout state |
Player Controls
| State | Type | Description |
|---|---|---|
walk | string | Walking style/gait |
playerCam | table | Player 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)
endWanted 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
})
endVoice 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
endState 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)
endLocalPlayer 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.