Addressed issues

This commit is contained in:
Garrett Brown 2019-10-26 05:00:19 -04:00
parent 646d7f022c
commit e88a2499d1
2 changed files with 37 additions and 36 deletions

View File

@ -6,23 +6,28 @@
if !NADMOD then if !NADMOD then
NADMOD = {} NADMOD = {}
NADMOD.PropOwners = {} NADMOD.PropOwners = {}
NADMOD.PropNames = {}
NADMOD.PPConfig = {} NADMOD.PPConfig = {}
NADMOD.Friends = {} NADMOD.Friends = {}
end end
local Props = NADMOD.PropOwners local Props = NADMOD.PropOwners
local PropNames = NADMOD.PropNames
net.Receive("nadmod_propowners",function(len) net.Receive("nadmod_propowners",function(len)
local set = {} local nameMap = {}
for i=1, net.ReadUInt(8) do for i=1, net.ReadUInt(8) do
set[i] = net.ReadString() nameMap[i] = net.ReadString()
end end
for i=1, net.ReadUInt(32) do for i=1, net.ReadUInt(32) do
local id, str = net.ReadUInt(16), set[net.ReadUInt(8)] local id, str = net.ReadUInt(16), nameMap[net.ReadUInt(8)]
if id==0 then break end if id==0 then break end
if str == "-" then Props[id] = nil if str == "-" then Props[id] = nil PropNames[id] = nil
elseif str == "W" then Props[id] = "World" elseif str == "W" then PropNames[id] = "World"
elseif str == "O" then Props[id] = "Ownerless" elseif str == "O" then PropNames[id] = "Ownerless"
else Props[id] = str else
Props[id] = str
local ply = player.GetBySteamID(str)
PropNames[id] = ply and ply:IsValid() and ply:Nick() or "N/A"
end end
end end
end) end)
@ -44,11 +49,14 @@ function NADMOD.PlayerCanTouch(ply, ent)
end end
-- Ownerless props can be touched by all -- Ownerless props can be touched by all
if Props[index] == "O" then return true end if PropNames[index] == "Ownerless" then return true end
-- Admins can touch anyones props + world -- Admins can touch anyones props + world
if NADMOD.PPConfig["adminall"] and NADMOD.IsPPAdmin(ply) then return true end if NADMOD.PPConfig["adminall"] and NADMOD.IsPPAdmin(ply) then return true end
-- Players can touch their own props and friends -- Players can touch their own props
if Props[index] == ply:SteamID() then return true end local plySteam = ply:SteamID()
if Props[index] == plySteam then return true end
-- Friends can touch LocalPlayer()'s props
if Props[index] == LocalPlayer():SteamID() and NADMOD.Friends[plySteam] then return true end
return false return false
end end
@ -72,14 +80,7 @@ hook.Add("HUDPaint", "NADMOD.HUDPaint", function()
if !tr.HitNonWorld then return end if !tr.HitNonWorld then return end
local ent = tr.Entity local ent = tr.Entity
if ent:IsValid() && !ent:IsPlayer() then if ent:IsValid() && !ent:IsPlayer() then
local index = ent:EntIndex() local text = "Owner: " .. (PropNames[ent:EntIndex()] or "N/A")
local text
local owner = NADMOD.GetPropOwner(ent)
if owner and owner:IsValid() then
text = "Owner: " .. owner:Nick()
else
text = "Owner: N/A"
end
surface.SetFont(font) surface.SetFont(font)
local Width, Height = surface.GetTextSize(text) local Width, Height = surface.GetTextSize(text)
local boxWidth = Width + 25 local boxWidth = Width + 25

View File

@ -82,26 +82,26 @@ end
function NADMOD.SendPropOwners(props, ply) function NADMOD.SendPropOwners(props, ply)
net.Start("nadmod_propowners") net.Start("nadmod_propowners")
local seti = 1 local nameMap = {}
local set = {} local nameMapi = 0
local count = 0 local count = 0
for k,v in pairs(props) do for k,v in pairs(props) do
if not set[v] then if not nameMap[v] then
set[v] = seti nameMapi = nameMapi + 1
set[seti] = v nameMap[v] = nameMapi
seti = seti + 1 nameMap[nameMapi] = v
end end
count = count + 1 count = count + 1
end end
net.WriteUInt(seti-1,8) net.WriteUInt(nameMapi,8)
for i=1, seti-1 do for i=1, nameMapi do
net.WriteString(set[i]) net.WriteString(nameMap[i])
end end
net.WriteUInt(count,32) net.WriteUInt(count,32)
for k,v in pairs(props) do for k,v in pairs(props) do
net.WriteUInt(k,16) net.WriteUInt(k,16)
net.WriteUInt(set[v],8) net.WriteUInt(nameMap[v],8)
end end
if ply then net.Send(ply) else net.Broadcast() end if ply then net.Send(ply) else net.Broadcast() end
end end
@ -109,7 +109,7 @@ end
function NADMOD.RefreshOwners() function NADMOD.RefreshOwners()
if not timer.Exists("NADMOD.RefreshOwners") then if not timer.Exists("NADMOD.RefreshOwners") then
timer.Create("NADMOD.RefreshOwners", 0, 1, function() timer.Create("NADMOD.RefreshOwners", 0, 1, function()
NADMOD.SendPropOwners(NADMOD.PropOwnersSmall, ply) NADMOD.SendPropOwners(NADMOD.PropOwnersSmall)
NADMOD.PropOwnersSmall = {} NADMOD.PropOwnersSmall = {}
end) end)
end end
@ -182,11 +182,11 @@ function NADMOD.PlayerCanTouch(ply, ent)
end end
if !NADMOD.Props[index] then if !NADMOD.Props[index] then
-- To get here implies the ent has a 'valid' GetPlayer()/GetOwner(), but still couldn't get set properly -- To get here implies the ent has a 'valid' GetPlayer()/GetOwner(), but still couldn't get set properly
-- For example, if an NPC is sitting in jeep (??), the jeep's GetPlayer returns the driver? or something -- For example, if an NPC is sitting in jeep (??), the jeep's GetPlayer returns the driver? or something
ent:CPPISetOwnerless(true) ent:CPPISetOwnerless(true)
if !NADMOD.Props[index] then return false end if !NADMOD.Props[index] then return false end
end end
end end
-- Ownerless props can be touched by all -- Ownerless props can be touched by all
@ -416,7 +416,7 @@ end
function NADMOD.CleanPlayer(ply, tar) function NADMOD.CleanPlayer(ply, tar)
if IsValid(tar) and tar:IsPlayer() then if IsValid(tar) and tar:IsPlayer() then
local count = NADMOD.CleanupPlayerProps(tar:SteamID()) local count = NADMOD.CleanupPlayerProps(tar:SteamID())
NADMOD.Notify(ply:Nick().. " cleaned up " ..tar:Nick().."'s props ("..count..")") NADMOD.Notify((ply:IsValid() and ply:Nick() or "Console") .. " cleaned up " ..tar:Nick().."'s props ("..count..")")
end end
end end
@ -449,7 +449,7 @@ function NADMOD.CleanName(ply, cmd, args, fullstr)
count = count + 1 count = count + 1
end end
end end
NADMOD.Notify(ply:Nick() .. " cleaned up " ..fullstr.."'s props ("..count..")") NADMOD.Notify((ply:IsValid() and ply:Nick() or "Console") .. " cleaned up " ..fullstr.."'s props ("..count..")")
end end
concommand.Add("nadmod_cleanname",NADMOD.CleanName) concommand.Add("nadmod_cleanname",NADMOD.CleanName)
@ -588,7 +588,7 @@ end
function metaent:CPPIGetOwner() return self.SPPOwner end function metaent:CPPIGetOwner() return self.SPPOwner end
function metaent:CPPISetOwner(ply) return NADMOD.PlayerMakePropOwner(ply, self) end function metaent:CPPISetOwner(ply) return NADMOD.PlayerMakePropOwner(ply, self) end
function metaent:CPPICanTool(ply,mode) return NADMOD.CanTool(ply,{Entity=self},mode) != false end function metaent:CPPICanTool(ply,mode) return NADMOD.CanTool(ply,{Entity=self},mode) != false end
function metaent:CPPICanPhysgun(ply) return NADMOD.PlayerCanTouch(ply,self) end function metaent:CPPICanPhysgun(ply) return NADMOD.PlayerCanTouch(ply,self) == true end
function metaent:CPPICanPickup(ply) return NADMOD.GravGunPickup(ply, self) != false end function metaent:CPPICanPickup(ply) return NADMOD.GravGunPickup(ply, self) != false end
function metaent:CPPICanPunt(ply) return NADMOD.GravGunPickup(ply, self) != false end function metaent:CPPICanPunt(ply) return NADMOD.GravGunPickup(ply, self) != false end
if E2Lib and E2Lib.replace_function then if E2Lib and E2Lib.replace_function then