diff --git a/gamemodes/terrortown/entities/weapons/weapon_tttbase.lua b/gamemodes/terrortown/entities/weapons/weapon_tttbase.lua index 90501a1dad..51f2e32b29 100644 --- a/gamemodes/terrortown/entities/weapons/weapon_tttbase.lua +++ b/gamemodes/terrortown/entities/weapons/weapon_tttbase.lua @@ -283,7 +283,7 @@ if CLIENT then local client = LocalPlayer() - if not enable_crosshair:GetBool() or not IsValid(client) or client.isSprinting and not GetGlobalBool("ttt2_sprint_crosshair", false) then return end + if not enable_crosshair:GetBool() or not IsValid(client) or client:GetSprintingPredicted() and not GetGlobalBool("ttt2_sprint_crosshair", false) then return end local sights = not self.NoSights and self:GetIronsights() local x = math.floor(ScrW() * 0.5) diff --git a/gamemodes/terrortown/gamemode/shared/sh_main.lua b/gamemodes/terrortown/gamemode/shared/sh_main.lua index 1dc291da6a..c95abcdfb0 100644 --- a/gamemodes/terrortown/gamemode/shared/sh_main.lua +++ b/gamemodes/terrortown/gamemode/shared/sh_main.lua @@ -239,15 +239,6 @@ end -- @realm shared -- @ref https://wiki.facepunch.com/gmod/GM:Move function GM:Move(ply, moveData) - if client and client.isSprinting then - -- We abuse IN_BULLRUSH here to still be able to use our own binding system - moveData:AddKeys(IN_BULLRUSH) - end - - if server and moveData:KeyDown(IN_BULLRUSH) then - ply.isSprinting = true - end - SPEED:HandleSpeedCalculation(ply, moveData) local mul = ply:GetSpeedMultiplier() diff --git a/gamemodes/terrortown/gamemode/shared/sh_player_ext.lua b/gamemodes/terrortown/gamemode/shared/sh_player_ext.lua index 1cb8f1ac96..cb4c15e26a 100644 --- a/gamemodes/terrortown/gamemode/shared/sh_player_ext.lua +++ b/gamemodes/terrortown/gamemode/shared/sh_player_ext.lua @@ -16,6 +16,29 @@ if not plymeta then return end +--- +-- Dummy functions that will be replaced when SetupDataTables runs. These are +-- here for when that does not happen (due to e.g. stacking base classes) +-- @return[default=false] boolean +-- @realm shared +function plymeta:GetSprintingPredicted() + return false +end + +--- +-- Dummy functions that will be replaced when SetupDataTables runs. These are +-- here for when that does not happen (due to e.g. stacking base classes) +-- @realm shared +function plymeta:SetSprintingPredicted() + +end + +function plymeta:SetupDataTables() + self:NetworkVar("Bool", 3, "SprintingPredicted") + + plymeta.SetupDataTables(self) +end + --- -- Checks whether a player is a available terrorist (not a spectator) -- @return boolean diff --git a/gamemodes/terrortown/gamemode/shared/sh_speed.lua b/gamemodes/terrortown/gamemode/shared/sh_speed.lua index 7f5bb07c9d..50f9aeee12 100644 --- a/gamemodes/terrortown/gamemode/shared/sh_speed.lua +++ b/gamemodes/terrortown/gamemode/shared/sh_speed.lua @@ -23,7 +23,7 @@ function SPEED:HandleSpeedCalculation(ply, moveData) if IsValid(wep) and wep.GetIronsights and wep:GetIronsights() then baseMultiplier = 120 / 220 isSlowed = true - elseif ply.isSprinting and (ply.sprintProgress or 0) > 0 then + elseif ply:GetSprintingPredicted() and (ply.sprintProgress or 0) > 0 then local sprintMultiplierModifier = {1} --- diff --git a/gamemodes/terrortown/gamemode/shared/sh_sprint.lua b/gamemodes/terrortown/gamemode/shared/sh_sprint.lua index 7932d8ddbb..45a6fcb412 100644 --- a/gamemodes/terrortown/gamemode/shared/sh_sprint.lua +++ b/gamemodes/terrortown/gamemode/shared/sh_sprint.lua @@ -2,12 +2,13 @@ local function PlayerSprint(trySprinting, moveKey) if SERVER then return end local client = LocalPlayer() + local isSprinting = client:GetSprintingPredicted() if not GetGlobalBool("ttt2_sprint_enabled", true) then return end - if not trySprinting and not client.isSprinting or trySprinting and client.isSprinting then return end - if client.isSprinting and (client.moveKey and not moveKey or not client.moveKey and moveKey) then return end + if not trySprinting and not isSprinting or trySprinting and isSprinting then return end + if isSprinting and (client.moveKey and not moveKey or not client.moveKey and moveKey) then return end - client.isSprinting = trySprinting + client:SetSprintingPredicted(trySprinting) client.moveKey = moveKey end @@ -80,7 +81,7 @@ else -- CLIENT -- @realm client function UpdateInputSprint(ply, key, pressed) if pressed then - if ply.isSprinting or not enable_doubletap_sprint:GetBool() or ply.preventSprint then return end + if ply:GetSprintingPredicted() or not enable_doubletap_sprint:GetBool() or ply.preventSprint then return end local time = CurTime() @@ -91,7 +92,7 @@ else -- CLIENT lastPressedMoveKey = key lastPress = time else - if not ply.isSprinting then return end + if not ply:GetSprintingPredicted() then return end local moveKey = ply.moveKey local wantsToMove = ply:KeyDown(IN_FORWARD) or ply:KeyDown(IN_BACK) or ply:KeyDown(IN_MOVERIGHT) or ply:KeyDown(IN_MOVELEFT) @@ -133,8 +134,8 @@ function UpdateSprint() local wantsToMove = ply:KeyDown(IN_FORWARD) or ply:KeyDown(IN_BACK) or ply:KeyDown(IN_MOVERIGHT) or ply:KeyDown(IN_MOVELEFT) - if ply.sprintProgress == 1 and (not ply.isSprinting or not wantsToMove) then continue end - if ply.sprintProgress == 0 and ply.isSprinting and wantsToMove then + if ply.sprintProgress == 1 and (not ply:GetSprintingPredicted() or not wantsToMove) then continue end + if ply.sprintProgress == 0 and ply:GetSprintingPredicted() and wantsToMove then ply.sprintResetDelayCounter = ply.sprintResetDelayCounter + FrameTime() -- If the player keeps sprinting even though they have no stamina, start refreshing stamina after 1.5 seconds automatically @@ -149,7 +150,7 @@ function UpdateSprint() local modifier = {1} -- Multiple hooking support - if not ply.isSprinting or not wantsToMove then + if not ply:GetSprintingPredicted() or not wantsToMove then --- -- @realm shared hook.Run("TTT2StaminaRegen", ply, modifier)