Skip to content

Commit 4729f81

Browse files
authored
Fix up issues related to +use, doors, buttons, and such (#1792)
fixes #1775 fixes #1691 fixes #1633 fixes #1626 fixes #1627 Fixed various bugs related to using doors and buttons, to match base TTT behavior - Fixed brush doors on certain maps not being usable - Fixed certain doors on certain maps being forcibly usable when they shouldn't be - Fixed func_rotating being forcibly usable - Fixed vehicles not being usable - Removed forced button solidity - Improved targetID trace detection for doors and buttons - Allow brush doors to be detected as destructible for targetID - Use NW2Vars instead of NWVars for door variables for more efficient networking - Fixed clientside door.GetAll() to return a more updated list of doors - Removed clientside TTT2PostDoorSetup hook - Changed crowbar unlocking behavior to match base TTT
1 parent b00d445 commit 4729f81

File tree

12 files changed

+265
-140
lines changed

12 files changed

+265
-140
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel
2525
- Fixed classic armour protecting against crowbar damage (by @wgetJane)
2626
- Fixed C4/Radio sounds not playing outside of PAS (Facepunch/garrysmod/pull/2203, by @figardo)
2727
- Fixed players sometimes being revealed as dead when they chat/voicechat right as they die (Facepunch/garrysmod/pull/2229, by @wgetJane)
28+
- Fixed various bugs related to using doors and buttons, to match base TTT behavior (by @wgetJane)
29+
- Fixed brush doors on certain maps not being usable
30+
- Fixed certain doors on certain maps being forcibly usable when they shouldn't be
31+
- Fixed func_rotating being forcibly usable
32+
- Fixed vehicles not being usable
33+
- Removed forced button solidity
34+
- Improved targetID trace detection for doors and buttons
35+
- Allow brush doors to be detected as destructible for targetID
36+
- Use NW2Vars instead of NWVars for door variables for more efficient networking
37+
- Fixed clientside door.GetAll() to return a more updated list of doors
38+
- Removed clientside TTT2PostDoorSetup hook
39+
- Changed crowbar unlocking behavior to match base TTT
2840

2941
## [v0.14.2b](https://github.com/TTT-2/TTT2/tree/v0.14.2b) (2025-02-02)
3042

gamemodes/terrortown/entities/weapons/weapon_zm_improvised.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ local pmnc_tbl = {
8585
}
8686

8787
local function OpenableEnt(ent)
88-
return pmnc_tbl[ent:GetClass()] or OPEN_NO
88+
return ent:GetName() ~= "" and pmnc_tbl[ent:GetClass()] or OPEN_NO
8989
end
9090

9191
local function CrowbarCanUnlock(t)
@@ -108,7 +108,7 @@ function SWEP:OpenEnt(hitEnt)
108108
hitEnt:Fire("Unlock", nil, 0)
109109
end
110110

111-
if unlock or hitEnt:HasSpawnFlags(SF_NPC_LONG_RANGE) then -- Long Visibility/Shoot
111+
if unlock or hitEnt:HasSpawnFlags(256) then -- SF_DOOR_PUSE
112112
if openable == OPEN_ROT then
113113
hitEnt:Fire("OpenAwayFrom", self:GetOwner(), 0)
114114
end

gamemodes/terrortown/gamemode/client/cl_keys.lua

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function GM:PlayerBindPress(ply, bindName, pressed)
7575
return TBHUD:UseFocused()
7676
end
7777

78-
-- Find out if a marker is focussed otherwise check normal use
78+
-- Find out if a marker is focused otherwise check normal use
7979
local isClientOnly = false
8080
local useEnt = markerVision.GetFocusedEntity()
8181
local isRemote = IsValid(useEnt)
@@ -104,14 +104,17 @@ function GM:PlayerBindPress(ply, bindName, pressed)
104104

105105
-- If returned true by ClientUse or RemoteUse, then dont call Use and UseOverride or RemoteUse serverside
106106
if isClientOnly then
107-
return
107+
return true
108108
end
109109

110-
net.Start("TTT2PlayerUseEntity")
111-
net.WriteBool(useEnt ~= nil)
112-
net.WriteEntity(useEnt)
113-
net.WriteBool(isRemote)
114-
net.SendToServer()
110+
if IsValid(useEnt) and useEnt:IsSpecialUsableEntity() then
111+
net.Start("TTT2PlayerUseEntity")
112+
net.WriteEntity(useEnt)
113+
net.WriteBool(isRemote)
114+
net.SendToServer()
115+
116+
return true
117+
end
115118
elseif string.sub(bindName, 1, 4) == "slot" and pressed then
116119
local idx = tonumber(string.sub(bindName, 5, -1)) or 1
117120

gamemodes/terrortown/gamemode/server/sv_entity.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function entmeta:IsUsableEntity(requiredCaps)
9090

9191
-- special case: TTT specific lua based use interactions
9292
-- when we're looking for specifically the lua use
93-
if self:IsWeapon() or self.player_ragdoll or (self:IsScripted() and self.CanUseKey) then
93+
if self:IsSpecialUsableEntity() then
9494
return true
9595
end
9696

gamemodes/terrortown/gamemode/server/sv_main.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,3 +1007,10 @@ function GM:TTT2PreEndRound(result, duration)
10071007
-- send the clients the round log, players will be shown the report
10081008
events.StreamToClients()
10091009
end
1010+
1011+
---
1012+
-- Called right after all doors are initialized on the map.
1013+
-- @param table doorsTable A table with the newly registered door entities
1014+
-- @hook
1015+
-- @realm server
1016+
function GM:TTT2PostDoorSetup(doorsTable) end

gamemodes/terrortown/gamemode/server/sv_player.lua

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -343,18 +343,30 @@ end
343343
-- Triggered when the @{Player} presses use on an object.
344344
-- Continuously runs until USE is released but will not activate other Entities
345345
-- until the USE key is released; dependent on activation type of the @{Entity}.
346-
-- @note TTT2 blocks all gmod internal use and only checks this for addons
347346
-- @param Player ply The @{Player} pressing the "use" key.
348347
-- @param Entity ent The entity which the @{Player} is looking at / activating USE on.
349-
-- @param bool overrideDoPlayerUse This is used to override the default outcome of the check
350348
-- @return boolean Return false if the @{Player} is not allowed to USE the entity.
351349
-- Do not return true if using a hook, otherwise other mods may not get a chance to block a @{Player}'s use.
352350
-- @hook
353351
-- @realm server
354352
-- @ref https://wiki.facepunch.com/gmod/GM:PlayerUse
355353
-- @local
356-
function GM:PlayerUse(ply, ent, overrideDoPlayerUse)
357-
return overrideDoPlayerUse or false
354+
function GM:PlayerUse(ply, ent)
355+
if not ply:IsTerror() then
356+
return false
357+
end
358+
359+
if
360+
ent:IsButton()
361+
---
362+
-- @realm server
363+
and hook.Run("TTT2OnButtonUse", ply, ent, ent:GetInternalVariable("m_toggle_state"))
364+
== false
365+
then
366+
return false
367+
end
368+
369+
return true
358370
end
359371

360372
---
@@ -514,11 +526,8 @@ end
514526

515527
local function EntityContinuousUse(ent, ply)
516528
---
517-
-- Enable addons to allow handling PlayerUse
518-
-- Otherwise default to old IsTerror Check
519529
-- @realm server
520-
-- stylua: ignore
521-
if hook.Run("PlayerUse", ply, ent, ply:IsTerror()) then
530+
if hook.Run("PlayerUse", ply, ent) then
522531
ent:Use(ply, ply)
523532
end
524533

@@ -568,7 +577,7 @@ local function EntityContinuousUse(ent, ply)
568577
end
569578

570579
-- make sure the entity is still in a good position
571-
local distance = ply:GetShootPos():Distance(ent:GetPos())
580+
local distance = ply:GetShootPos():Distance(ent:WorldSpaceCenter())
572581

573582
if distance > 100 + ent:BoundingRadius() then
574583
return
@@ -586,15 +595,10 @@ end
586595
-- @realm server
587596
-- @internal
588597
net.Receive("TTT2PlayerUseEntity", function(len, ply)
589-
local hasEnt = net.ReadBool()
590598
local ent = net.ReadEntity()
591599
local isRemote = net.ReadBool()
592600

593-
if not hasEnt or not ent:IsUsableEntity() then
594-
ent = ply:GetUseEntity()
595-
end
596-
597-
if not IsValid(ent) then
601+
if not (IsValid(ent) and ent:IsSpecialUsableEntity()) then
598602
return
599603
end
600604

@@ -608,21 +612,11 @@ net.Receive("TTT2PlayerUseEntity", function(len, ply)
608612

609613
-- Check if the use interaction is possible
610614
-- Add the bounding radius to compensate for center position
611-
local distance = ply:GetShootPos():Distance(ent:GetPos())
615+
local distance = ply:GetShootPos():Distance(ent:WorldSpaceCenter())
612616
if distance > 100 + ent:BoundingRadius() then
613617
return
614618
end
615619

616-
if
617-
ent:IsButton()
618-
---
619-
-- @realm server
620-
and hook.Run("TTT2OnButtonUse", ply, ent, ent:GetInternalVariable("m_toggle_state"))
621-
== false
622-
then
623-
return
624-
end
625-
626620
EntityContinuousUse(ent, ply)
627621
end)
628622

@@ -1324,6 +1318,18 @@ function GM:EntityTakeDamage(ent, dmginfo)
13241318
end
13251319
end
13261320

1321+
---
1322+
-- Called after an entity receives a damage event, after passing damage filters, etc.
1323+
-- @param Entity ent The @{Entity} taking damage
1324+
-- @param CTakeDamageInfo dmginfo Damage info
1325+
-- @param boolean wasDamageTaken Whether the entity actually took the damage
1326+
-- @hook
1327+
-- @realm server
1328+
-- @ref https://wiki.facepunch.com/gmod/GM:PostEntityTakeDamage
1329+
function GM:PostEntityTakeDamage(ent, dmginfo, wasDamageTaken)
1330+
door.PostHandleDamage(ent, dmginfo, wasDamageTaken)
1331+
end
1332+
13271333
---
13281334
-- Called by @{GM:EntityTakeDamage}
13291335
-- @param Entity ent The @{Entity} taking damage

gamemodes/terrortown/gamemode/shared/sh_door.lua

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function entmeta:IsDoorLocked()
4545
return
4646
end
4747

48-
return self:GetNWBool("ttt2_door_locked", false)
48+
return self:GetNW2Bool("ttt2_door_locked", false)
4949
end
5050

5151
---
@@ -57,7 +57,7 @@ function entmeta:IsDoorForceclosed()
5757
return
5858
end
5959

60-
return self:GetNWBool("ttt2_door_forceclosed", false)
60+
return self:GetNW2Bool("ttt2_door_forceclosed", false)
6161
end
6262

6363
---
@@ -70,7 +70,7 @@ function entmeta:UseOpensDoor()
7070
return
7171
end
7272

73-
return self:GetNWBool("ttt2_door_player_use", false)
73+
return self:GetNW2Bool("ttt2_door_player_use", false)
7474
end
7575

7676
---
@@ -82,7 +82,7 @@ function entmeta:TouchOpensDoor()
8282
return
8383
end
8484

85-
return self:GetNWBool("ttt2_door_player_touch", false)
85+
return self:GetNW2Bool("ttt2_door_player_touch", false)
8686
end
8787

8888
---
@@ -106,19 +106,28 @@ function entmeta:DoorAutoCloses()
106106
return
107107
end
108108

109-
return self:GetNWBool("ttt2_door_auto_close", false)
109+
return self:GetNW2Bool("ttt2_door_auto_close", false)
110110
end
111111

112112
---
113-
-- Retuens if a door is destructible.
113+
-- Returns if a door is destructible.
114114
-- @return boolean If a door is destructible
115115
-- @realm shared
116116
function entmeta:DoorIsDestructible()
117117
if not self:IsDoor() then
118118
return
119119
end
120120

121-
return self:GetNWBool("ttt2_door_is_destructable", false)
121+
-- might be a little hacky
122+
if
123+
self:Health() > 0
124+
and self:GetMaxHealth() > 0
125+
and (self:GetInternalVariable("m_takedamage") or 2) > 1
126+
then
127+
return true
128+
end
129+
130+
return self:GetNW2Bool("ttt2_door_is_destructable", false)
122131
end
123132

124133
---
@@ -130,15 +139,15 @@ function entmeta:IsDoorOpen()
130139
return
131140
end
132141

133-
return self:GetNWBool("ttt2_door_open", false)
142+
return self:GetNW2Bool("ttt2_door_open", false)
134143
end
135144

136145
---
137146
-- Returns the fast synced health of the door entity. This is useful for UI applications.
138147
-- @return number The synced health
139148
-- @realm shared
140149
function entmeta:GetFastSyncedHealth()
141-
return math.max(0, self:GetNWInt("fast_sync_health", 100))
150+
return math.max(0, self:GetNW2Int("fast_sync_health", self:Health()))
142151
end
143152

144153
if SERVER then
@@ -259,7 +268,7 @@ if SERVER then
259268
function entmeta:SetDoorCanTouchOpen(state, surpressPair)
260269
door.SetPlayerCanTouch(self, state)
261270

262-
self:SetNWBool("ttt2_door_player_touch", door.PlayerCanTouch(self))
271+
self:SetNW2Bool("ttt2_door_player_touch", door.PlayerCanTouch(self))
263272

264273
-- if the door is grouped as a pair, call the other one as well
265274
if not surpressPair and IsValid(self.otherPairDoor) then
@@ -275,7 +284,7 @@ if SERVER then
275284
function entmeta:SetDoorCanUseOpen(state, surpressPair)
276285
door.SetPlayerCanUse(self, state)
277286

278-
self:SetNWBool("ttt2_door_player_use", door.PlayerCanUse(self))
287+
self:SetNW2Bool("ttt2_door_player_use", door.PlayerCanUse(self))
279288

280289
-- if the door is grouped as a pair, call the other one as well
281290
if not surpressPair and IsValid(self.otherPairDoor) then
@@ -291,7 +300,7 @@ if SERVER then
291300
function entmeta:SetDoorAutoCloses(state, surpressPair)
292301
door.SetAutoClose(self, state)
293302

294-
self:SetNWBool("ttt2_door_auto_close", door.AutoCloses(self))
303+
self:SetNW2Bool("ttt2_door_auto_close", door.AutoCloses(self))
295304

296305
-- if the door is grouped as a pair, call the other one as well
297306
if not surpressPair and IsValid(self.otherPairDoor) then
@@ -309,12 +318,12 @@ if SERVER then
309318
return
310319
end
311320

312-
self:SetNWBool("ttt2_door_is_destructable", state)
321+
self:SetNW2Bool("ttt2_door_is_destructable", state)
313322

314323
if self:Health() == 0 then
315324
self:SetHealth(cvDoorHealth:GetInt())
316325

317-
self:SetNWInt("fast_sync_health", self:Health())
326+
self:SetNW2Int("fast_sync_health", self:Health())
318327
end
319328

320329
-- if the door is grouped as a pair, call the other one as well

gamemodes/terrortown/gamemode/shared/sh_entity.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,15 @@ end
4040
function entmeta:IsButton()
4141
return self:IsDefaultButton() or self:IsRotatingButton()
4242
end
43+
44+
---
45+
-- @return boolean
46+
-- @realm server
47+
function entmeta:IsSpecialUsableEntity()
48+
return self:IsWeapon()
49+
or self.player_ragdoll
50+
or self:IsPlayerRagdoll()
51+
or self.CanUseKey
52+
or self.ClientUse
53+
or self.RemoteUse
54+
end

gamemodes/terrortown/gamemode/shared/sh_main.lua

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -548,13 +548,6 @@ function GM:InitFallbackShops() end
548548
-- @realm shared
549549
function GM:LoadedFallbackShops() end
550550

551-
---
552-
-- Called right after all doors are initialized on the map.
553-
-- @param table doorsTable A table with the newly registered door entities
554-
-- @hook
555-
-- @realm shared
556-
function GM:TTT2PostDoorSetup(doorsTable) end
557-
558551
-- Called after all roles were loaded, @{ROLE:Preinitialize} and @{ROLE:Initialize} were called
559552
-- and their convars were set up.
560553
-- @hook

lua/ttt2/libraries/buttons.lua

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ if SERVER then
3131
for j = 1, #buttonsTable do
3232
local foundButton = buttonsTable[j]
3333

34-
foundButton:SetNotSolid(false)
35-
foundButton:SetSolid(SOLID_BSP)
36-
37-
foundButton:SetNWInt("button_class", i)
34+
foundButton:SetNW2Int("button_class", i)
3835
end
3936
end
4037

@@ -62,7 +59,7 @@ end
6259
-- @return boolean Returns true if the entity matches the provided class name
6360
-- @realm shared
6461
function button.IsClass(ent, class)
65-
local classID = ent:GetNWInt("button_class")
62+
local classID = ent:GetNW2Int("button_class")
6663

6764
if not classID or classID > #validButtons then
6865
return

0 commit comments

Comments
 (0)