Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continous Use: Reimplemented #1645

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ 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)
- Fixed the loadingscreen disable causing an error (by @TimGoll)
- Fixed the rounds left always displaying one less than actually left (by @TimGoll)
- Fixed rendering glitches in the loading screen (by @TimGoll)
Expand All @@ -36,6 +37,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel

- 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)
- Updated Russian localization (by @Satton2)
- Updated targetID to use `Vehicle:GetDriver` instead of the `ttt_driver` NWEntity (by @Histalek)
- Updated Russian and English localization files (by @Satton2)
Expand Down
16 changes: 4 additions & 12 deletions gamemodes/terrortown/gamemode/server/sv_entity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -91,19 +88,14 @@ 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 or (self:IsScripted() and self.CanUseKey) then
return true
end

local caps = self:ObjectCaps()

if
bit.band(
caps,
Expand Down
98 changes: 67 additions & 31 deletions gamemodes/terrortown/gamemode/server/sv_player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,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()
TimGoll marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down Expand Up @@ -557,37 +623,7 @@ net.Receive("TTT2PlayerUseEntity", function(len, ply)
return
end

---
-- Enable addons to allow handling PlayerUse
-- Otherwise default to old IsTerror Check
-- @realm server
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)

---
Expand Down
Loading