Fix not receiving props and prop owner names correctly on join

This commit is contained in:
Garrett Brown 2019-10-27 00:30:22 -04:00
parent 6f5c0e0eb7
commit 1fcc45b1fd
2 changed files with 13 additions and 10 deletions

View File

@ -20,14 +20,11 @@ net.Receive("nadmod_propowners",function(len)
end
for i=1, net.ReadUInt(32) do
local id, str = net.ReadUInt(16), nameMap[net.ReadUInt(8)]
if id==0 then break end
if str == "-" then Props[id] = nil PropNames[id] = nil
elseif str == "W" then PropNames[id] = "World"
elseif str == "O" then PropNames[id] = "Ownerless"
else
Props[id] = str
local ply = player.GetBySteamID(str)
PropNames[id] = ply and ply:IsValid() and ply:Nick() or "N/A"
end
end
end)
@ -80,7 +77,16 @@ hook.Add("HUDPaint", "NADMOD.HUDPaint", function()
if !tr.HitNonWorld then return end
local ent = tr.Entity
if ent:IsValid() && !ent:IsPlayer() then
local text = "Owner: " .. (PropNames[ent:EntIndex()] or "N/A")
local index = ent:EntIndex()
local name = PropNames[index]
if not name then
local ply = NADMOD.GetPropOwner(ent)
if ply and ply:IsValid() then
name = ply:Nick()
PropNames[index] = name
end
end
local text = "Owner: " .. (name or "N/A")
surface.SetFont(font)
local Width, Height = surface.GetTextSize(text)
local boxWidth = Width + 25

View File

@ -97,7 +97,6 @@ function NADMOD.SendPropOwners(props, ply)
for i=1, nameMapi do
net.WriteString(nameMap[i])
end
net.WriteUInt(count,32)
for k,v in pairs(props) do
net.WriteUInt(k,16)
@ -117,17 +116,15 @@ end
function NADMOD.PPInitPlayer(ply)
local steamid = ply:SteamID()
for _,v in pairs(NADMOD.Props) do
local tbl = {}
for k, v in pairs(NADMOD.Props) do
tbl[k] = v.SteamID
if v.SteamID == steamid then
v.Owner = ply
v.Ent.SPPOwner = ply
if v.Ent.SetPlayer then v.Ent:SetPlayer(ply) end
end
end
local tbl = {}
for k,v in pairs(NADMOD.Props) do
tbl[k] = v.SteamID
end
NADMOD.SendPropOwners(tbl, ply)
end
hook.Add("PlayerInitialSpawn", "NADMOD.PPInitPlayer", NADMOD.PPInitPlayer)