Silkicons in HUD?

So I have been kinda learning how to create a hud and I wanted to attempt at making a very simple one but wanted to have icons in the actual HUD. Well, as I was doing that the icons kept getting put behind the HUD. So I am a little confused on how to exactly do it. I’ll put the full code to hud below.


if !CLIENT then return end
	
	local money_icon = Material( "icon16/money_dollar.png" )
	local star_icon = Material( "icon16/star.png" )
	local page_icon = Material( "icon16/page_add.png" )
	



	local v = { "DarkRP_HUD", "CHudBattery", "CHudHealth" }

	hook.Add( 'HUDShouldDraw', 'HUD_HIDE_DRKP', function( vs )
          if table.HasValue( v, vs ) then return false end
      end )
	  	
	  
	hook.Add( 'HUDPaint', 'HUD_DRAW_HUD', function()
          CreateHUD()
    end )
	
	
	
function CreateHUD()
	
	surface.SetMaterial(money_icon)
	surface.SetDrawColor(color_white)
	surface.DrawTexturedRect(40, 900, 16, 16)
	
	--Main Background
	draw.RoundedBox(0, 20, ScrH() - 225, 450, 205, Color(50,50,50,235))
	
	--Player Icon
	draw.RoundedBox(0, 45, ScrH() - 215, 100, 90, Color(100, 100, 100, 255))
	
	--Health Stuff
	draw.RoundedBox(0, 45, ScrH() - 110, 300, 35, Color(100, 100, 100, 100))
	
	local DrawHealth = LocalPlayer():Health() or 0
	local EchoHealth = LocalPlayer():Health() or 0
	
	if DrawHealth > 100 then DrawHealth = 100 end
	if DrawHealth < 0 then DrawHealth = 0 end
	
	if DrawHealth != 0 then
	
		draw.RoundedBox(0, 47, ScrH() - 110 + 2, 300 * DrawHealth / 101.5, 31, Color(200, 0, 0, 255))
	
	end
	
	draw.DrawText( "Health: "..EchoHealth, "Trebuchet24", 50, ScrH() - 108 + 2, Color(255, 255, 255, 255))
	
	--Armor Stuff
	draw.RoundedBox(0, 45, ScrH() - 70, 300, 35, Color(100, 100, 100, 100))
	
	local DrawArmor = LocalPlayer():Armor() or 0
	local EchoArmor = LocalPlayer():Armor() or 0
	
	if DrawArmor > 100 then DrawArmor = 100 end
	if DrawArmor < 0 then DrawArmor = 0 end
	
	if DrawArmor != 0 then
	
		draw.RoundedBox(0, 47, ScrH() - 70 + 2, 300 * DrawArmor / 101.5, 31, Color(0, 0, 255, 255))
	
	end
	
	draw.DrawText("Armor: "..EchoArmor, "Trebuchet24", 50, ScrH() - 68 + 2, Color(255, 255, 255, 255))
	
	--Salary, Job, Name
	draw.RoundedBox(0, 350, ScrH() - 110, 100, 75, Color (100, 100, 100, 100))
	draw.DrawText( LocalPlayer():Nick(), "Trebuchet24", 150, ScrH() - 175 - 35, Color(255, 255, 255, 255))
	draw.DrawText("Job: "..LocalPlayer():getDarkRPVar( "job" ), "Trebuchet24", 150, ScrH() - 145 - 30, Color(255, 255, 255, 255))
		
end




 local function DisplayNotify(msg)
    local txt = msg:ReadString()
    GAMEMODE:AddNotify(txt, msg:ReadShort(), msg:ReadLong())
    surface.PlaySound("buttons/lightswitch2.wav")

    -- Log to client console
    MsgC(Color(255, 20, 20, 255), "[DarkRP] ", Color(200, 200, 200, 255), txt, "
")
end
usermessage.Hook("_Notify", DisplayNotify)

You’re drawing the icons before your draw in the backgrounds. Just swap them around should fix it.

That worked! Thank you very much!



local v = { "DarkRP_HUD", "CHudBattery", "CHudHealth" }

	hook.Add( 'HUDShouldDraw', 'HUD_HIDE_DRKP', function( vs )
          if table.HasValue( v, vs ) then return false end
      end )


This is very slow. Please refer to the example on the wiki page:



local hide = {
	CHudHealth = true,
	CHudBattery = true,
}

hook.Add( "HUDShouldDraw", "HideHUD", function( name )
	if ( hide[ name ] ) then return false end
end )


This is much faster as it indexes directly and doesn’t need to loop through the entire table every single time. Your code should be:



local hide = {
    DarkRP_HUD = true,
    CHudBattery = true,
    CHudHealth = true
}

hook.Add( "HUDShouldDraw", "HUD_HIDE_DRKP", function( name )
    if hide[ name ] then return false end
end )


[editline]3rd September 2017[/editline]

Also, please don’t use usermessages, they’re ancient and deprecated



usermessage.Hook("_Notify", DisplayNotify) -- please no


You should really be using the net library, as the wiki suggests.

[editline]3rd September 2017[/editline]

Also, this function:



function CreateHUD()


Should be local:



local function CreateHUD()


If it’s not local, it could get overridden or broken by another addon.

That’s a DarkRP usermessage, not really his choice.