A Simple ammo counter

Its a bit rude of me, barging in here and asking you to do something for me but I am truly shit at VGUI stuff.

All I would like is a little box that sits slightly above the bottom right hand corner which show’s the current ammo in the gun and the ammo of that type remaining.

Sorry if you find my post a bit rude.

Code By LaaZa. All I did was edit one or two things to make it fit your needs.

[lua]if (SERVER) then return end //Clientside only

function CustomFont()
surface.CreateFont (“coolvetica”,16, 400, true, true, “GlassHUD_1”)
surface.CreateFont (“coolvetica”,36, 400, true, true, “GlassHUD_2”)
end
hook.Add( “Initialize”, “GlassHUD_CustomFont”,CustomFont);

function CustomGlassHUD()

local ply = LocalPlayer()
local AMouter = Color(255,255,255, 150 )
local AMinner = Color(50,50,50,255)
local AMDisplay = Color(255,255,255,255)
local AMLight = Color(255,255, 255,50)
local AMtextColor = Color(255,255,255,255)
local AMPosx,AMPosy = ScrW() * 0.85, ScrH() * 0.92
local FONT_1 = "GlassHUD_1"
local FONT_2 = "GlassHUD_2"

local function drawammoDisplayBox(posx,posy,outerbox,innerbox,text,textcol,bgtext,bgtxtcol,lightbox,sizeX,SizeY,fix)
    draw.RoundedBox(6, posx-50,posy - 25, sizeX,SizeY, outerbox)
    draw.RoundedBox(6, posx-45,posy - 20, sizeX - 10,SizeY - 20,innerbox)
	draw.SimpleText(text,FONT_2, posx + fix,posy + 10,textcol, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
    draw.RoundedBox(6, posx-45,posy - 20, sizeX - 10,SizeY - 50,lightbox)
    draw.SimpleText(bgtext,FONT_1,posx + fix,posy + 48,bgtxtcol, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
end

if ply:GetActiveWeapon():IsWeapon() and ply:Alive() then
		local magazine1 = ply:GetActiveWeapon():Clip1()
		local magazines = ply:GetAmmoCount(ply:GetActiveWeapon():GetPrimaryAmmoType())
		local magazine2 = ply:GetAmmoCount(ply:GetActiveWeapon():GetSecondaryAmmoType())
		
		if (magazine1 != -1) and (magazine2 != 0) then
			drawammoDisplayBox(AMPosx,AMPosy,AMouter,AMinner,magazine1.." | "..magazines.." | "..magazine2,AMtextColor,"AMMUNITION",AMDisplay,AMLight,250,80,70)
		elseif !(magazine1 < 1 ) and !(magazines < 0) then
			drawammoDisplayBox(AMPosx,AMPosy,AMouter,AMinner,magazine1.." | "..magazines ,AMtextColor,"AMMUNITION",AMDisplay,AMLight,200,80,50)
		elseif (magazine1 < 0) and !(magazines < 1) then
			drawammoDisplayBox(AMPosx,AMPosy,AMouter,AMinner,magazines,AMtextColor,"AMMUNITION",AMDisplay,AMLight,200,80,50)
		elseif (magazinel == nil) then
			drawammoDisplayBox(AMPosx,AMPosy,AMouter,AMinner,"0".." | ".. magazines ,AMtextColor,"AMMUNITION",AMDisplay,AMLight,200,80,50)
		elseif (magazines == nil) then
			drawammoDisplayBox(AMPosx,AMPosy,AMouter,AMinner,magazine1.." | ".. "0" ,AMtextColor,"AMMUNITION",AMDisplay,AMLight,200,80,50)
		end    
	end

end
hook.Add(“HUDPaint”,“CustomGlassHUD”,CustomGlassHUD)

function HideHudComponents(name)
if (name == “CHudAmmo”) or (name == “CHudSecondaryAmmo”) then
return false
end
end
hook.Add( “HUDShouldDraw”, “HideHudComponents”,HideHudComponents)[/lua]

That works perfectly, Thank you! :slight_smile: