CapsAdmin

Untitled

Jun 16th, 2012
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.54 KB | None | 0 0
  1. propprotect = {}
  2. propprotect.PlayerInfo = {}
  3.  
  4. function propprotect.StoreInfo(ply)
  5.     local nick = ply:Nick()
  6.     propprotect.PlayerInfo[ply:UniqueID()] =
  7.     {
  8.         steamid = ply:SteamID(),
  9.         nick =  function() if ply:IsValid() then return ply:Nick() end return nick end,
  10.         player = ply,
  11.     }
  12. end
  13.  
  14. function propprotect.CanModify(ply, ent)
  15.     propprotect.StoreInfo(ply)
  16.     return ply:CheckUserGroupLevel("moderators") or ply:AreFriends(ent:GetRealOwner()) or ent:GetRealOwner() == ply
  17. end
  18.  
  19. do -- meta
  20.     local ENT = FindMetaTable("Entity")
  21.    
  22.     function ENT:GetRealOwnerSteamID() 
  23.         local data = propprotect.PlayerInfo[self:GetNWString("pp_owner")]
  24.        
  25.         return data and data.steamid or ""
  26.     end
  27.        
  28.     function ENT:GetRealOwnerNick()
  29.         local data = propprotect.PlayerInfo[self:GetNWString("pp_owner")]
  30.        
  31.         return data and data.nick and data.nick() or ""
  32.     end
  33.    
  34.     function ENT:GetRealOwner()
  35.         local data = propprotect.PlayerInfo[self:GetNWString("pp_owner")]
  36.        
  37.         return data and data.player or NULL
  38.     end
  39.    
  40.     function ENT:CPPIGetOwner()
  41.         return self:GetRealOwner(), util.CRC("gm_" .. self:GetRealOwnerSteamID() .. "_gm")
  42.     end
  43. end
  44.    
  45. do -- pickup hooks
  46.     hook.Add("CanTool", "propprotect", function(ply, data, mode)
  47.         return propprotect.CanModify(ply, data.Entity)
  48.     end)
  49.    
  50.     hook.Add("AllowPlayerPickup", "propprotect", function(ply, ent)
  51.         return propprotect.CanModify(ply, ent)
  52.     end)
  53.    
  54.     hook.Add("GravGunPickupAllowed", "propprotect", function(ply, ent)
  55.         return propprotect.CanModify(ply, ent)
  56.     end)       
  57.    
  58.     hook.Add("PhysgunPickup", "propprotect", function(ply, ent)
  59.         return propprotect.CanModify(ply, ent)
  60.     end)   
  61.    
  62.     hook.Add("PhysgunPickup", "propprotect", function(ply, ent)
  63.         return propprotect.CanModify(ply, ent)
  64.     end)
  65.    
  66.     hook.Add("EntityTakeDamage", "propprotect", function(ent, _, ply, _, dmginfo)
  67.         if ply:IsPlayer() and ent:IsValid() and not propprotect.CanModify(ply, ent) then
  68.             dmginfo:SetDamage(0)
  69.         end
  70.     end)   
  71. end
  72.  
  73. if CLIENT then
  74.     usermessage.Hook("propprotect_spawn", function(umr)
  75.         local ply = umr:ReadEntity()
  76.         local ent = umr:ReadEntity()
  77.        
  78.         if ply:IsPlayer() and ent:IsValid() then
  79.             propprotect.StoreInfo(ply)
  80.         end
  81.     end)
  82.    
  83.     timer.Create("propprotect_lookat", 1, 0, function()
  84.         local ent = LocalPlayer():GetEyeTrace().Entity
  85.         if ent:IsValid() then
  86.             local nick = ent:GetRealOwnerNick()
  87.             if nick ~= "" then
  88.                 local allowed = propprotect.CanModify(LocalPlayer(), ent)
  89.                 GAMEMODE:AddNotify(nick, allowed and NOTIFY_GENERIC or NOTIFY_ERROR, 1)
  90.             end
  91.         end
  92.     end)
  93. end
  94.  
  95. if SERVER then
  96.     function propprotect.PlayerSpawnedEntity(ply, ent, skip_nw)
  97.         ent:SetNWString("pp_owner", ply:UniqueID())
  98.        
  99.         if not skip_nw then
  100.             umsg.Start("propprotect_spawn")
  101.                 umsg.Entity(ply)
  102.                 umsg.Entity(ent)
  103.             umsg.End()
  104.         end
  105.     end
  106.    
  107.     do -- spawn hooks
  108.         hook.Add("PlayerSpawnedEffect", "propprotect", function(ply, _, ent)
  109.             propprotect.PlayerSpawnedEntity(ply, ent)
  110.         end)
  111.  
  112.         hook.Add("PlayerSpawnedNPC", "propprotect", function(ply, ent)
  113.             propprotect.PlayerSpawnedEntity(ply, ent)
  114.         end)
  115.        
  116.         hook.Add("PlayerSpawnedProp", "propprotect", function(ply, _, ent)
  117.             propprotect.PlayerSpawnedEntity(ply, ent)
  118.         end)   
  119.        
  120.         hook.Add("PlayerSpawnedRagdoll", "propprotect", function(ply, _, ent)
  121.             propprotect.PlayerSpawnedEntity(ply, ent)
  122.         end)
  123.                    
  124.         hook.Add("PlayerSpawnedSENT", "propprotect", function(ply, ent)
  125.             propprotect.PlayerSpawnedEntity(ply, ent)
  126.         end)
  127.                
  128.         hook.Add("PlayerSpawnedVehicle", "propprotect", function(ply, ent)
  129.             propprotect.PlayerSpawnedEntity(ply, ent)
  130.         end)
  131.     end
  132. end
Advertisement
Add Comment
Please, Sign In to add comment