From dd0050f053b6c39ce3283468ad3436d35c655c56 Mon Sep 17 00:00:00 2001 From: Dillon Skaggs Date: Thu, 15 Aug 2024 15:03:00 -0500 Subject: [PATCH] tweak: define all functions that will be used in the example --- NETWORK/NetworkConcealPlayer.md | 49 ++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/NETWORK/NetworkConcealPlayer.md b/NETWORK/NetworkConcealPlayer.md index ce3b6195d..bb2de07bb 100644 --- a/NETWORK/NetworkConcealPlayer.md +++ b/NETWORK/NetworkConcealPlayer.md @@ -28,28 +28,39 @@ This setup keeps instance players separate from each other while allowing intera * **bAllowDamagingWhileConcealed**: ```lua +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(instanceId) - local allPlayers = GetPlayers() +function concealPlayers() + local allPlayers = GetActivePlayers() + local localPlayerInstance = GetPlayerInstance(playerId) for _, player in ipairs(allPlayers) do - local playerInstance = GetPlayerInstance(player) -- You need to define this function - - if instanceId == nil then - -- General population: hide players in any instance - if playerInstance ~= nil then - NetworkConcealPlayer(player, true, false) - else - NetworkConcealPlayer(player, false, false) - end - else - -- Instance players: hide players not in the same instance - if playerInstance ~= instanceId then - NetworkConcealPlayer(player, true, false) - else - NetworkConcealPlayer(player, false, false) - end - end + 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) ```