mirror of
https://github.com/Nebual/NadmodPP.git
synced 2025-03-04 03:03:10 -05:00
Have server transmit player name
This commit is contained in:
parent
1fcc45b1fd
commit
6f88e5352b
@ -16,15 +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 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
|
||||
Props[id] = owner.SteamID
|
||||
PropNames[id] = owner.Name
|
||||
end
|
||||
end
|
||||
end)
|
||||
@ -77,16 +78,7 @@ hook.Add("HUDPaint", "NADMOD.HUDPaint", function()
|
||||
if !tr.HitNonWorld then return end
|
||||
local ent = tr.Entity
|
||||
if ent:IsValid() && !ent:IsPlayer() then
|
||||
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")
|
||||
local text = "Owner: " .. (PropNames[ent:EntIndex()] or "N/A")
|
||||
surface.SetFont(font)
|
||||
local Width, Height = surface.GetTextSize(text)
|
||||
local boxWidth = Width + 25
|
||||
|
@ -95,7 +95,8 @@ function NADMOD.SendPropOwners(props, ply)
|
||||
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
|
||||
@ -116,16 +117,14 @@ end
|
||||
|
||||
function NADMOD.PPInitPlayer(ply)
|
||||
local steamid = ply:SteamID()
|
||||
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
|
||||
NADMOD.SendPropOwners(tbl, ply)
|
||||
NADMOD.SendPropOwners(NADMOD.Props, ply)
|
||||
end
|
||||
hook.Add("PlayerInitialSpawn", "NADMOD.PPInitPlayer", NADMOD.PPInitPlayer)
|
||||
|
||||
@ -279,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
|
||||
@ -314,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
|
||||
@ -329,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
|
||||
@ -363,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