HUDDrawTargetID problems.

So, I have a cloaking device on my server. I want to remove the player’s names from showing up when you pan over them.
[lua]
function TSE_TargetDisplay()

local tr = utilx.GetPlayerTrace( LocalPlayer(), LocalPlayer():GetCursorAimVector() )
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

local r,g,b,a = trace.Entity:GetColor()
if (a==0) then return 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
hook.Add(“HUDDrawTargetID”, “TSE_TargetDisplay”, TSE_TargetDisplay)
[/lua]
That’s the code I’m using. I’ve gone as far as to cut all the draw code and just put “return false”, but it still draws the name (granted, I just did lua_openscript_cl for this test)

Am I missing something obvious? Is there some magic trick to make this code work?

You can’t disable it by returning a value.

I know. But the return should stop it from getting to the draw part. And it didn’t work even when it was just return, instead of return false.

I had this problem too. You’re going to have to override the gamemode function itself.

Well, you could override the function (GAMEMODE:HUDDrawTargetID), because the hooks in this case are called after the function is. But a better way would be to override util.TraceLine (works with custom gamemodes too):

[lua]
– Call this stuff somewhere on the clientside

local oldTraceLine = util.TraceLine;
function util.TraceLine(…)
local trace = oldTraceLine(…); – Run the trace normally
if(ValidEntity(trace.Entity) && trace.Entity:IsPlayer()) then – If it hit a player
local r,g,b,a = trace.Entity:GetColor();
if(a <= 0) then – Player’s alpha is zero or below it
trace.Hit = false; – Alter the results, so it thinks that we hit nothing
trace.HitNonWorld = false;
trace.Entity = NULL;
end
end
return trace; – Return the results
end
[/lua]

Untested, but it should work, as I’ve done something like this before. And no, it doesn’t conflict with anything, as oldTraceLine is a local.

So you’re saying instead of just replacing the intended function to be replaced, you should replace the util.TraceLine function that is used by everything in Garry’s Mod so that whenever a player’s alpha is zero they are null? :raise:

Facts:

Replacing GAMEMODE:HUDDrawTargetID may break custom gamemodes, or the custom TargetIDs used in them

util.TraceLine is only being replaced on clientside, it doesn’t affect serverside stuff

We’re manipulating only the results, not the entity itself

You could always replace that alpha check with something like trace.Entity:GetNWBool(“cloaked”), which would be always better

Catdaemon used a similiar method on his cloaking-weapon, and it works

derp. I didn’t read over the entirety of TomatoSoup’s code so the alpha part made me confused. That would work then, I suppose. This is what I get for posting at 2am. I was referring to the result as well, by the way.

You should probably get some sleep then, no offence. Edited/improved the code so it also sets trace.Hit and trace.HitNonWorld to false.

Bedtime it is then. :v:

So I would have the clients always do this trace, instead of the default one?

That overwrites the default trace, so you just need to put that somewhere on your clientside code and everything should work.

The clients automagically always do that trace instead of the default one.