Skip to content

Commit

Permalink
Only reset ViewEntity if modified (#1980)
Browse files Browse the repository at this point in the history
Remove prints
  • Loading branch information
adamnejm authored Jan 17, 2025
1 parent 5689608 commit 04cce8f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lua/entities/starfall_processor/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,10 @@ if SERVER then
local function disconnect(sync)
huds[ply] = nil
hook.Remove("EntityRemoved", n)
ply:SetViewEntity()
if chip.instance and chip.instance.data.viewEntityChanged then
chip.instance.data.viewEntityChanged = false
ply:SetViewEntity()
end
if IsValid(lockController) and IsValid(lockController.link) then
net.Start("starfall_lock_control")
net.WriteEntity(lockController.link)
Expand All @@ -261,7 +264,10 @@ if SERVER then
disconnect(false)
end
else
if not enabled then ply:SetViewEntity() end
if not enabled and chip.instance.data.viewEntityChanged then
chip.instance.data.viewEntityChanged = false
ply:SetViewEntity()
end
huds[ply] = enabled or nil
end
runHudHooks(ply, chip, activator, enabled)
Expand Down
3 changes: 2 additions & 1 deletion lua/starfall/libs_sh/players.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ end)
if SERVER then
instance:AddHook("deinitialize", function()
for k, ply in pairs(player.GetAll()) do
if SF.IsHUDActive(instance.entity, ply) then
if instance.data.viewEntityChanged then
Ply_SetViewEntity(ply)
end
end
Expand Down Expand Up @@ -547,6 +547,7 @@ if SERVER then
local ply = getply(self)
if ent~=nil then ent = getent(ent) end
if not SF.IsHUDActive(instance.entity, ply) then SF.Throw("Player isn't connected to HUD!", 2) end
instance.data.viewEntityChanged = ent ~= nil and ent ~= ply
Ply_SetViewEntity(ply, ent)
end

Expand Down

0 comments on commit 04cce8f

Please sign in to comment.