Skip to content

Commit

Permalink
TargetID: Fixed and Improved Vehicle Integration (#1614)
Browse files Browse the repository at this point in the history
Fixed the targetID bug where the player would see their own name in
targetID while they were in a vehicle:
https://www.youtube.com/shorts/qAhQHJRp7eo

While I was at it, I added targetID and KeyInfo integration to it as
well.
  • Loading branch information
TimGoll authored Sep 19, 2024
1 parent 2c8edbd commit 960c70e
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel
- Added force role admin command (by @mexikoedi)
- Added `draw.RefreshAvatars(id64)` to refresh avatar icons (by @mexikoedi)
- Added `GM:TTT2OnButtonUse(ply, ent, oldState)`: a hook that is triggered when a button is pressed and that is able to prevent that button press (by @TimGoll)
- Added TargetID and keyInfo to vehicles (by @TimGoll)
- Added `GM:TTT2PostButtonInitialization(buttonList)`: a hook that is called after all buttons on the map have been initialized (by @TimGoll)

### Changed
Expand Down Expand Up @@ -115,6 +116,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel
- Fixed OldTTT HUD sidebar elements missing translation (by @TimGoll)
- Fixed avatar icons not refreshing if they were changed on Steam (by @mexikoedi)
- Fixed a wrong label for the sprint speed multiplier in the F1 menu (by @TimGoll)
- Fixed own player name being shown in targetID when in vehicle (by @TimGoll)

### Removed

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"UnlitGeneric"
{
"$basetexture" "vgui/ttt/hudhelp/leave_vehicle"
"$nocull" 1
"$nodecal" 1
"$nolod" 1
"$translucent" 1
"$vertexalpha" 1
"$vertexcolor" 1
}
Binary file not shown.
1 change: 1 addition & 0 deletions gamemodes/terrortown/gamemode/client/cl_targetid.lua
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ function GM:HUDDrawTargetID()
targetid.HUDDrawTargetIDButtons(tData)
targetid.HUDDrawTargetIDDoors(tData)
targetid.HUDDrawTargetIDDNAScanner(tData)
targetid.HUDDrawTargetIDVehicle(tData)

-- add hints to the focused entity (deprecated method of adding stuff to targetID)
local hint = ent.TargetIDHint
Expand Down
5 changes: 5 additions & 0 deletions lua/terrortown/lang/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2361,3 +2361,8 @@ The minimum display time is there to give the player time to read the tips. If t

L.label_enable_loadingscreen_server = "Enable the loadingscreen serverwide"
L.label_loadingscreen_min_duration = "Minimum loadingscreen display time"

-- 2024-09-18
L.label_keyhelper_leave_vehicle = "leave vehicle"
L.name_vehicle = "Vehicle"
L.vehicle_enter = "Press [{usekey}] to enter vehicle"
14 changes: 14 additions & 0 deletions lua/ttt2/libraries/keyhelp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ local materialShowmore = Material("vgui/ttt/hudhelp/showmore")
local materialPointer = Material("vgui/ttt/hudhelp/pointer")
local materialThirdPerson = Material("vgui/ttt/hudhelp/third_person")
local materialSave = Material("vgui/ttt/hudhelp/save")
local materialLeaveVehicle = Material("vgui/ttt/hudhelp/leave_vehicle")

---
-- @realm client
Expand Down Expand Up @@ -594,6 +595,19 @@ function keyhelp.InitializeBasicKeys()
return true
end
)
keyhelp.RegisterKeyHelper(
"+use",
materialLeaveVehicle,
KEYHELP_CORE,
"label_keyhelper_leave_vehicle",
function(client)
if client:IsSpec() or not client:InVehicle() then
return
end

return true
end
)

-- extra bindings that are not that important but are there as well
keyhelp.RegisterKeyHelper(
Expand Down
42 changes: 39 additions & 3 deletions lua/ttt2/libraries/targetid.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ end
-- @return number The Distance between the Origin and the Entity
-- @realm client
function targetid.FindEntityAlongView(pos, dir, filter)
local client = LocalPlayer()
local endpos = dir

endpos:Mul(MAX_TRACE_LENGTH)
endpos:Add(pos)

if entspawnscript.IsEditing(LocalPlayer()) then
if entspawnscript.IsEditing(client) then
local focusedSpawn = entspawnscript.GetFocusedSpawn()
local wepEditEnt = entspawnscript.GetSpawnInfoEntity()

Expand Down Expand Up @@ -108,8 +110,12 @@ function targetid.FindEntityAlongView(pos, dir, filter)
local ent = trace.Entity

-- if a vehicle, we identify the driver instead
if IsValid(ent) and IsValid(ent:GetNWEntity("ttt_driver", nil)) then
ent = ent:GetNWEntity("ttt_driver", nil)
if IsValid(ent) then
local driver = ent:GetNWEntity("ttt_driver", nil)

if IsValid(driver) and driver ~= client then
ent = driver
end
end

return ent, trace.StartPos:Distance(trace.HitPos)
Expand Down Expand Up @@ -719,3 +725,33 @@ function targetid.HUDDrawTargetIDDNAScanner(tData)
tData:AddDescriptionLine(TryT("dna_tid_impossible"), COLOR_RED, { materialDNATargetID })
end
end

---
-- This function handles looking at usable vehicles
-- @param TARGET_DATA tData The object to be used in the hook
-- @realm client
function targetid.HUDDrawTargetIDVehicle(tData)
local client = LocalPlayer()
local ent = tData:GetEntity()

if
not IsValid(client)
or not client:IsTerror()
or client:InVehicle()
or not IsValid(ent)
or not ent:IsVehicle()
or tData:GetEntityDistance() > 100
then
return
end

-- enable targetID rendering
tData:EnableText()
tData:EnableOutline()
tData:SetOutlineColor(client:GetRoleColor())

tData:SetKey(input.GetKeyCode(key_params.usekey))

tData:SetTitle(TryT(ent.PrintName or "name_vehicle"))
tData:SetSubtitle(ParT("vehicle_enter", key_params))
end

0 comments on commit 960c70e

Please sign in to comment.