Advertisement
fluffy_dev

Untitled

Dec 12th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.25 KB | None | 0 0
  1. local entitiesToRemove = {
  2.     ["prop_physics"] = true,
  3.     ["money_printer"] = true,
  4. }
  5.  
  6. local cachedEntites = {};
  7. hook.Add("OnEntityCreated", "cache_entities", function(ent)
  8.     table.insert(cachedEntites, {e = ent});
  9. end);
  10.  
  11. hook.Add("EntityRemoved", "remove_cached_entities", function(ent)
  12.     for k, v in ipairs(cachedEntites) do
  13.         if (IsValid(v.e) and v.e:GetClass() == ent:GetClass()) then
  14.             table.remove(cachedEntites, k);
  15.         end
  16.     end
  17. end);
  18.  
  19. hook.Add("PlayerDisconnected", "remove_ents_on_disconnect", function(ply)
  20.     for k, v in ipairs(cachedEntites) do
  21.         if (IsValid(v.e) and v.e:GetClass() == ent:GetClass()) then
  22.             table.remove(cachedEntites, k);
  23.         end
  24.     end
  25. end);
  26.  
  27. hook.Add("OnPlayerChangedTeam", "removenets_on_jobchange", function(ply, old, new)
  28.     for k, v in ipairs(cachedEntites) do
  29.         if (IsValid(v.e) and entitiesToRemove[v.e:GetClass()]) then
  30.             if (v.e.CPPIGetOwner and IsValid(v.e:CPPIGetOwner()) and v.e:CPPIGetOwner() == ply) then
  31.                 v.e:Remove();
  32.             end
  33.  
  34.             if (v.e.Getowning_ent and IsValid(v.e:Getowning_ent()) and v.e:Getowning_ent() == ply) then
  35.                 v.e:Remove();
  36.             end
  37.         end
  38.     end
  39. end);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement