diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fb4d2aa7..804d6885a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,8 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel - Fixed detective search being overwritten by player search results - Fixed `DynamicCamera` error when a weapon's `CalcView` doesn't return complete values (by @TW1STaL1CKY) - Fixed Roundendscreen showing karma changes even if karma is disabled +- Fixed the player's FOV staying zoomed in if their weapon is removed while scoped in (by @TW1STaL1CKY) +- Fixed weapon unscoping (or generally any time FOV is set back to default) being delayed due to the player's lag (by @TW1STaL1CKY) ### Removed diff --git a/gamemodes/terrortown/entities/weapons/weapon_tttbase.lua b/gamemodes/terrortown/entities/weapons/weapon_tttbase.lua index 74cbf7eb3..19ee192fd 100644 --- a/gamemodes/terrortown/entities/weapons/weapon_tttbase.lua +++ b/gamemodes/terrortown/entities/weapons/weapon_tttbase.lua @@ -769,16 +769,6 @@ if CLIENT then -- @realm client function SWEP:DrawWeaponSelection() end - --- - -- @realm client - function SWEP:OnRemove() - local owner = self:GetOwner() - - if IsValid(owner) and owner == LocalPlayer() and owner:IsTerror() then - RunConsoleCommand("lastinv") - end - end - --- -- @realm client function SWEP:CalcViewModel() @@ -1223,6 +1213,22 @@ function SWEP:Reload() self:SetZoom(false) end +--- +-- Called when the weapon entity is about to be removed +-- @see https://wiki.facepunch.com/gmod/WEAPON:OnRemove +-- @realm shared +function SWEP:OnRemove() + if CLIENT then + local owner = self:GetOwner() + + if IsValid(owner) and owner == LocalPlayer() and owner:IsTerror() then + RunConsoleCommand("lastinv") + end + end + + self:SetZoom(false) +end + --- -- Called when the weapon entity is reloaded on a changelevel event -- @see https://wiki.facepunch.com/gmod/WEAPON:OnRestore diff --git a/gamemodes/terrortown/gamemode/client/cl_main.lua b/gamemodes/terrortown/gamemode/client/cl_main.lua index 6528d1d13..13dbe47c9 100644 --- a/gamemodes/terrortown/gamemode/client/cl_main.lua +++ b/gamemodes/terrortown/gamemode/client/cl_main.lua @@ -817,6 +817,8 @@ local position = 0 local frameCount = 10 local lastStrafeValue = 0 +local lastFovTimeValue = 0 +local curTimeShift = 0 local cvHostTimescale = GetConVar("host_timescale") @@ -867,10 +869,24 @@ function GM:DynamicCamera(viewTable, ply) -- dynamic mode: transition between different FOV values else - local time = math.max( - 0, - (CurTime() - ply:GetFOVTime()) * game.GetTimeScale() * cvHostTimescale:GetFloat() - ) + local fovTime = ply:GetFOVTime() + + if lastFovTimeValue ~= fovTime then + lastFovTimeValue = fovTime + curTimeShift = 0 + end + + local curTime = CurTime() + curTimeShift + + -- GetFOVTime ends up in the future with lag, causing a delay in the transition (the bigger your lag, the longer the delay) + -- shift curTime by the difference to correct it + if curTime < fovTime then + curTimeShift = fovTime - curTime + curTime = curTime + curTimeShift + end + + local time = + math.max(0, (curTime - fovTime) * game.GetTimeScale() * cvHostTimescale:GetFloat()) local progressTransition = math.min(1.0, time / ply:GetFOVTransitionTime())