Skip to content

Commit d3ff971

Browse files
authored
Sprinting tweaks, 2 new sprint settings (#1794)
`ttt2_sprint_stamina_cooldown 0.8` : time in seconds before stamina begins regenerating after sprinting `ttt2_sprint_forwards_only 1` : require forward key to be held to be able to sprint, prevents sprinting backwards or side to side, still allows sprinting diagonally with W+A or W+D not sure if these should be enabled by default, but feels closer to how sprint/stamina in other games work
1 parent e71f0b3 commit d3ff971

File tree

5 files changed

+61
-12
lines changed

5 files changed

+61
-12
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel
1313
- Added server option for body armor to protect against crowbar damage (by @wgetJane)
1414
- Added `GM:TTTLastWordsMsg` hook from base TTT (Facepunch/garrysmod/pull/2227, by @wgetJane)
1515
- Port new TTT entity ttt_filter_role to TTT2 (Facepunch/garrysmod/pull/2225 by @figardo, ported by @wgetJane)
16+
- Added 2 new sprint settings (by @wgetJane)
17+
- Stamina cooldown time before stamina begins regenerating after sprinting, 0.8 seconds by default
18+
- Option to require forward key to be held to sprint, enabled by default
1619

1720
### Changed
1821

gamemodes/terrortown/gamemode/shared/sh_player_ext.lua

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,19 @@ end
2828
function plymeta:SetupDataTables()
2929
-- This has to be transferred, because we need the value when predicting the player movement
3030
-- It turned out that this is the only reliable way to fix all prediction errors.
31-
self:NetworkVar("Float", 0, "SprintStamina")
31+
self:NetworkVar("Float", "SprintStamina")
32+
self:NetworkVar("Float", "SprintCooldownTime")
3233

3334
if SERVER then
3435
self:SetSprintStamina(1)
3536
end
3637

3738
-- these are networked variables for the custom FOV handling
38-
self:NetworkVar("Float", 1, "FOVTime")
39-
self:NetworkVar("Float", 2, "FOVTransitionTime")
40-
self:NetworkVar("Float", 3, "FOVValue")
41-
self:NetworkVar("Float", 4, "FOVLastValue")
42-
self:NetworkVar("Bool", 0, "FOVIsFixed")
39+
self:NetworkVar("Float", "FOVTime")
40+
self:NetworkVar("Float", "FOVTransitionTime")
41+
self:NetworkVar("Float", "FOVValue")
42+
self:NetworkVar("Float", "FOVLastValue")
43+
self:NetworkVar("Bool", "FOVIsFixed")
4344
end
4445

4546
---

gamemodes/terrortown/gamemode/shared/sh_sprint.lua

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ SPRINT = {
3131
{ FCVAR_ARCHIVE, FCVAR_NOTIFY, FCVAR_REPLICATED },
3232
"The regeneration time of the stamina (per second; Def: 0.3)"
3333
),
34+
-- @realm shared
35+
cooldown = CreateConVar(
36+
"ttt2_sprint_stamina_cooldown",
37+
"0.8",
38+
{ FCVAR_ARCHIVE, FCVAR_NOTIFY, FCVAR_REPLICATED },
39+
"Time before stamina begins regenerating after sprinting (in seconds; Def: 0.8)"
40+
),
41+
-- @realm shared
42+
forwards_only = CreateConVar(
43+
"ttt2_sprint_forwards_only",
44+
"1",
45+
{ FCVAR_ARCHIVE, FCVAR_NOTIFY, FCVAR_REPLICATED },
46+
"Disallow sprinting backwards or laterally (Def: 1)"
47+
),
3448
},
3549
}
3650

@@ -41,10 +55,17 @@ SPRINT = {
4155
-- @realm shared
4256
function SPRINT:PlayerWantsToSprint(ply)
4357
local inSprint = ply:KeyDown(IN_SPEED)
44-
local inMovement = ply:KeyDown(IN_FORWARD)
45-
or ply:KeyDown(IN_BACK)
46-
or ply:KeyDown(IN_MOVERIGHT)
47-
or ply:KeyDown(IN_MOVELEFT)
58+
59+
local inMovement
60+
61+
if self.convars.forwards_only:GetBool() then
62+
inMovement = ply:KeyDown(IN_FORWARD) and not ply:KeyDown(IN_BACK)
63+
else
64+
inMovement = ply:KeyDown(IN_FORWARD)
65+
or ply:KeyDown(IN_BACK)
66+
or ply:KeyDown(IN_MOVERIGHT)
67+
or ply:KeyDown(IN_MOVELEFT)
68+
end
4869

4970
return inSprint and inMovement
5071
end
@@ -68,6 +89,7 @@ end
6889
function SPRINT:HandleStaminaCalculation(ply)
6990
local staminaRegeneratonRate = self.convars.regeneration:GetFloat()
7091
local staminaConsumptionRate = self.convars.consumption:GetFloat()
92+
local staminaCooldownTime = self.convars.cooldown:GetFloat()
7193

7294
local sprintStamina = ply:GetSprintStamina()
7395
local playerWantsToSprint = self:PlayerWantsToSprint(ply) and not ply:IsInIronsights()
@@ -81,7 +103,7 @@ function SPRINT:HandleStaminaCalculation(ply)
81103

82104
-- Note: This is a table, because it is passed by reference and multiple addons can adjust the value.
83105
local rateModifier = { 1 }
84-
local newStamina = 0
106+
local newStamina = sprintStamina
85107

86108
if playerWantsToSprint then
87109
---
@@ -90,7 +112,11 @@ function SPRINT:HandleStaminaCalculation(ply)
90112

91113
newStamina =
92114
math.max(sprintStamina - FrameTime() * rateModifier[1] * staminaConsumptionRate, 0)
93-
else
115+
116+
if staminaCooldownTime > 0 then
117+
ply:SetSprintCooldownTime(CurTime() + staminaCooldownTime)
118+
end
119+
elseif staminaCooldownTime <= 0 or CurTime() > ply:GetSprintCooldownTime() then
94120
---
95121
-- @realm shared
96122
hook.Run("TTT2StaminaRegen", ply, rateModifier)

lua/terrortown/lang/en.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2832,3 +2832,7 @@ L.choice_distance_unit_3 = "Feet"
28322832

28332833
-- 2025-03-06
28342834
L.label_armor_block_clubdmg = "Enable armor blocking crowbar damage"
2835+
2836+
-- 2025-03-10
2837+
L.label_sprint_stamina_cooldown = "Stamina cooldown time"
2838+
L.label_sprint_stamina_forwards_only = "Disallow sprinting backwards or laterally"

lua/terrortown/menus/gamemode/administration/sprint.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,19 @@ function CLGAMEMODESUBMENU:Populate(parent)
3939
decimal = 2,
4040
master = enbSprint,
4141
})
42+
43+
form:MakeSlider({
44+
serverConvar = "ttt2_sprint_stamina_cooldown",
45+
label = "label_sprint_stamina_cooldown",
46+
min = 0,
47+
max = 2,
48+
decimal = 2,
49+
master = enbSprint,
50+
})
51+
52+
form:MakeCheckBox({
53+
serverConvar = "ttt2_sprint_forwards_only",
54+
label = "label_sprint_stamina_forwards_only",
55+
master = enbSprint,
56+
})
4257
end

0 commit comments

Comments
 (0)