From 70518fee1513d252c4da86e0443c1a05b98a61b2 Mon Sep 17 00:00:00 2001 From: Tim Goll Date: Sat, 28 Sep 2024 23:15:49 +0200 Subject: [PATCH 1/3] readded continuous use --- .../terrortown/gamemode/server/sv_entity.lua | 18 ++-- .../terrortown/gamemode/server/sv_player.lua | 99 +++++++++++++------ 2 files changed, 73 insertions(+), 44 deletions(-) diff --git a/gamemodes/terrortown/gamemode/server/sv_entity.lua b/gamemodes/terrortown/gamemode/server/sv_entity.lua index 890fc2f96..e1a85676d 100644 --- a/gamemodes/terrortown/gamemode/server/sv_entity.lua +++ b/gamemodes/terrortown/gamemode/server/sv_entity.lua @@ -10,9 +10,6 @@ FCAP_DIRECTIONAL_USE = 128 FCAP_USE_ONGROUND = 256 FCAP_USE_IN_RADIUS = 512 --- custom FCAPS possible from 2048 to 268435456 -FCAP_USE_LUA = 2048 - local safeCollisionGroups = { [COLLISION_GROUP_WEAPON] = true, } @@ -91,19 +88,16 @@ end function entmeta:IsUsableEntity(requiredCaps) requiredCaps = requiredCaps or 0 - local caps = self:ObjectCaps() - -- special case: TTT specific lua based use interactions - -- when were looking for specifically the lua use, return false it not set - if - bit.band(FCAP_USE_LUA, requiredCaps) > 0 - and not (self.CanUseKey or self.player_ragdoll or self:IsWeapon()) - then - return false - elseif requiredCaps == 0 and (self.CanUseKey or self.player_ragdoll or self:IsWeapon()) then + -- when we're looking for specifically the lua use + if self:IsWeapon() or self.player_ragdoll then + return true + elseif self:IsScripted() and self.CanUseKey then return true end + local caps = self:ObjectCaps() + if bit.band( caps, diff --git a/gamemodes/terrortown/gamemode/server/sv_player.lua b/gamemodes/terrortown/gamemode/server/sv_player.lua index e5380e7c0..ecbc1e992 100644 --- a/gamemodes/terrortown/gamemode/server/sv_player.lua +++ b/gamemodes/terrortown/gamemode/server/sv_player.lua @@ -518,6 +518,72 @@ local function SpecUseKey(ply, ent) end 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 + ent:Use(ply, ply) + end + + if ply:IsSpec() then + SpecUseKey(ply, ent) + + return + end + + if not ply:IsTerror() then + return + end + + if ent.CanUseKey and ent.UseOverride then + local phys = ent:GetPhysicsObject() + + if not IsValid(phys) or phys:HasGameFlag(FVPHYSICS_PLAYER_HELD) then + return + end + + ent:UseOverride(ply) + elseif ent.player_ragdoll then + CORPSE.ShowSearch(ply, ent, ply:KeyDown(IN_WALK) or ply:KeyDownLast(IN_WALK)) + + return + elseif ent:IsWeapon() then + ply:SafePickupWeapon(ent, false, true, true, nil) + + return + end + + -- if it is a SENT, this will always return true + -- if it is a map entity, the flag will be checked + if not ent:IsUsableEntity(FCAP_CONTINUOUS_USE) then + return + end + + -- make sure it is called 10 times per second + timer.Simple(0.1, function() + if not IsValid(ent) or not IsValid(ply) then + return + end + + -- make sure the use key is still pressed + if not ply:KeyDown(IN_USE) then + return + end + + -- make sure the entity is still in a good position + local distance = ply:GetShootPos():Distance(ent:GetPos()) + + if distance > 100 + ent:BoundingRadius() then + return + end + + EntityContinuousUse(ent, ply) + end) +end + --- -- This is called by a client when using the "+use"-key -- and contains the entity which was detected @@ -564,38 +630,7 @@ net.Receive("TTT2PlayerUseEntity", function(len, ply) return end - --- - -- 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 - ent:Use(ply, ply) - end - - if ply:IsSpec() then - SpecUseKey(ply, ent) - - return - end - - if not ply:IsTerror() then - return - end - - if ent.CanUseKey and ent.UseOverride then - local phys = ent:GetPhysicsObject() - - if not IsValid(phys) or phys:HasGameFlag(FVPHYSICS_PLAYER_HELD) then - return - end - - ent:UseOverride(ply) - elseif ent.player_ragdoll then - CORPSE.ShowSearch(ply, ent, ply:KeyDown(IN_WALK) or ply:KeyDownLast(IN_WALK)) - elseif ent:IsWeapon() then - ply:SafePickupWeapon(ent, false, true, true, nil) - end + EntityContinuousUse(ent, ply) end) --- From 105bf0f2d8db9206405403c6a8d4ff023fb3a6f6 Mon Sep 17 00:00:00 2001 From: Tim Goll Date: Sat, 28 Sep 2024 23:17:10 +0200 Subject: [PATCH 2/3] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc47f52e7..aad407d47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,11 +9,13 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel - Fixed missing translation for None role error by removing it (by @mexikoedi) - Fixed sometimes entity use triggering the wrong or no entity (by @TimGoll) - Fixed translation of muting Terrorists and Spectators (by @mexikoedi) +- Fixed continuous use being broken, meaing that holding E on a health station did nothing (by @TimGoll) ### Changed - Updated French translation (by @MisterClems) - Updated Turkish localization (by @NovaDiablox) +- Changed it so that continous use doesn't require direct focus; healing at a health station also works when looking around as long as you stay close by (by @TimGoll) ## [v0.14.0b](https://github.com/TTT-2/TTT2/tree/v0.14.0b) (2024-09-20) From 5e5f1a605a3c039c0f0968662cfc4552d60e5e8d Mon Sep 17 00:00:00 2001 From: Tim Goll Date: Fri, 3 Jan 2025 14:52:11 +0100 Subject: [PATCH 3/3] Update gamemodes/terrortown/gamemode/server/sv_entity.lua Co-authored-by: ZenBre4ker <72046466+ZenBre4ker@users.noreply.github.com> --- gamemodes/terrortown/gamemode/server/sv_entity.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/gamemodes/terrortown/gamemode/server/sv_entity.lua b/gamemodes/terrortown/gamemode/server/sv_entity.lua index e1a85676d..7486bcdde 100644 --- a/gamemodes/terrortown/gamemode/server/sv_entity.lua +++ b/gamemodes/terrortown/gamemode/server/sv_entity.lua @@ -90,9 +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 then - return true - elseif self:IsScripted() and self.CanUseKey then + if self:IsWeapon() or self.player_ragdoll or (self:IsScripted() and self.CanUseKey) then return true end