Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- propprotect = {}
- propprotect.PlayerInfo = {}
- function propprotect.StoreInfo(ply)
- local nick = ply:Nick()
- propprotect.PlayerInfo[ply:UniqueID()] =
- {
- steamid = ply:SteamID(),
- nick = function() if ply:IsValid() then return ply:Nick() end return nick end,
- player = ply,
- }
- end
- function propprotect.CanModify(ply, ent)
- propprotect.StoreInfo(ply)
- return ply:CheckUserGroupLevel("moderators") or ply:AreFriends(ent:GetRealOwner()) or ent:GetRealOwner() == ply
- end
- do -- meta
- local ENT = FindMetaTable("Entity")
- function ENT:GetRealOwnerSteamID()
- local data = propprotect.PlayerInfo[self:GetNWString("pp_owner")]
- return data and data.steamid or ""
- end
- function ENT:GetRealOwnerNick()
- local data = propprotect.PlayerInfo[self:GetNWString("pp_owner")]
- return data and data.nick and data.nick() or ""
- end
- function ENT:GetRealOwner()
- local data = propprotect.PlayerInfo[self:GetNWString("pp_owner")]
- return data and data.player or NULL
- end
- function ENT:CPPIGetOwner()
- return self:GetRealOwner(), util.CRC("gm_" .. self:GetRealOwnerSteamID() .. "_gm")
- end
- end
- do -- pickup hooks
- hook.Add("CanTool", "propprotect", function(ply, data, mode)
- return propprotect.CanModify(ply, data.Entity)
- end)
- hook.Add("AllowPlayerPickup", "propprotect", function(ply, ent)
- return propprotect.CanModify(ply, ent)
- end)
- hook.Add("GravGunPickupAllowed", "propprotect", function(ply, ent)
- return propprotect.CanModify(ply, ent)
- end)
- hook.Add("PhysgunPickup", "propprotect", function(ply, ent)
- return propprotect.CanModify(ply, ent)
- end)
- hook.Add("PhysgunPickup", "propprotect", function(ply, ent)
- return propprotect.CanModify(ply, ent)
- end)
- hook.Add("EntityTakeDamage", "propprotect", function(ent, _, ply, _, dmginfo)
- if ply:IsPlayer() and ent:IsValid() and not propprotect.CanModify(ply, ent) then
- dmginfo:SetDamage(0)
- end
- end)
- end
- if CLIENT then
- usermessage.Hook("propprotect_spawn", function(umr)
- local ply = umr:ReadEntity()
- local ent = umr:ReadEntity()
- if ply:IsPlayer() and ent:IsValid() then
- propprotect.StoreInfo(ply)
- end
- end)
- timer.Create("propprotect_lookat", 1, 0, function()
- local ent = LocalPlayer():GetEyeTrace().Entity
- if ent:IsValid() then
- local nick = ent:GetRealOwnerNick()
- if nick ~= "" then
- local allowed = propprotect.CanModify(LocalPlayer(), ent)
- GAMEMODE:AddNotify(nick, allowed and NOTIFY_GENERIC or NOTIFY_ERROR, 1)
- end
- end
- end)
- end
- if SERVER then
- function propprotect.PlayerSpawnedEntity(ply, ent, skip_nw)
- ent:SetNWString("pp_owner", ply:UniqueID())
- if not skip_nw then
- umsg.Start("propprotect_spawn")
- umsg.Entity(ply)
- umsg.Entity(ent)
- umsg.End()
- end
- end
- do -- spawn hooks
- hook.Add("PlayerSpawnedEffect", "propprotect", function(ply, _, ent)
- propprotect.PlayerSpawnedEntity(ply, ent)
- end)
- hook.Add("PlayerSpawnedNPC", "propprotect", function(ply, ent)
- propprotect.PlayerSpawnedEntity(ply, ent)
- end)
- hook.Add("PlayerSpawnedProp", "propprotect", function(ply, _, ent)
- propprotect.PlayerSpawnedEntity(ply, ent)
- end)
- hook.Add("PlayerSpawnedRagdoll", "propprotect", function(ply, _, ent)
- propprotect.PlayerSpawnedEntity(ply, ent)
- end)
- hook.Add("PlayerSpawnedSENT", "propprotect", function(ply, ent)
- propprotect.PlayerSpawnedEntity(ply, ent)
- end)
- hook.Add("PlayerSpawnedVehicle", "propprotect", function(ply, ent)
- propprotect.PlayerSpawnedEntity(ply, ent)
- end)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment