Skip to content

Instantly share code, notes, and snippets.

@Starfox64
Created May 14, 2016 15:19
Show Gist options
  • Save Starfox64/702ad7f486d198c072c1b89cb06f4cc3 to your computer and use it in GitHub Desktop.
Save Starfox64/702ad7f486d198c072c1b89cb06f4cc3 to your computer and use it in GitHub Desktop.
Example HUD for GMod (with scale)
local font = "PF Ronda Seven"
surface.CreateFont( "Microblast_BarText", {
font = font,
size = 20,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = false
})
local bgColor = Color(31, 31, 31)
local emptyColor = Color(128, 128, 128)
local redLow = Color(251, 96, 80)
local redHigh = Color(201, 46, 30)
local scrWidth = 1920
local scrHeight = 1080
local multX = ScrW() / scrWidth
local multY = ScrH() / scrHeight
hook.Add("HUDPaint", "Microblast", function()
local hpBg = {
{x = 50 * multX, y = 1010 * multY},
{x = 510 * multX, y = 1010 * multY},
{x = 530 * multX, y = 1040 * multY},
{x = 70 * multX, y = 1040 * multY}
}
surface.SetDrawColor(bgColor)
surface.DrawPoly(hpBg)
for i = 0, 9 do
local block = {
{x = (60 + i * 45) * multX, y = 1015 * multY},
{x = (100 + i * 45) * multX, y = 1015 * multY},
{x = (115 + i * 45) * multX, y = 1035 * multY},
{x = (75 + i * 45) * multX, y = 1035 * multY}
}
if i <= 2 then
if LocalPlayer():Health() >= (i + 1) * 10 then
surface.SetDrawColor(redHigh)
else
surface.SetDrawColor(redLow)
end
else
if LocalPlayer():Health() >= (i + 1) * 10 then
surface.SetDrawColor(color_white)
else
surface.SetDrawColor(emptyColor)
end
end
surface.DrawPoly(block)
end
end)
local toHide = {
["CHudHealth"] = true,
["CHudBattery"] = true,
["CHudAmmo"] = false,
["CHudSecondaryAmmo"] = false
}
hook.Add("HUDShouldDraw", "MicroblastHide", function( name )
if toHide[name] then
return false
end
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment