CapsAdmin

Untitled

Mar 29th, 2012
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.92 KB | None | 0 0
  1. local distance = 1000
  2. local eye_origin = vector_origin
  3.  
  4. distance = distance * distance
  5.  
  6. hook.Add("RenderScene", "hide_entities", function(pos)
  7.     eye_origin = pos
  8. end)
  9.  
  10. local function IsAllowed(ent)
  11.     return ent:IsValid() and not ent:IsPlayer()
  12. end
  13.  
  14. local function ShouldHide(ent)
  15.     return (ent:GetPos() - eye_origin):LengthSqr() > distance
  16. end
  17.  
  18. local init_hidden = {}
  19.  
  20. local function CheckEntity(ent)
  21.     if not init_hidden[ent:EntIndex()] then
  22.         ent:SetNoDraw(true)
  23.         init_hidden[ent:EntIndex()] = ent
  24.     end
  25.     if ShouldHide(ent) then
  26.         if not ent.he_hiding then
  27.             ent:SetNoDraw(true)
  28.             ent.he_hiding = true
  29.             print("hiding ", ent)
  30.         end
  31.     else
  32.         if ent.he_hiding then
  33.             ent:SetNoDraw(false)
  34.             ent.he_hiding = nil
  35.             print("showing ", ent)
  36.         end
  37.     end
  38. end
  39.  
  40. timer.Create("hide_entities", 0.2, 0, function()
  41.     for key, ent in pairs(ents.GetAll()) do
  42.         if IsAllowed(ent) then
  43.             CheckEntity(ent)
  44.         end
  45.     end
  46. end)
Advertisement
Add Comment
Please, Sign In to add comment