TTT HUD?

My current TTT HUD doesnt have a ammo bar to display how much ammo you have, could someone help me and tell me how to edit this? :confused:


-- HUD HUD HUD

local table = table
local surface = surface
local draw = draw
local math = math
local string = string

local GetTranslation = LANG.GetTranslation
local GetPTranslation = LANG.GetParamTranslation
local GetLang = LANG.GetUnsafeLanguageTable
local interp = string.Interp

-- Fonts
surface.CreateFont("TraitorState", {font = "Trebuchet24",
                                    size = 28,
                                    weight = 1000})
surface.CreateFont("TimeLeft",     {font = "Trebuchet24",
                                    size = 24,
                                    weight = 800})
surface.CreateFont("HealthAmmo",   {font = "Trebuchet24",
                                    size = 24,
                                    weight = 750})
-- Color presets
local bg_colors = {
   background_main = Color(0, 0, 10, 200),

   noround = Color(100,100,100,200),
   traitor = Color(200, 25, 25, 200),
   innocent = Color(25, 200, 25, 200),
   detective = Color(25, 25, 200, 200)
};

local health_colors = {
   border = COLOR_WHITE,
   background = Color(100, 25, 25, 222),
   fill = Color(200, 50, 50, 250)
};

local ammo_colors = {
   border = COLOR_WHITE,
   background = Color(20, 20, 5, 222),
   fill = Color(205, 155, 0, 255)
};


-- Modified RoundedBox
local Tex_Corner8 = surface.GetTextureID( "gui/corner8" )
local function RoundedMeter( bs, x, y, w, h, color)
   surface.SetDrawColor(clr(color))

   surface.DrawRect( x+bs, y, w-bs*2, h )
   surface.DrawRect( x, y+bs, bs, h-bs*2 )

   surface.SetTexture( Tex_Corner8 )
   surface.DrawTexturedRectRotated( x + bs/2 , y + bs/2, bs, bs, 0 )
   surface.DrawTexturedRectRotated( x + bs/2 , y + h -bs/2, bs, bs, 90 )

   if w > 14 then
      surface.DrawRect( x+w-bs, y+bs, bs, h-bs*2 )
      surface.DrawTexturedRectRotated( x + w - bs/2 , y + bs/2, bs, bs, 270 )
      surface.DrawTexturedRectRotated( x + w - bs/2 , y + h - bs/2, bs, bs, 180 )
   else
      surface.DrawRect( x + math.max(w-bs, bs), y, bs/2, h )
   end

end

---- The bar painting is loosely based on:
---- http://wiki.garrysmod.com/?title=Creating_a_HUD

-- Paints a graphical meter bar
local function PaintBar(x, y, w, h, colors, value)
   -- Background
   -- slightly enlarged to make a subtle border
   draw.RoundedBox(8, x-1, y-1, w+2, h+2, colors.background)

   -- Fill
   local width = w * math.Clamp(value, 0, 1)

   if width > 0 then
      RoundedMeter(8, x, y, width, h, colors.fill)
   end
end

local roundstate_string = {
   [ROUND_WAIT]   = "round_wait",
   [ROUND_PREP]   = "round_prep",
   [ROUND_ACTIVE] = "round_active",
   [ROUND_POST]   = "round_post"
};

-- Returns player's ammo information
local function GetAmmo(ply)
   local weap = ply:GetActiveWeapon()
   if not weap or not ply:Alive() then return -1 end

   local ammo_inv = weap:Ammo1()
   local ammo_clip = weap:Clip1()
   local ammo_max = weap.Primary.ClipSize

   return ammo_clip, ammo_max, ammo_inv
end

local function DrawBg(x, y, width, height, client)
   -- Traitor area sizes
   local th = 30
   local tw = 170

   -- Adjust for these
   y = y - th
   height = height + th

   -- main bg area, invariant
   -- encompasses entire area
   draw.RoundedBox(8, x, y, width, height, bg_colors.background_main)

   -- main border, traitor based
   local col = bg_colors.innocent
   if GAMEMODE.round_state != ROUND_ACTIVE then
      col = bg_colors.noround
   elseif client:GetTraitor() then
      col = bg_colors.traitor
   elseif client:GetDetective() then
      col = bg_colors.detective
   end

   draw.RoundedBox(8, x, y, tw, th, col)
end

local sf = surface
local dr = draw
local function ShadowedText(text, font, x, y, color, xalign, yalign)

   dr.SimpleText(text, font, x+2, y+2, COLOR_BLACK, xalign, yalign)

   dr.SimpleText(text, font, x, y, color, xalign, yalign)
end

local margin = 10

-- Paint punch-o-meter
local function PunchPaint(client)
   local L = GetLang()
   local punch = client:GetNWFloat("specpunches", 0)

   local width, height = 200, 25
   local x = ScrW() / 2 - width/2
   local y = margin/2 + height

   PaintBar(x, y, width, height, ammo_colors, punch)

   local color = bg_colors.background_main

   dr.SimpleText(L.punch_title, "HealthAmmo", ScrW() / 2, y, color, TEXT_ALIGN_CENTER)

   dr.SimpleText(L.punch_help, "TabLarge", ScrW() / 2, margin, COLOR_WHITE, TEXT_ALIGN_CENTER)

   local bonus = client:GetNWInt("bonuspunches", 0)
   if bonus != 0 then
      local text
      if bonus < 0 then
         text = interp(L.punch_bonus, {num = bonus})
      else
         text = interp(L.punch_malus, {num = bonus})
      end

      dr.SimpleText(text, "TabLarge", ScrW() / 2, y * 2, COLOR_WHITE, TEXT_ALIGN_CENTER)
   end
end



local function createCircle(x,y,radius,quality)
quality = quality or 180
local circle = {}
local tmp = 0
local s,c
for i=1,quality do
tmp = math.rad(i*360)/quality
s = math.sin(tmp)
c = math.cos(tmp)
circle* = {x = x + c*radius,y = y + s*radius,u = (c+1)/2,v = (s+1)/2}
end
return circle
end

local key_params = { usekey = Key("+use", "USE") }

local function SpecHUDPaint(client)
   local L = GetLang() -- for fast direct table lookups

   -- Draw round state
   local x       = margin
   local height  = 32
   local width   = 250
   local round_y = ScrH() - height - margin

   -- move up a little on low resolutions to allow space for spectator hints
   if ScrW() < 1000 then round_y = round_y - 15 end

   local time_x = x + 170
   local time_y = round_y + 4

   draw.RoundedBox(0, x, round_y, width, height, bg_colors.background_main)
   draw.RoundedBox(0, x, round_y, time_x - x, height, bg_colors.noround)

   local text = L[ roundstate_string[GAMEMODE.round_state] ]
   ShadowedText(text, "TraitorState", x + margin, round_y, COLOR_WHITE)

   -- Draw round/prep/post time remaining
   local text = util.SimpleTime(math.max(0, GetGlobalFloat("ttt_round_end", 0) - CurTime()), "%02i:%02i")
   ShadowedText(text, "TimeLeft", time_x + margin, time_y, COLOR_WHITE)

   local tgt = client:GetObserverTarget()
   if IsValid(tgt) and tgt:IsPlayer() then
      ShadowedText(tgt:Nick(), "TimeLeft", ScrW() / 2, margin, COLOR_WHITE, TEXT_ALIGN_CENTER)

   elseif IsValid(tgt) and tgt:GetNWEntity("spec_owner", nil) == client then
      PunchPaint(client)
   else
      ShadowedText(interp(L.spec_help, key_params), "TabLarge", ScrW() / 2, margin, COLOR_WHITE, TEXT_ALIGN_CENTER)
   end
   
    if round_state == ROUND_PREP then 
local circle = createCircle(100,ScrH() - 100, 65) 
surface.SetDrawColor(128,128,128,255)
surface.SetTexture(0)
surface.DrawPoly( circle )
draw.DrawText("Preparing","SBTitleB",170,ScrH() - 172,Color(255,255,255,255),TEXT_ALIGN_LEFT)

elseif round_state == ROUND_POST then
local circle = createCircle(100,ScrH() - 100, 65) 
surface.SetDrawColor(128,128,128,255)
surface.SetTexture(0)
surface.DrawPoly( circle )
draw.DrawText("Round Over","SBTitleB",170,ScrH() - 172,Color(255,255,255,255),TEXT_ALIGN_LEFT)

elseif round_state == ROUND_WAIT then 
local circle = createCircle(100,ScrH() - 100, 65) 
surface.SetDrawColor(128,128,128,255)
surface.SetTexture(0)
surface.DrawPoly( circle )
draw.DrawText("Waiting","SBTitleB",170,ScrH() - 172,Color(255,255,255,255),TEXT_ALIGN_LEFT)
end
end

local ttt_health_label = CreateClientConVar("ttt_health_label", "0", true)

surface.CreateFont( "SBTitleB", {
font = "Calibri",
size = 30,
weight = 700,
blursize = 0,
scanlines = 0,
antialias = true,
underline = false,
italic = false,
strikeout = false,
symbol = false,
rotary = false,
shadow = false,
additive = false,
outline = true
} )

surface.CreateFont( "SBPName", {
font = "Calibri",
size = 20,
weight = 600,
blursize = 0,
scanlines = 0,
antialias = true,
underline = false,
italic = false,
strikeout = false,
symbol = false,
rotary = false,
shadow = true,
additive = false,
outline = false
} )

local function InfoPaint(client)
local L = GetLang()
local ply = LocalPlayer()
local HP = ply:Health()

local round_state = GAMEMODE.round_state
local endtime = GetGlobalFloat("ttt_round_end", 0) - CurTime()
local text = util.SimpleTime(math.max(0, endtime), "%02i:%02i") 


  local circle = createCircle(100,ScrH() - 100, 70) 
surface.SetDrawColor(46,46,46,255)
surface.SetTexture(0)
surface.DrawPoly( circle )

draw.RoundedBoxEx(1,145,ScrH() - 150,250,100,Color(46,46,46,255),false,true,false,true)

if ( LocalPlayer():GetRole() == ROLE_INNOCENT ) then 
local circle = createCircle(100,ScrH() - 100, 65) 
surface.SetDrawColor(40,200,40,255)
surface.SetTexture(0)
surface.DrawPoly( circle )
draw.DrawText("Innocent","SBTitleB",100,ScrH() - 117,Color(255,255,255,255),TEXT_ALIGN_CENTER)
elseif ( LocalPlayer():GetRole() == ROLE_TRAITOR ) then 
local circle = createCircle(100,ScrH() - 100, 65) 
surface.SetDrawColor(255,40,40,255)
surface.SetTexture(0)
surface.DrawPoly( circle ) 
draw.DrawText("Traitor","SBTitleB",100,ScrH() - 117,Color(255,255,255,255),TEXT_ALIGN_CENTER)
draw.DrawText(L.hastemode,"TabLarge", 370,ScrH() - 180,Color(255,255,255,255),TEXT_ALIGN_CENTER)
elseif ( LocalPlayer():GetRole() == ROLE_DETECTIVE ) then 
local circle = createCircle(100,ScrH() - 100, 65) 
surface.SetDrawColor(40,40,255,255)
surface.SetTexture(0)
surface.DrawPoly( circle )
draw.DrawText("Detective","SBTitleB",100,ScrH() - 117,Color(255,255,255,255),TEXT_ALIGN_CENTER)
end

if round_state == ROUND_PREP then 
local circle = createCircle(100,ScrH() - 100, 65) 
surface.SetDrawColor(128,128,128,255)
surface.SetTexture(0)
surface.DrawPoly( circle )
draw.DrawText("Preparing","SBTitleB",170,ScrH() - 172,Color(255,255,255,255),TEXT_ALIGN_LEFT)

elseif round_state == ROUND_POST then
local circle = createCircle(100,ScrH() - 100, 65) 
surface.SetDrawColor(128,128,128,255)
surface.SetTexture(0)
surface.DrawPoly( circle )
draw.DrawText("Round Over","SBTitleB",170,ScrH() - 172,Color(255,255,255,255),TEXT_ALIGN_LEFT)

elseif round_state == ROUND_WAIT then 
local circle = createCircle(100,ScrH() - 100, 65) 
surface.SetDrawColor(128,128,128,255)
surface.SetTexture(0)
surface.DrawPoly( circle )
draw.DrawText("Waiting","SBTitleB",180,ScrH() - 172,Color(255,255,255,255),TEXT_ALIGN_LEFT)
end

// HP 
draw.RoundedBox(0,180,ScrH() - 135,200,30,Color(10,10,10,255))
draw.RoundedBox(0,182,ScrH() - 133,math.Clamp(HP,0,100)*1.96,26,Color(255,40,40,255))
draw.DrawText("Health: "..HP.." /100","SBPName",280,ScrH() - 132,Color(255,255,255,255),TEXT_ALIGN_CENTER)

// Karma
local carma = math.Round(ply:GetBaseKarma())
if KARMA.IsEnabled() then
draw.RoundedBox(0,290,ScrH() - 90,90,30,Color(16,16,16,255))
draw.RoundedBox(0,292,ScrH() - 88,85,26,Color(80,80,255,255))
draw.DrawText("Ka: "..carma,"SBPName",295,ScrH() - 86,Color(255,255,255,255),TEXT_ALIGN_LEFT)
end

// Points
draw.RoundedBox(0,180,ScrH() - 90,90,30,Color(16,16,16,255))
draw.RoundedBox(0,182,ScrH() - 88,85,26,Color(80,80,255,255))
draw.DrawText("PS: "..ply:PS_GetPoints(),"SBPName",185,ScrH() - 86,Color(255,255,255,255),TEXT_ALIGN_LEFT)
// Haste
draw.DrawText(text,"SBPName",370,ScrH() - 170,Color(255,255,255,255),TEXT_ALIGN_CENTER)
end

-- Paints player status HUD element in the bottom left
function GM:HUDPaint()
   local client = LocalPlayer()

   GAMEMODE:HUDDrawTargetID()

   MSTACK:Draw(client)

   if (not client:Alive()) or client:Team() == TEAM_SPEC then
      SpecHUDPaint(client)

      return
   end


   RADAR:Draw(client)
   TBHUD:Draw(client)
   WSWITCH:Draw(client)

   VOICE.Draw(client)
   DISGUISE.Draw(client)

   GAMEMODE:HUDDrawPickupHistory()

   -- Draw bottom left info panel
   InfoPaint(client)
end

-- Hide the standard HUD stuff
local hud = {"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo"}
function GM:HUDShouldDraw(name)
   for k, v in pairs(hud) do
      if name == v then return false end
   end

   return true
end

This ends up looking like this

So i would like someone to help me with the ammo bar please!

This is developer discussion, a place in which you can ask for help in fixing errors, bugs and glitches, it’s also a great place to ask for advices and such but it is NOT a place for a typical ‘heres code, do it for me’ threads.

AKA read the Sticky.

Ya know, you could just reverse engineer the code you already HAVE to make it do what you would like?
Ex: OH this function does this, so if I do this it should do that aswell.

I created it for someone, he didn’t liked it so I didn’t finished it and then I uploaded it on gmod.org
Don’t ask for help it’s not worth, the HUD looks like shit.