How to pass a life bar over a material?

Hello,
I am annoyed because I work on a HUD, I created a background for my hud except that I can not manage to pass the bar of life, the text above this material each time my bar of life is found below the material. Thank you in advance for your reply, the code:

[lua]
include(“config_replacement.lua”)
resource.AddFile( “material/bibihud/blabla_tout.png” )
local icone = false
local b_base = Material( “material/bibihud/blabla_tout.png” ) – Calling Material() every frame is quite expensive

hook.Add( “HUDPaint”, “HUDHealth”, function()

local health = LocalPlayer():Health() or 0
if health < 0 then health = 0 elseif health > 100 then health = 100 end
draw.RoundedBox( 0, 80, ScrH() -125, health *3 -20, 17, Color(192, 57, 43, 255)) – box de vie
end)
hook.Add( “HUDPaint”, “b_base”, function()
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial(b_base) – If you use Material, cache it!
surface.DrawTexturedRect( 0, 580, 320, 500 )
end )
-----------------------------------------------Désactiver les hud de base----------------------------------------------------------------------
------------------------------Darkrp
local hideHUDElements = {
– if you DarkRP_HUD this to true, ALL of DarkRP’s HUD will be disabled. That is the health bar and stuff,
– but also the agenda, the voice chat icons, lockdown text, player arrested text and the names above players’ heads
[“DarkRP_HUD”] = false,

-- DarkRP_EntityDisplay is the text that is drawn above a player when you look at them.
-- This also draws the information on doors and vehicles
["DarkRP_EntityDisplay"] = false,

-- DarkRP_ZombieInfo draws information about zombies for admins who use /showzombie.
["DarkRP_ZombieInfo"] = false,

-- This is the one you're most likely to replace first
-- DarkRP_LocalPlayerHUD is the default HUD you see on the bottom left of the screen
-- It shows your health, job, salary and wallet
["DarkRP_LocalPlayerHUD"] = true,

-- Drawing the DarkRP agenda
["DarkRP_Agenda"] = true

}

– this is the code that actually disables the drawing.
hook.Add(“HUDShouldDraw”, “HideDefaultDarkRPHud”, function(name)
if hideHUDElements[name] then return false end
end)
-------------------------------------- Sandbox
hook.Add( “HUDShouldDraw”, “DefautHUD”, function( name ) if ( name == “CHudHealth” or name == “CHudBattery” ) then return false end
end )[/lua]

Firstly, use [noparse][lua][/lua][/noparse] tags, it makes it so much easier for others to help you.

Secondly, you are drawing your interface in two different functions for the same hook. The order of execution for hooks is undefined (https://github.com/Facepunch/garrysmod/blob/master/garrysmod/lua/includes/modules/hook.lua#L77 ), and you therefore cannot expect them to be called in the order of definition. This rule is valid for any asynchronous functions.

Group them into the same hook, and call your draw functions in the order of back to front. Example:

[lua]
hook.Add( “HUDPaint”, “HUDHealth”, function()
– Background
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial(b_base) – If you use Material, cache it!
surface.DrawTexturedRect( 0, 580, 320, 500 )

-- Foreground
local health = LocalPlayer():Health() or 0
if health &lt; 0 then health = 0 elseif health &gt; 100 then health = 100 end
draw.RoundedBox( 0, 80, ScrH() -125, health *3 -20, 17, Color(192, 57, 43, 255)) -- box de vie

end)
[/lua]

thank you i did as you said [lua] [/ lua], for the code i try it right away the time gmod is working

[editline]20th September 2017[/editline]

thanks the script working :toot: