Is this basic hud correct?

Just did this on my phone so I’m sure there’s capital letters in the wrong places and what not but finally think I’m getting the hang of the basics of drawing huds xD
Also I’ll be honest I had to get the table and the if v == name parts from the interne I wasn’t sure about that! Anyways I could improve on the organisation or shorten the code I know I could of done
hook.Add(“HUDPaint”, “PaintHud”, function() )
drawRoundedRect etc etc

Also I couldn’t input co-ordinates and color for the obvious reasons I ain’t got a PC Infront of me to twiddle about with. I’m hoping to be able to start getting more advance like making huds with pictures and making scoreboards because they are quite confusing.

But yeah first actual decent attempt at a hud (my opinion) I’m a nub :confused:


 Hud:

hudtable = {} --I will use the colors later not in this part of code
hudtable.colorwhite = Color ( 255, 255, 255, 255 )
hudtable.colorblack = Color ( 0, 0, 0, 255 )

function drawhud()

local client = LocalPlayer() --local variables 
local health = client:Health()
local name = client:nick()

draw.RoundedBox(co-ordinates and color etc) --Used for drawing a black background 

draw.RoundedBox(co-ordinates and color etc) --Used for drawing health bar
draw.RoudedBox(co-ordinates and color etc) --used for health bar shadow
draw.SimpleText(co-ordinates and color etc) -used to draw the amount of health in text

hook.Add("HUDPaint","PerfectDrawingHudName", drawhud) -our hook to draw the hud 

end

function hideoldhud(name) -- hide the old hud
for k, v in pairs ({old hud stuff here }) do 
If name == v then return false end
end
end

hook.Add("HUDShouldDraw","Oldhudhook","hideoldhud") 

U dont need to do that to hid the hud lol. Just hide the elements you want.

That’s the things I’m going to place In


 ({old hud stuff here})

Nvm you are right.

Instead of looping through all elements in the HUDShouldDraw function, use direct access…

Here’s why: https://dl.dropboxusercontent.com/u/26074909/tutoring/benchmarking_tips/benchmarking_hud_stuff.lua.html

100 million calls using table search : 15 seconds. 100 million calls using direct access : 0.08 seconds.

Here’s how: https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/proper_hud_creation.lua.html

Somethin’ ain’t right here…


draw.SimpleText( string text, string font, number x, number y, table color, number xAlign, number yAlign )

Plus he said it’s just a mock-up as he’s on his phone and therefore couldn’t do all the maths for it.

Thanks for this, really useful. I’ll incorporate this in my next work! :slight_smile: