Mafia's Slick Sandbox HUD Template

Hello! I was lost on what to do and I was bored, so I present to you, a simple HUD template!
Recognize this is WIP and errors may be present, this is literally just a simpler version of a HUD I made, I just made the localization more easy to comprehend, so this has gone without testing.
Please help me by pointing out any errors, thank you.
Any questions or comments, send a comment, pm, or on my steam profile.



-- Mafia's Slick Sandbox HUD Template
-- Version 12-7-16
-- WIP -- ANY ERRORS? CONTACT ME AT http://steamcommunity.com/id/woahgtheremafia/
-- There is still a lot to be worked on FYI
-- Feel free to use, but promise me you will try and not Ctrl + C if you are new to developing!
-- It would be very much appreciated if you gave me at least some credits in wherever you share it.

local hideHL2HUD =  {
	["CHudHealth"] = true,
	["CHudBattery"] = true,
	["CHudAmmo"] = true,
	["CHudSecondaryAmmo"] = true,
}
hook.Add("HUDShouldDraw", "HideDefDarkHUD", function( name )
	if hideHL2HUD[ name ] then return false end
end )

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

--[[------------[[
	   Spacer
--]]------------]]
MAF = MAF or {}
C = C or {}

C.Health = Color( 255, 120, 120, 255 )
C.Armor = Color( 66, 134, 244, 255 )

MAF.CamV = Vector( 20, 0, 65 )
MAF.LookV = Vector( 0, 0, 65 )

local ply = LocalPlayer()
local weapon = LocalPlayer():GetActiveWeapon()
local avataropen = false

--[[------------[[
	 The Entrée
--]]------------]]

local function Base()
	draw.RoundedBox(0, 0, ScrH() - 125, 425, 125, Color(0, 0, 0, 210))
	draw.RoundedBox(0, 0, ScrH() - 250, 125, 125, Color(0, 0, 0, 210))
	draw.RoundedBox(0, 130, ScrH() - 155, 295, 25, Color(0,0,0,210))
end
/*
local function plyS() 

	This right here could use some fixing, may come in future updates. Don't criticize!

	if avataropen == false then
		avataropen = true
		plyM = vgui.Create( "DModelPanel" )
		function plyM:LayoutEntity( Entity ) return end
		plyM:SetModel( ply:GetModel() )
		plyM:SetPos( 0, ScrH() - 295 )
		plyM:SetSize( 135, 170 )
		plyM:SetCamPos( MAF.CamV )
		plyM:SetLookAt( MAF.LookV )
		timer.Create( "check4change", 0.5, 0, function()
			if ply:GetModel() ~= plyM.Entity:GetModel() then
				plyM:Remove()
				plyM = vgui.Create( "DModelPanel" )
				function plyM:LayoutEntity( Entity ) return end
				plyM:SetModel( ply:GetModel() )
				plyM:SetPos( 0, ScrH() - 295 )
				plyM:SetSize( 145, 170 )
				plyM:SetCamPos( MAF.CamV )
				plyM:SetLookAt( MAF.LookV )
			end
		end )
	end
end
*/
local function Stats()
	-- Use here if working with statistics like in DarkRP
end

local function mHealth()
	local Het = ply:Health()
	mHealth = Lerp(0.02 , mHealth , ply:Health())
	draw.RoundedBox(0, 5, ScrH() - 125 + 10, 250, 50, Color(0, 0, 0, 230))
	draw.RoundedBox(0, 5, ScrH() - 125 + 10, mHealth * 3 - 50, 50, C.Health)
	draw.RoundedBox(0, 5, ScrH() - 125 + 10, mHealth * 3 - 50, 5, Color(255, 150, 150, 255))
	draw.DrawText("Health : "..Het, "MFont", 15, ScrH() - 100,Color(255, 255, 255, 255), TEXT_ALIGN_LEFT)
end

local function mArmor()
	local Arm = ply:Armor()
	mArmor = Lerp(0.02 , mArmor , ply:Armor())
	draw.RoundedBox(0, 5, ScrH() - 55, 250, 50, Color(0, 0, 0, 230))
	draw.RoundedBox(0, 5, ScrH() - 55, mArmor * 3 - 50, 50, C.Armor)
	draw.RoundedBox(0, 5, ScrH() - F55, mArmor * 3 - 50, 5, Color(66, 164, 255, 255))
	draw.DrawText("Armor : "..Arm, "MFont", 15, ScrH() - 40,Color(255, 255, 255, 255), TEXT_ALIGN_LEFT)
end

local function Ammo()
	if IsValid( weapon ) && LocalPlayer():Alive() then
		local Ammo = LocalPlayer():GetActiveWeapon():Clip1()
		local MaxA = LocalPlayer():GetActiveWeapon():GetMaxClip1()
		local TotAl = LocalPlayer():GetAmmoCount( weapon:GetSecondaryAmmoType() )

		draw.RoundedBox(0,ScrW() - 130,ScrH() - 130,115,115,Color(0,0,0,200)) -- Total ammo is being worked on
		draw.DrawText("Ammo","Trebuchet18",ScrW() - 120,ScrH() - 120,Color(255,255,255,255), TEXT_ALIGN_LEFT)

		draw.DrawText(Ammo,"CloseCaption_Normal",ScrW() - 100,ScrH() - 100,Color(255,255,255,255), TEXT_ALIGN_LEFT)
		draw.DrawText("/","DermaLarge",ScrW() - 80,ScrH() - 90,Color(255,255,255,255), TEXT_ALIGN_LEFT)
		draw.DrawText(MaxA,"CloseCaption_Normal",ScrW() - 70,ScrH() - 80,Color(255,255,255,255), TEXT_ALIGN_LEFT)
		draw.DrawText("Alt : "..TotAl,"Trebuchet18",ScrW() - 120,ScrH() - 35,Color(255,255,255,255), TEXT_ALIGN_LEFT)
	end
end

--[[------------[[
	   Load
--]]------------]]
local function MAFStart()
	Base()
	mHealth()
	mArmor()
	Ammo()
	plyS()
end
hook.Add("HUDPaint", "drawDMAF", MAFStart )


funny how you mention easy localization, but you have an unnecessary generic global named C

also why in the world are you overriding mHealth and mArmor within their own functions? just by looking that quickly you’ll get an arithmetic on function error since you’re passing the function directly instead of a number in Lerp

also what in the world is this abomination


if avataropen == false then
		avataropen = true
		plyM = vgui.Create( "DModelPanel" )
		function plyM:LayoutEntity( Entity ) return end
		plyM:SetModel( ply:GetModel() )
		plyM:SetPos( 0, ScrH() - 295 )
		plyM:SetSize( 135, 170 )
		plyM:SetCamPos( MAF.CamV )
		plyM:SetLookAt( MAF.LookV )
		timer.Create( "check4change", 0.5, 0, function()
			if ply:GetModel() ~= plyM.Entity:GetModel() then
				plyM:Remove()
				plyM = vgui.Create( "DModelPanel" )
				function plyM:LayoutEntity( Entity ) return end
				plyM:SetModel( ply:GetModel() )
				plyM:SetPos( 0, ScrH() - 295 )
				plyM:SetSize( 145, 170 )
				plyM:SetCamPos( MAF.CamV )
				plyM:SetLookAt( MAF.LookV )
			end
		end )
	end
end

why not just change the model instead of reinitializing the entire panel?

It’s like he’s over-complicated the process for no given reason whatsoever.

Yeah I know, like I said this is from my own HUD I made. I just took some parts out giving a example.

[editline]8th December 2016[/editline]

Like you left out of the code, it said “This right here could use some fixing, may come in future updates. Don’t criticize!”

But you state some good points I will work on! Thanks

as a general rule of thumb, don’t be naive enough to post here actually expecting people to be kind enough to spare you criticism when you have something absolutely terrible and non-functional.

Now I understand, yes, there are some horrid parts, but this was a mere concept and a WIP. No reason to go around saying it’s non-functional and terrible. I love the “suggestions”, I truly do! I just want you to understand I didn’t intend it to look so trashy, I was just trying to show maybe some new people how to make a HUD, they could at least pick up some information like how you can local function them, then put them all into one function and hook it. But if you feel different on it, tell me instead of saying I made true garbage. Thanks

You want to show new people how to do things, but if so do it right. This is not the way they should learn, as they’ll learn wrong.

You are very true, I was hoping for too much. I was hoping people would understand it’s a WIP and also pick up some new information, I will get straight to fixing this nightmare by fully restarting, as before I just sorta “stripped” my old HUD.

No Mafia 3 here than :v: