NetworkConcealPlayer
DocsNetworkConcealPlayer(player, toggle, bAllowDamagingWhileConcealed)Description
This is what R\ uses to hide players in MP interiors.
To manage player visibility with NetworkConcealPlayer, here’s a solid approach:
General Population (players not in any instance):
Use NetworkConcealPlayer to hide players who are in any instance. This way, general population players won’t see or interact with instance players.
Instance Players (players in a specific instance):
- Use NetworkConcealPlayer to hide players who aren’t in the same instance. Instance players can still see and interact with the general population but not with players in other instances.
Parameters
| Name | Type | Description |
|---|---|---|
player | Player | — |
toggle | BOOL | — |
bAllowDamagingWhileConcealed | BOOL | — |
Quick Snippet: Get Playerplayer
playerUse this to get the local player ID or a target player's server ID.
-- Get the local player index (client-side)
local playerId = PlayerId()
-- Get the local player's server ID (for server events)
local serverId = GetPlayerServerId(playerId)
print("Player ID: " .. playerId)
print("Server ID: " .. serverId)
-- Get player ped from a server ID:
-- local targetPed = GetPlayerPed(GetPlayerFromServerId(targetServerId))Returns
voidThis native does not return a value.
Examples
Official
function GetPlayerInstance(player)
-- you can replace this with your own data
local playerServerId = GetPlayerServerId(player)
return Player(playerServerId).state.instance_id or 0
end
local playerId = PlayerId()
-- Function to manage player visibility
function concealPlayers()
local allPlayers = GetActivePlayers()
local localPlayerInstance = GetPlayerInstance(playerId)
for _, player in ipairs(allPlayers) do
if player == playerId then goto continue end
local playerInstance = GetPlayerInstance(player)
if playerInstance == localPlayerInstance then
-- if we're in the same instance then we want to be able to see them
NetworkConcealPlayer(player, false, false)
else
-- they're in a different instance, so hide them
NetworkConcealPlayer(player, true, false)
end
::continue::
end
end
CreateThread(function()
while true do
concealPlayers()
Wait(250)
end
end)