Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local distance = 4000
- local eye_origin = vector_origin
- distance = distance * distance
- hook.Add("RenderScene", "hide_entities", function(pos)
- eye_origin = pos
- end)
- local function IsAllowed(ent)
- return ent:IsValid() and not ent:IsPlayer()
- end
- local function ShouldHide(ent)
- return (ent:GetPos() - eye_origin):LengthSqr() > distance
- end
- local init_hidden = {}
- local function CheckEntity(ent)
- if not init_hidden[ent:EntIndex()] then
- ent:SetNoDraw(true)
- init_hidden[ent:EntIndex()] = ent
- end
- if ShouldHide(ent) then
- if not ent.he_hiding then
- ent:SetNoDraw(true)
- ent.he_hiding = true
- print("hiding ", ent)
- end
- else
- if ent.he_hiding then
- ent:SetNoDraw(false)
- ent.he_hiding = nil
- print("showing ", ent)
- end
- end
- end
- timer.Create("hide_entities", 0.2, 0, function()
- for key, ent in pairs(ents.GetAll()) do
- if IsAllowed(ent) then
- CheckEntity(ent)
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment