HUDDrawTargetID() see other traitors


I’m learning to use the hook HUDDrawTargetID(), because I didn’t found anything in the web.
I would like to make traitors can see where is other traitors with a text, I made this but it is very badly coded:

hook.Add("HUDDrawTargetID", "ShowTraitors", function()
for _, ply in pairs(player.GetAll()) do
if ply:IsTraitor() then

		local traitorpos = ply:GetPos():ToScreen()

		local x,y = surface.GetTextSize("Traitor")	
		surface.SetTextPos(traitorpos.x - x/2,traitorpos.y - 40)


I tried to make something but it is the hell of the code xD

Can someone help me?

Use HUDPaint

Wait, you really couldn’t find

GM:HUDPaint? Anyway, close enough. It looks like that code would work but it could be simplified into this:

hook.Add( "HUDPaint", "ShowTraitors", function()
	for _, ply in pairs( player.GetAll() ) do
		if ply:IsTraitor() then
			local traitorpos = ply:GetPos():ToScreen()
			draw.SimpleText( "Traitor", "Trebuchet24", traitorpos.x, traitorpos.y, Color( 255, 0, 0, 255 ), TEXT_ALIGN_CENTER, TEXT_ALIGN_BOTTOM )
end )

I didn’t really change anything since your original code was perfectly fine though :stuck_out_tongue:

[editline]22nd August 2016[/editline]


Thank you!
Only one question, when have I to use HUDDrawTargetID() ?

Really only when you want to override that name thing that pops up below players when you mouse over them - if you want it to display for ALL players then HUDPaint is probably a better option - although they both do pretty much the same thing

Thank you!