experimental networking changes DO NOT PUSH WS

This commit is contained in:
TheOnly8Z 2023-09-03 14:58:52 -07:00
parent 4592395b3b
commit 0d1b2fe317
5 changed files with 26 additions and 18 deletions

View File

@ -164,25 +164,28 @@ hook.Add( "OnEntityCreated", "ArcCW_NPCWeaponReplacement", function(ent)
end
end)
hook.Add("PlayerCanPickupWeapon", "ArcCW_PlayerCanPickupWeapon", function(ply, wep)
if !wep.ArcCW then return end
if !ply:HasWeapon(wep:GetClass()) then return end
-- This hook steals attachments from dropped weapons when a player walks over.
-- Disabled cause this is called CONSTANTLY when player is over a weapon, causing massive network lag.
-- Also it's just weird and hard to understand.
-- hook.Add("PlayerCanPickupWeapon", "ArcCW_PlayerCanPickupWeapon", function(ply, wep)
-- if !wep.ArcCW then return end
-- if !ply:HasWeapon(wep:GetClass()) then return end
if wep.Singleton then return false end
-- if wep.Singleton then return false end
if !ArcCW.EnableCustomization or ArcCW.ConVars["enable_customization"]:GetInt() < 0 or ArcCW.ConVars["attinv_free"]:GetBool() then return end
-- if !ArcCW.EnableCustomization or ArcCW.ConVars["enable_customization"]:GetInt() < 0 or ArcCW.ConVars["attinv_free"]:GetBool() then return end
for _, i in pairs(wep.Attachments) do
if i.Installed then
ArcCW:PlayerGiveAtt(ply, i.Installed)
end
-- for _, i in pairs(wep.Attachments) do
-- if i.Installed then
-- ArcCW:PlayerGiveAtt(ply, i.Installed)
-- end
i.Installed = nil
end
-- i.Installed = nil
-- end
ArcCW:PlayerSendAttInv(ply)
wep:NetworkWeapon()
end)
-- ArcCW:PlayerSendAttInv(ply)
-- wep:NetworkWeapon()
-- end)
hook.Add("onDarkRPWeaponDropped", "ArcCW_DarkRP", function(ply, spawned_weapon, wep)
if wep.ArcCW and wep.Attachments then

View File

@ -365,7 +365,7 @@ net.Receive("arccw_rqwpnnet", function(len, ply)
if !wpn.ArcCW then return end
wpn:RecalcAllBuffs()
wpn:NetworkWeapon()
wpn:NetworkWeapon(ply)
end)
net.Receive("arccw_slidepos", function(len, ply)

View File

@ -748,6 +748,7 @@ function SWEP:DrawWorldModel()
if !self.CertainAboutAtts and !self.AttReqSent and IsValid(self:GetOwner()) then
self.AttReqSent = true
print(self, "network weapon from cl_viewmodel")
net.Start("arccw_rqwpnnet")
net.WriteEntity(self)
net.SendToServer()

View File

@ -790,8 +790,8 @@ function SWEP:NetworkWeapon(sendto)
if sendto then
net.Send(sendto)
else
net.SendPVS(self:GetPos())
--net.Broadcast()
-- net.SendPVS(self:GetPos())
net.Broadcast()
end
end

View File

@ -93,9 +93,13 @@ function SWEP:Deploy()
if SERVER then
self:SetupShields()
-- Networking the weapon at this time is too early - entity is not yet valid on client
-- Also not a good idea because networking many weapons will cause mass lag (e.g. TTT round setup)
-- Instead, make client send a request when it is valid there
--self:NetworkWeapon()
elseif CLIENT and !self.CertainAboutAtts then
elseif CLIENT and !self.CertainAboutAtts and IsValid(self:GetOwner()) then
-- If client is aware of this weapon and it's not on the ground, ask for attachment info
-- If it is not on a player, delay networking until it is rendered (in cl_viewmodel)
print(self, "network weapon from sh_deploy")
net.Start("arccw_rqwpnnet")
net.WriteEntity(self)
net.SendToServer()