slashkeyvalue

concealment

Jul 6th, 2021 (edited)
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.87 KB | None | 0 0
  1. local gIsConcealmentRunning = false
  2. local gConcealedNetPlayers = { }
  3. local gIgnoreMap = { }
  4.  
  5. function InitConcealment(ignoreList)
  6.     if #ignoreList > 0 then
  7.         for _, ignoredNetPlayer in ipairs(ignoreList) do
  8.             gIgnoreMap[ignoredNetPlayer] = true
  9.         end
  10.     end
  11.  
  12.     RunConcealment()
  13. end
  14.  
  15. function RunConcealment()
  16.     if gIsConcealmentRunning then
  17.         return
  18.     end
  19.  
  20.     gIsConcealmentRunning = true    
  21.  
  22.     CreateThread(function()
  23.         while true do
  24.  
  25.             local keepRunning = false
  26.  
  27.             if not IsHashMapEmpty(gConcealedNetPlayers) then
  28.                 keepRunning = true
  29.  
  30.                 for playerNetId, _ in pairs(gConcealedNetPlayers) do
  31.                      if not gIsConcealmentRunning or gIgnoreMap[playerNetId] then
  32.                         NetworkConcealPlayer(playerIndex, false, false)
  33.  
  34.                         gConcealedNetPlayers[playerNetId] = nil
  35.                      end
  36.                 end
  37.             end
  38.  
  39.             if gIsConcealmentRunning then
  40.                 keepRunning = true
  41.  
  42.                 for _, playerIndex in ipairs(GetActivePlayers()) do
  43.                     local playerNetId = GetPlayerServerId(playerIndex)
  44.  
  45.                     local isConcealed = gConcealedNetPlayers[playerNetId] ~= nil
  46.  
  47.                     if not isConcealed then
  48.                         if not gIgnoreMap[playerNetId] then
  49.                             NetworkConcealPlayer(playerIndex, true, true)
  50.  
  51.                             gConcealedNetPlayers[playerNetId] = true
  52.                         end
  53.                     end
  54.                 end
  55.             end
  56.  
  57.             if not keepRunning then
  58.                 break
  59.             end
  60.  
  61.             Wait(500)
  62.         end
  63.     end)
  64. end
  65.  
  66. function IsHashMapEmpty(hashMap)
  67.     for _, _ in pairs(hashMap) do
  68.         return false
  69.     end
  70.  
  71.     return true
  72. end
Add Comment
Please, Sign In to add comment