forked from Nebual/NadmodPP
Merge pull request #5 from thegrb93/fix
Fix new networking not receiving props and prop owner names correctly on join
This commit is contained in:
commit
e30a4d5247
@ -16,18 +16,16 @@ local PropNames = NADMOD.PropNames
|
||||
net.Receive("nadmod_propowners",function(len)
|
||||
local nameMap = {}
|
||||
for i=1, net.ReadUInt(8) do
|
||||
nameMap[i] = net.ReadString()
|
||||
nameMap[i] = {SteamID = net.ReadString(), Name = net.ReadString()}
|
||||
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"
|
||||
local id, owner = net.ReadUInt(16), nameMap[net.ReadUInt(8)]
|
||||
if owner.SteamID == "-" then Props[id] = nil PropNames[id] = nil
|
||||
elseif owner.SteamID == "W" then PropNames[id] = "World"
|
||||
elseif owner.SteamID == "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"
|
||||
Props[id] = owner.SteamID
|
||||
PropNames[id] = owner.Name
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
@ -86,22 +86,22 @@ function NADMOD.SendPropOwners(props, ply)
|
||||
local nameMapi = 0
|
||||
local count = 0
|
||||
for k,v in pairs(props) do
|
||||
if not nameMap[v] then
|
||||
if not nameMap[v.SteamID] then
|
||||
nameMapi = nameMapi + 1
|
||||
nameMap[v] = nameMapi
|
||||
nameMap[v.SteamID] = nameMapi
|
||||
nameMap[nameMapi] = v
|
||||
end
|
||||
count = count + 1
|
||||
end
|
||||
net.WriteUInt(nameMapi,8)
|
||||
for i=1, nameMapi do
|
||||
net.WriteString(nameMap[i])
|
||||
net.WriteString(nameMap[i].SteamID)
|
||||
net.WriteString(nameMap[i].Name)
|
||||
end
|
||||
|
||||
net.WriteUInt(count,32)
|
||||
for k,v in pairs(props) do
|
||||
net.WriteUInt(k,16)
|
||||
net.WriteUInt(nameMap[v],8)
|
||||
net.WriteUInt(nameMap[v.SteamID],8)
|
||||
end
|
||||
if ply then net.Send(ply) else net.Broadcast() end
|
||||
end
|
||||
@ -117,18 +117,14 @@ end
|
||||
|
||||
function NADMOD.PPInitPlayer(ply)
|
||||
local steamid = ply:SteamID()
|
||||
for _,v in pairs(NADMOD.Props) do
|
||||
for k, v in pairs(NADMOD.Props) do
|
||||
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)
|
||||
NADMOD.SendPropOwners(NADMOD.Props, ply)
|
||||
end
|
||||
hook.Add("PlayerInitialSpawn", "NADMOD.PPInitPlayer", NADMOD.PPInitPlayer)
|
||||
|
||||
@ -282,13 +278,14 @@ function NADMOD.PlayerMakePropOwner(ply,ent)
|
||||
if !IsValid(ent) or ent:IsPlayer() then return end
|
||||
if ply:IsWorld() then return NADMOD.SetOwnerWorld(ent) end
|
||||
if !IsValid(ply) or !ply:IsPlayer() then return end
|
||||
NADMOD.Props[ent:EntIndex()] = {
|
||||
local index = ent:EntIndex()
|
||||
NADMOD.Props[index] = {
|
||||
Ent = ent,
|
||||
Owner = ply,
|
||||
SteamID = ply:SteamID(),
|
||||
Name = ply:Nick()
|
||||
}
|
||||
NADMOD.PropOwnersSmall[ent:EntIndex()] = ply:SteamID()
|
||||
NADMOD.PropOwnersSmall[index] = NADMOD.Props[index]
|
||||
ent.SPPOwner = ply
|
||||
NADMOD.RefreshOwners()
|
||||
end
|
||||
@ -317,13 +314,14 @@ hook.Add("PlayerSpawnedSWEP", "NADMOD.PlayerSpawnedSWEP", NADMOD.PlayerMakePropO
|
||||
function metaent:CPPISetOwnerless(bool)
|
||||
if !IsValid(self) or self:IsPlayer() then return end
|
||||
if(bool) then
|
||||
NADMOD.Props[self:EntIndex()] = {
|
||||
local index = self:EntIndex()
|
||||
NADMOD.Props[index] = {
|
||||
Ent = self,
|
||||
Owner = game.GetWorld(),
|
||||
SteamID = "O",
|
||||
Name = "O"
|
||||
}
|
||||
NADMOD.PropOwnersSmall[self:EntIndex()] = "O"
|
||||
NADMOD.PropOwnersSmall[index] = NADMOD.Props[index]
|
||||
self.SPPOwner = game.GetWorld()
|
||||
NADMOD.RefreshOwners()
|
||||
else
|
||||
@ -332,13 +330,14 @@ function metaent:CPPISetOwnerless(bool)
|
||||
end
|
||||
|
||||
function NADMOD.SetOwnerWorld(ent)
|
||||
NADMOD.Props[ent:EntIndex()] = {
|
||||
local index = ent:EntIndex()
|
||||
NADMOD.Props[index] = {
|
||||
Ent = ent,
|
||||
Owner = game.GetWorld(),
|
||||
SteamID = "W",
|
||||
Name = "W"
|
||||
}
|
||||
NADMOD.PropOwnersSmall[ent:EntIndex()] = "W"
|
||||
NADMOD.PropOwnersSmall[index] = NADMOD.Props[index]
|
||||
ent.SPPOwner = game.GetWorld()
|
||||
NADMOD.RefreshOwners()
|
||||
end
|
||||
@ -366,7 +365,7 @@ end)
|
||||
|
||||
function NADMOD.EntityRemoved(ent)
|
||||
NADMOD.Props[ent:EntIndex()] = nil
|
||||
NADMOD.PropOwnersSmall[ent:EntIndex()] = "-"
|
||||
NADMOD.PropOwnersSmall[ent:EntIndex()] = {SteamID = "-", Name = "-"}
|
||||
NADMOD.RefreshOwners()
|
||||
if ent:IsValid() and ent:IsPlayer() and not ent:IsBot() then
|
||||
-- This is more reliable than PlayerDisconnect
|
||||
|
Loading…
Reference in New Issue
Block a user