Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel
- Fixed classic armour protecting against crowbar damage (by @wgetJane)
- Fixed C4/Radio sounds not playing outside of PAS (Facepunch/garrysmod/pull/2203, by @figardo)
- Fixed players sometimes being revealed as dead when they chat/voicechat right as they die (Facepunch/garrysmod/pull/2229, by @wgetJane)
- Fixed various bugs related to using doors and buttons, to match base TTT behavior (by @wgetJane)
- 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
- 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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ local pmnc_tbl = {
}

local function OpenableEnt(ent)
return pmnc_tbl[ent:GetClass()] or OPEN_NO
return ent:GetName() ~= "" and pmnc_tbl[ent:GetClass()] or OPEN_NO
end

local function CrowbarCanUnlock(t)
Expand All @@ -108,7 +108,7 @@ function SWEP:OpenEnt(hitEnt)
hitEnt:Fire("Unlock", nil, 0)
end

if unlock or hitEnt:HasSpawnFlags(SF_NPC_LONG_RANGE) then -- Long Visibility/Shoot
if unlock or hitEnt:HasSpawnFlags(256) then
if openable == OPEN_ROT then
hitEnt:Fire("OpenAwayFrom", self:GetOwner(), 0)
end
Expand Down
17 changes: 10 additions & 7 deletions gamemodes/terrortown/gamemode/client/cl_keys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function GM:PlayerBindPress(ply, bindName, pressed)
return TBHUD:UseFocused()
end

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

-- If returned true by ClientUse or RemoteUse, then dont call Use and UseOverride or RemoteUse serverside
if isClientOnly then
return
return true
end

net.Start("TTT2PlayerUseEntity")
net.WriteBool(useEnt ~= nil)
net.WriteEntity(useEnt)
net.WriteBool(isRemote)
net.SendToServer()
if IsValid(useEnt) and useEnt:IsSpecialUsableEntity() then
net.Start("TTT2PlayerUseEntity")
net.WriteEntity(useEnt)
net.WriteBool(isRemote)
net.SendToServer()

return true
end
elseif string.sub(bindName, 1, 4) == "slot" and pressed then
local idx = tonumber(string.sub(bindName, 5, -1)) or 1

Expand Down
2 changes: 1 addition & 1 deletion gamemodes/terrortown/gamemode/server/sv_entity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function entmeta:IsUsableEntity(requiredCaps)

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

Expand Down
7 changes: 7 additions & 0 deletions gamemodes/terrortown/gamemode/server/sv_main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1007,3 +1007,10 @@ function GM:TTT2PreEndRound(result, duration)
-- send the clients the round log, players will be shown the report
events.StreamToClients()
end

---
-- Called right after all doors are initialized on the map.
-- @param table doorsTable A table with the newly registered door entities
-- @hook
-- @realm server
function GM:TTT2PostDoorSetup(doorsTable) end
58 changes: 32 additions & 26 deletions gamemodes/terrortown/gamemode/server/sv_player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -343,18 +343,30 @@ end
-- Triggered when the @{Player} presses use on an object.
-- Continuously runs until USE is released but will not activate other Entities
-- until the USE key is released; dependent on activation type of the @{Entity}.
-- @note TTT2 blocks all gmod internal use and only checks this for addons
-- @param Player ply The @{Player} pressing the "use" key.
-- @param Entity ent The entity which the @{Player} is looking at / activating USE on.
-- @param bool overrideDoPlayerUse This is used to override the default outcome of the check
-- @return boolean Return false if the @{Player} is not allowed to USE the entity.
-- Do not return true if using a hook, otherwise other mods may not get a chance to block a @{Player}'s use.
-- @hook
-- @realm server
-- @ref https://wiki.facepunch.com/gmod/GM:PlayerUse
-- @local
function GM:PlayerUse(ply, ent, overrideDoPlayerUse)
return overrideDoPlayerUse or false
function GM:PlayerUse(ply, ent)
if not ply:IsTerror() then
return false
end

if
ent:IsButton()
---
-- @realm server
and hook.Run("TTT2OnButtonUse", ply, ent, ent:GetInternalVariable("m_toggle_state"))
== false
then
return false
end

return true
end

---
Expand Down Expand Up @@ -514,11 +526,8 @@ end

local function EntityContinuousUse(ent, ply)
---
-- Enable addons to allow handling PlayerUse
-- Otherwise default to old IsTerror Check
-- @realm server
-- stylua: ignore
if hook.Run("PlayerUse", ply, ent, ply:IsTerror()) then
if hook.Run("PlayerUse", ply, ent) then
ent:Use(ply, ply)
end

Expand Down Expand Up @@ -568,7 +577,7 @@ local function EntityContinuousUse(ent, ply)
end

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

if distance > 100 + ent:BoundingRadius() then
return
Expand All @@ -586,15 +595,10 @@ end
-- @realm server
-- @internal
net.Receive("TTT2PlayerUseEntity", function(len, ply)
local hasEnt = net.ReadBool()
local ent = net.ReadEntity()
local isRemote = net.ReadBool()

if not hasEnt or not ent:IsUsableEntity() then
ent = ply:GetUseEntity()
end

if not IsValid(ent) then
if not (IsValid(ent) and ent:IsSpecialUsableEntity()) then
return
end

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

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

if
ent:IsButton()
---
-- @realm server
and hook.Run("TTT2OnButtonUse", ply, ent, ent:GetInternalVariable("m_toggle_state"))
== false
then
return
end

EntityContinuousUse(ent, ply)
end)

Expand Down Expand Up @@ -1324,6 +1318,18 @@ function GM:EntityTakeDamage(ent, dmginfo)
end
end

---
-- Called after an entity receives a damage event, after passing damage filters, etc.
-- @param Entity ent The @{Entity} taking damage
-- @param CTakeDamageInfo dmginfo Damage info
-- @param boolean wasDamageTaken Whether the entity actually took the damage
-- @hook
-- @realm server
-- @ref https://wiki.facepunch.com/gmod/GM:PostEntityTakeDamage
function GM:PostEntityTakeDamage(ent, dmginfo, wasDamageTaken)
door.PostHandleDamage(ent, dmginfo, wasDamageTaken)
end

---
-- Called by @{GM:EntityTakeDamage}
-- @param Entity ent The @{Entity} taking damage
Expand Down
37 changes: 23 additions & 14 deletions gamemodes/terrortown/gamemode/shared/sh_door.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function entmeta:IsDoorLocked()
return
end

return self:GetNWBool("ttt2_door_locked", false)
return self:GetNW2Bool("ttt2_door_locked", false)
end

---
Expand All @@ -57,7 +57,7 @@ function entmeta:IsDoorForceclosed()
return
end

return self:GetNWBool("ttt2_door_forceclosed", false)
return self:GetNW2Bool("ttt2_door_forceclosed", false)
end

---
Expand All @@ -70,7 +70,7 @@ function entmeta:UseOpensDoor()
return
end

return self:GetNWBool("ttt2_door_player_use", false)
return self:GetNW2Bool("ttt2_door_player_use", false)
end

---
Expand All @@ -82,7 +82,7 @@ function entmeta:TouchOpensDoor()
return
end

return self:GetNWBool("ttt2_door_player_touch", false)
return self:GetNW2Bool("ttt2_door_player_touch", false)
end

---
Expand All @@ -106,19 +106,28 @@ function entmeta:DoorAutoCloses()
return
end

return self:GetNWBool("ttt2_door_auto_close", false)
return self:GetNW2Bool("ttt2_door_auto_close", false)
end

---
-- Retuens if a door is destructible.
-- Returns if a door is destructible.
-- @return boolean If a door is destructible
-- @realm shared
function entmeta:DoorIsDestructible()
if not self:IsDoor() then
return
end

return self:GetNWBool("ttt2_door_is_destructable", false)
-- might be a little hacky
if
self:Health() > 0
and self:GetMaxHealth() > 0
and (self:GetInternalVariable("m_takedamage") or 2) > 1
then
return true
end

return self:GetNW2Bool("ttt2_door_is_destructable", false)
end

---
Expand All @@ -130,15 +139,15 @@ function entmeta:IsDoorOpen()
return
end

return self:GetNWBool("ttt2_door_open", false)
return self:GetNW2Bool("ttt2_door_open", false)
end

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

if SERVER then
Expand Down Expand Up @@ -259,7 +268,7 @@ if SERVER then
function entmeta:SetDoorCanTouchOpen(state, surpressPair)
door.SetPlayerCanTouch(self, state)

self:SetNWBool("ttt2_door_player_touch", door.PlayerCanTouch(self))
self:SetNW2Bool("ttt2_door_player_touch", door.PlayerCanTouch(self))

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

self:SetNWBool("ttt2_door_player_use", door.PlayerCanUse(self))
self:SetNW2Bool("ttt2_door_player_use", door.PlayerCanUse(self))

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

self:SetNWBool("ttt2_door_auto_close", door.AutoCloses(self))
self:SetNW2Bool("ttt2_door_auto_close", door.AutoCloses(self))

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

self:SetNWBool("ttt2_door_is_destructable", state)
self:SetNW2Bool("ttt2_door_is_destructable", state)

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

self:SetNWInt("fast_sync_health", self:Health())
self:SetNW2Int("fast_sync_health", self:Health())
end

-- if the door is grouped as a pair, call the other one as well
Expand Down
12 changes: 12 additions & 0 deletions gamemodes/terrortown/gamemode/shared/sh_entity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,15 @@ end
function entmeta:IsButton()
return self:IsDefaultButton() or self:IsRotatingButton()
end

---
-- @return boolean
-- @realm server
function entmeta:IsSpecialUsableEntity()
return self:IsWeapon()
or self.player_ragdoll
or self:IsPlayerRagdoll()
or self.CanUseKey
or self.ClientUse
or self.RemoteUse
end
7 changes: 0 additions & 7 deletions gamemodes/terrortown/gamemode/shared/sh_main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -548,13 +548,6 @@ function GM:InitFallbackShops() end
-- @realm shared
function GM:LoadedFallbackShops() end

---
-- Called right after all doors are initialized on the map.
-- @param table doorsTable A table with the newly registered door entities
-- @hook
-- @realm shared
function GM:TTT2PostDoorSetup(doorsTable) end

-- Called after all roles were loaded, @{ROLE:Preinitialize} and @{ROLE:Initialize} were called
-- and their convars were set up.
-- @hook
Expand Down
7 changes: 2 additions & 5 deletions lua/ttt2/libraries/buttons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ if SERVER then
for j = 1, #buttonsTable do
local foundButton = buttonsTable[j]

foundButton:SetNotSolid(false)
foundButton:SetSolid(SOLID_BSP)

foundButton:SetNWInt("button_class", i)
foundButton:SetNW2Int("button_class", i)
end
end

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

if not classID or classID > #validButtons then
return
Expand Down
Loading