Code:
-- Draw the healthbar
local hp_bg = Material( "icons/bg_hp_sil.png" )
local hp_in = Material( "icons/in_hp_sil.png" )
function DrawHPImage( ply )
if !ply:Health() then return end
local w = 94
local h = 242
local padding = 36
local percent = ply:Health() / 100
local y = ScrH() - (padding * 3) - (infoBarH * 3)
local color = Color( 140, 50, 50, 255 )
// Background image.
render.SetMaterial( hp_bg )
render.DrawQuadEasy( Vector( padding + w/2, ScrH() - h/2,0), --position of the rect
Vector(0,0,-1), --direction to face in
w, h, --size of the rect
Color( 10, 10, 10, 200 ), --color
-90 --rotate 90 degrees
)
// Second background image
render.SetMaterial( hp_in )
render.DrawQuadEasy( Vector( padding + w/2, ScrH() - h/2,0), --position of the rect
Vector(0,0,-1), --direction to face in
w, h, --size of the rect
Color( 40, 10, 10, 240 ), --color
-90 --rotate 90 degrees
)
// Draw the actual HP
render.SetScissorRect( 0, ScrH() - (h * percent), padding + w, ScrH(), true )
render.SetMaterial( hp_in )
render.DrawQuadEasy( Vector( padding + w/2, ScrH() - h/2,0), --position of the rect
Vector(0,0,-1), --direction to face in
w, h, --size of the rect
color, --color
-90 --rotate 90 degrees
)
render.SetScissorRect( 0, ScrH() - h + 20, padding + w, ScrH(), false )
// Draw HP number.
if ply:Health() > 0 then
draw.SimpleTextOutlined( ply:Health(), "ChatFont", padding + w/2 - 4, ScrH() - h/2 - 26, Color( 255, 255, 255, 255 ), 1, 1, 1, Color( 0, 0, 0, 255 ))
end
end