Draws a textured rectangle with a repeated or partial texture. U and V refer to texture coordinates. 0,0 is the bottom left corner of the texture, 1,0 is the bottom right, 1,1 is the top right and 0,1 is the top left.
Think of UV as 2D X/Y coordinates for where to place the texture’s top left and bottom right corners.
local iWidth = 256
local iHeight = 32
local iPadding = 24
local tForeground = Color(255, 0, 0)
local tBackground = Color(127, 0, 0)
local mTexture = Material(“icon16/box.png”, “noclamp”)
hook.Add(“HUDPaint”, “HealthBar”, function()
– Anchor it to the bottom left.w
local x = iPadding
local y = ScrH() - iHeight - iPadding
-- Draw the static background
surface.DrawRect(x, y, iWidth, iHeight)
-- 100 standing for the max possible health.
local fFrac = LocalPlayer():Health() / 100
-- Adjust the draw width according to how much health there is left.
local iDrawWidth = iWidth * fFrac
-- Draw the dynamic foreground
surface.DrawTexturedRectUV(x, y, iDrawWidth, iHeight, 0, 0, fFrac, 1)
Now what this does is it creates the ugliest health bar known to man. But you can fix that by incorporating pictures that actually fit; rather than a box icon and a dark red background.
You can also make it go vertically and any which way direction you’d like. Here it is next to my own vertical orbs.
pretty aint it