Is there any function that targets the player your cursor is on, or maybe even on the default cross-hair target.
[lua]
local trace = LocalPlayer():GetEyeTrace()
local ent = trace.Entity
if ( IsValid( ent ) and ent:IsPlayer() ) then
// Do stuff
end
[/lua]
[url]http://wiki.garrysmod.com/page/GM/HUDDrawTargetID[/url] will draw the player name of the player you're hovering over.
You can do a trace, if the trace.Entity:IsPlayer( ) then you can do something like that too in HUDPaint which is exactly what the HUDDrawTargetID does.
gamemodes/base/gamemode/cl_targetid.lua -- Modify to make it draw whatever you want, or just hook into HUDDrawTargetID and do a trace like this does.
[lua]--[[---------------------------------------------------------
Name: gamemode:HUDDrawTargetID( )
Desc: Draw the target id (the name of the player you're currently looking at)
-----------------------------------------------------------]]
function GM:HUDDrawTargetID()
local tr = util.GetPlayerTrace( LocalPlayer() )
local trace = util.TraceLine( tr )
if (!trace.Hit) then return end
if (!trace.HitNonWorld) then return end
local text = "ERROR"
local font = "TargetID"
if (trace.Entity:IsPlayer()) then
text = trace.Entity:Nick()
else
return
--text = trace.Entity:GetClass()
end
surface.SetFont( font )
local w, h = surface.GetTextSize( text )
local MouseX, MouseY = gui.MousePos()
if ( MouseX == 0 && MouseY == 0 ) then
MouseX = ScrW() / 2
MouseY = ScrH() / 2
end
local x = MouseX
local y = MouseY
x = x - w / 2
y = y + 30
-- The fonts internal drop shadow looks lousy with AA on
draw.SimpleText( text, font, x+1, y+1, Color(0,0,0,120) )
draw.SimpleText( text, font, x+2, y+2, Color(0,0,0,50) )
draw.SimpleText( text, font, x, y, self:GetTeamColor( trace.Entity ) )
y = y + h + 5
local text = trace.Entity:Health() .. "%"
local font = "TargetIDSmall"
surface.SetFont( font )
local w, h = surface.GetTextSize( text )
local x = MouseX - w / 2
draw.SimpleText( text, font, x+1, y+1, Color(0,0,0,120) )
draw.SimpleText( text, font, x+2, y+2, Color(0,0,0,50) )
draw.SimpleText( text, font, x, y, self:GetTeamColor( trace.Entity ) )
end[/lua]
Sorry, you need to Log In to post a reply to this thread.