Advertisement
code_gs

Untitled

Mar 10th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.63 KB | None | 0 0
  1. local tDrawPlayers = {}
  2. local uDrawPlayers = 0
  3.  
  4. function AddDrawPlayer(pPlayer)
  5.     -- Only increment if the player isn't already in the table
  6.     if (not tDrawPlayers[pPlayer]) then
  7.         uDrawPlayers = uDrawPlayers + 1
  8.         tDrawPlayers[uDrawPlayers] = pPlayer -- Store in array for quick iteration
  9.         tDrawPlayers[pPlayer] = uDrawPlayers -- Store in hash for quick lookup
  10.     end
  11. end
  12.  
  13. function RemoveDrawPlayer(pPlayer)
  14.     local uIndex = tDrawPlayers[pPlayer]
  15.  
  16.     if (uIndex ~= nil) then
  17.         -- If we removed the tail, just do a normal removal
  18.         if (uIndex == uDrawPlayers) then
  19.             tDrawPlayers[pPlayer] = nil
  20.             tDrawPlayers[uIndex] = nil
  21.         -- If we removed a player in the middle of the array
  22.         -- fill the hole with the tail
  23.         else
  24.             local pLastPlayer = tDrawPlayers[uDrawPlayers]
  25.             tDrawPlayers[uIndex] = pLastPlayer
  26.             tDrawPlayers[pLastPlayer] = uIndex -- Update the index in the hash entry
  27.             tDrawPlayers[uDrawPlayers] = nil
  28.         end
  29.  
  30.         uDrawPlayers = uDrawPlayers - 1
  31.     end
  32. end
  33.  
  34. local bDontDrawPlayers = false
  35.  
  36. -- Don't draw any of our targetted players between PreRender and PostRender
  37. hook.Add("PreRender", "foo", function()
  38.     bDontDrawPlayers = true
  39. end)
  40.  
  41. hook.Add("PrePlayerDraw", "foo", function(pPlayer)
  42.     if (bDontDrawPlayers and tDrawPlayers[pPlayer] ~= nil) then
  43.         return true
  44.     end
  45. end)
  46.  
  47. hook.Add("PostRender", "foo", function()
  48.     bDontDrawPlayers = false
  49.  
  50.     if (uDrawPlayers ~= 0) then
  51.         cam.Start3D()
  52.             for i = 1, uDrawPlayers do
  53.                 tDrawPlayers[uDrawPlayers]:DrawModel()
  54.             end
  55.         cam.End3D()
  56.     end
  57.  
  58.     -- Leave the skip-draw bool as false so any player rendering outside of the standard render context aren't blocked
  59. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement