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

Player States

Other player entity states for BJJ Racing Core v7

This page covers entity states for other players and NPCs in BJJ Racing Core v7. These states track the properties and status of other players visible to the client.

Core Identity States

Player Information

StateTypeDescription
namestringPlayer's display name
racernamestringPlayer's racing alias
mmrnumberMatchmaking rating/skill level
charIdnumberCharacter ID
isLoadedbooleanPlayer has fully loaded

Group & Permission States

StateTypeDescription
groupstablePlayer's group memberships (police, admin, etc.)
crewstablePlayer's crew memberships

Health & Status States

Life & Physical States

StateTypeDescription
isdeadbooleanPlayer/ped is dead
isDeadbooleanAlternative death state
inHospitalBedbooleanPlayer is in a hospital bed

Restraint & Control States

StateTypeDescription
cuffStatebooleanPlayer is handcuffed
cuffTypenumberType of restraints applied
escortStatebooleanBeing escorted by another player
tackledbooleanPlayer has been tackled

Communication States

Voice & Communication

StateTypeDescription
assignedChannelnumberMumble voice channel assignment
callChannelnumberCurrent phone call channel
radioChannelnumberRadio frequency
submixtableAudio submix settings
isTalkingbooleanCurrently speaking/transmitting

World States

Location & Instance

StateTypeDescription
instancenumberCurrent world instance/dimension
walkstringWalking style/animation set

Usage Examples

Basic Player State Access

-- Check another player's state
local playerId = GetPlayerServerId(NetworkGetPlayerIndexFromPed(ped))
local playerState = Player(playerId)?.state

if playerState then
    -- Check if player is loaded
    if not playerState.isLoaded then
        print("Player is still loading")
        return
    end
    
    -- Get player information
    local playerName = playerState.name
    local racerName = playerState.racername
    local mmr = playerState.mmr
    
    print("Player Info:", playerName, "Racing Name:", racerName, "MMR:", mmr)
end

Health Status Checking

-- Check if player can be interacted with
local function canInteractWithPlayer(playerId)
    local playerState = Player(playerId)?.state
    if not playerState then return false end
    
    -- Can't interact if dead, in hospital, or being escorted
    if playerState.isdead or playerState.inHospitalBed or playerState.escortState then
        return false
    end
    
    return true
end

-- Usage example
local targetPed = GetPlayerPed(GetPlayerFromServerId(targetPlayerId))
if canInteractWithPlayer(targetPlayerId) then
    -- Safe to interact with player
    TriggerEvent('interaction:startWithPlayer', targetPlayerId)
else
    Core.Functions.Notify('Cannot interact with this player right now', 'error')
end

Permission System Integration

-- Check player permissions
local function hasPermission(playerId, permission)
    local playerState = Player(playerId)?.state
    if not playerState or not playerState.groups then
        return false
    end
    
    -- Check if player has the required group
    return playerState.groups[permission] ~= nil
end

-- Example usage
local function canArrestPlayer(officerId, targetId)
    local officerState = Player(officerId)?.state
    local targetState = Player(targetId)?.state
    
    -- Check if officer has police permissions
    if not hasPermission(officerId, 'police') then
        return false, "You don't have police permissions"
    end
    
    -- Check if target is already dead or in hospital
    if targetState and (targetState.isdead or targetState.inHospitalBed) then
        return false, "Cannot arrest - target is dead or in hospital"
    end
    
    -- Check if target is already cuffed
    if targetState and targetState.cuffState then
        return false, "Target is already restrained"
    end
    
    return true
end

Voice System Integration

-- Monitor voice activity from other players
local function setupVoiceMonitoring()
    -- Listen for talking state changes
    AddStateBagChangeHandler('isTalking', '', function(bagName, key, value)
        if bagName:find('player:') then
            local playerId = tonumber(bagName:gsub('player:', ''))
            local playerState = Player(playerId)?.state
            
            if playerState and value then
                -- Player started talking
                local radioChannel = playerState.radioChannel
                local assignedChannel = playerState.assignedChannel
                
                if radioChannel then
                    print("Player", playerId, "is talking on radio channel", radioChannel)
                elseif assignedChannel then
                    print("Player", playerId, "is talking on voice channel", assignedChannel)
                else
                    print("Player", playerId, "is talking on proximity")
                end
            end
        end
    end)
end

-- Check if players are on same radio frequency
local function areOnSameRadio(playerId1, playerId2)
    local state1 = Player(playerId1)?.state
    local state2 = Player(playerId2)?.state
    
    if not state1 or not state2 then return false end
    
    local radio1 = state1.radioChannel
    local radio2 = state2.radioChannel
    
    return radio1 and radio2 and radio1 == radio2
end

Hospital System Integration

-- Monitor hospital bed status
AddStateBagChangeHandler('inHospitalBed', '', function(bagName, key, value)
    if bagName:find('player:') then
        local playerId = tonumber(bagName:gsub('player:', ''))
        local playerState = Player(playerId)?.state
        
        if playerState then
            if value then
                -- Player entered hospital bed
                print("Player", playerState.name, "is now in hospital")
                
                -- Disable certain interactions
                TriggerEvent('medical:playerHospitalized', playerId)
            else
                -- Player left hospital bed
                print("Player", playerState.name, "left hospital")
                
                -- Re-enable interactions
                TriggerEvent('medical:playerReleased', playerId)
            end
        end
    end
end)

Death State Monitoring

-- Monitor player death/revival
AddStateBagChangeHandler('isdead', '', function(bagName, key, value)
    if bagName:find('player:') then
        local playerId = tonumber(bagName:gsub('player:', ''))
        local playerState = Player(playerId)?.state
        
        if playerState then
            if value then
                -- Player died
                print("Player", playerState.name, "has died")
                
                -- Update UI to show death status
                SendNUIMessage({
                    type = 'playerDied',
                    playerId = playerId,
                    playerName = playerState.name
                })
                
                -- Trigger death handling
                TriggerEvent('medical:playerDied', playerId)
            else
                -- Player was revived
                print("Player", playerState.name, "was revived")
                
                -- Update UI to remove death status
                SendNUIMessage({
                    type = 'playerRevived',
                    playerId = playerId,
                    playerName = playerState.name
                })
                
                -- Trigger revival handling
                TriggerEvent('medical:playerRevived', playerId)
            end
        end
    end
end)

Restraint System Integration

-- Monitor cuffing status
AddStateBagChangeHandler('cuffState', '', function(bagName, key, value)
    if bagName:find('player:') then
        local playerId = tonumber(bagName:gsub('player:', ''))
        local playerState = Player(playerId)?.state
        
        if playerState then
            if value then
                -- Player was cuffed
                local cuffType = playerState.cuffType or 1
                local cuffTypeName = cuffType == 1 and "handcuffs" or "zipties"
                
                print("Player", playerState.name, "was restrained with", cuffTypeName)
                
                -- Update interaction options
                TriggerEvent('police:playerCuffed', playerId, cuffType)
            else
                -- Player was uncuffed
                print("Player", playerState.name, "was released from restraints")
                
                -- Restore normal interactions
                TriggerEvent('police:playerUncuffed', playerId)
            end
        end
    end
end)

State Change Handlers

Comprehensive Player Monitoring

-- Set up monitoring for multiple player states
local function setupPlayerStateMonitoring()
    local playerId = GetPlayerServerId(PlayerId())
    
    -- Monitor escort state changes
    AddStateBagChangeHandler('escortState', '', function(bagName, key, value)
        if bagName:find('player:') then
            local targetId = tonumber(bagName:gsub('player:', ''))
            local playerState = Player(targetId)?.state
            
            if playerState then
                if value then
                    print("Player", playerState.name, "is being escorted")
                    TriggerEvent('police:playerEscorted', targetId)
                else
                    print("Player", playerState.name, "is no longer being escorted")
                    TriggerEvent('police:playerReleased', targetId)
                end
            end
        end
    end)
    
    -- Monitor tackle state changes
    AddStateBagChangeHandler('tackled', '', function(bagName, key, value)
        if bagName:find('player:') then
            local targetId = tonumber(bagName:gsub('player:', ''))
            local playerState = Player(targetId)?.state
            
            if playerState and value then
                print("Player", playerState.name, "was tackled")
                TriggerEvent('police:playerTackled', targetId)
            end
        end
    end)
end

-- Initialize monitoring
CreateThread(function()
    -- Wait for local player to load
    while not LocalPlayer.state.isLoaded do
        Wait(100)
    end
    
    -- Set up monitoring systems
    setupPlayerStateMonitoring()
    print("Player state monitoring initialized")
end)

Player states are automatically synchronized across all clients that have the player in scope. Use these states to build responsive multiplayer interactions.

Always check if a player state exists before accessing it, as players can disconnect at any time. Use null-safe access patterns (Player(id)?.state).

State change handlers provide real-time updates when other players' states change, enabling seamless multiplayer system integration.