Advertisement
fluffy_dev

Untitled

Dec 25th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.56 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 entitiesToRemove[v.e:GetClass()]) then
  22.             if (v.e.CPPIGetOwner and IsValid(v.e:CPPIGetOwner()) and v.e:CPPIGetOwner() == ply) then
  23.                 v.e:Remove();
  24.  
  25.                 continue;
  26.             end
  27.  
  28.             if (v.e.Getowning_ent and IsValid(v.e:Getowning_ent()) and v.e:Getowning_ent() == ply) then
  29.                 v.e:Remove();
  30.             end
  31.         end
  32.     end
  33. end);
  34.  
  35. hook.Add("OnPlayerChangedTeam", "removenets_on_jobchange", function(ply, old, new)
  36.     for k, v in ipairs(cachedEntites) do
  37.         if (IsValid(v.e) and entitiesToRemove[v.e:GetClass()]) then
  38.             if (v.e.CPPIGetOwner and IsValid(v.e:CPPIGetOwner()) and v.e:CPPIGetOwner() == ply) then
  39.                 v.e:Remove();
  40.  
  41.                 continue;
  42.             end
  43.  
  44.             if (v.e.Getowning_ent and IsValid(v.e:Getowning_ent()) and v.e:Getowning_ent() == ply) then
  45.                 v.e:Remove();
  46.             end
  47.         end
  48.     end
  49. end);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement