HUDDrawTargetID() see other traitors

Hello.

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()

		surface.SetFont("Trebuchet24")
		local x,y = surface.GetTextSize("Traitor")	
		surface.SetTextPos(traitorpos.x - x/2,traitorpos.y - 40)
	        surface.SetTextColor(Color(200,0,0,220))	
		surface.DrawText("Traitor")

	
end
end
end)


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
	end
end )


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

[editline]22nd August 2016[/editline]

ninja’d

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!