Help Coding a Custom TTT HUD?

Hello there guys! I have a custom HUD I am trying to code for my TTT server, however, I am having a lot of trouble. I need someone who can help me through this. If possible, could you pm me and add me on steam, or join into my mumble server and talk or guide us through? Thanks to anyone who tries and help! I have a screenshot of what the HUD will look like, and very basic knowledge of drawing things to the screen. If anyone helps I would be so appreciative!

coderhire.com is one resource.
Here’s another

Ok that is 5 years old, do those functions need porting or should that adequately work for what i’m trying to do? I don’t want to
pay anyone as I can code, it just takes time to learn a new part of coding, especially visual stuff. It’s much easier with a guide, no doubt

I tried and I helped. I gave you two resources. Where’s my “Thanks”?

[editline]17th May 2014[/editline]

Another resource for you.

I’m not sure if you actually read what that person posted but that isn’t a very good resource if they made a variable for a function call and later on used that function directly anyway. (LocalPlayer())

Thanks, what I’m currently doing my self if using


 

function HUD()

local ply = LocalPlayer()
local HP = LocalPlayer():Health()

end


and just writing the variable names

in fact here is my previous code, using the recent HUD drawing tutorial just posted :stuck_out_tongue:





function HUDHide(oldHUD)
	for	k, v in pairs{"CHudHealth", "CHUDBattery"} do
		
		if oldHUD == v 
		then return false end
			
	end

end

hook.Add("HUDShouldDraw","HUDHide",HUDHide)

local gradient = surface.GetTextureID( "gui/gradient.vtf" )




function GM:HUDPaint()
	
	KryptonHud()

	
end 


function KryptonHud()

	local ply = LocalPlayer()
	local HP = LocalPlayer:Health()
	local ARM = LocalPlayer:Armor()
	

surface.SetDrawColor(color(255, 255, 255, 200))
surface.SetTexture(gradient)
surface.DrawTexturedRect(0, ScrH() - 50, 300, 50)
draw.DrawText(HP .. " HP", "HudHintTextLarge",5, ScrH() -40, color(255, 0, 0, 220 )

end



You completely misunderstood what I meant.

This:
[lua]
local ply = LocalPlayer()
local HP = LocalPlayer():Health()
[/lua]

Should look like this:
[lua]
local ply = LocalPlayer()
local HP = ply:Health()
[/lua]

You were also missing () on your LocalPlayer

Hello, I currently have this code…it worked once but now it says that line 15 (which is ply:Health() is a Nul or Nil) Now, it simply loads the original HUD like with orange and black, with no custom hud, and says that line 15 is a Null value, which is ply:Health()



-- 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

local ply = LocalPlayer()
local HP = ply:Health()
local ARM = ply:Armor()
if !IsValid(weap) or not ply:Alive() then return -1 end
local weap = ply:GetActiveWeapon()

local is_alive = ply:Alive() and (ply.IsSpec and not ply:IsSpec())
-- 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)
};




--This builds are sizable fonts, much thanks to WYOZI!!!
WHBFontCache = WHBFontCache or {}
do
	if not WHBFontCache["WHBHelvetica28"] then
		surface.CreateFont( "WHBHelvetica28", {
			font = system.IsOSX() and [[Helvetica]] or [[Tahoma]],
			size = 34,
		})
		WHBFontCache["WHBHelvetica28"] = true
	end
	if not WHBFontCache["WHBHelvetica24"] then
		surface.CreateFont( "WHBHelvetica24", {
			font = system.IsOSX() and [[Helvetica]] or [[Tahoma]],
			size = 30,
		})
		WHBFontCache["WHBHelvetica24"] = true
	end
	if not WHBFontCache["WHBHelvetica42"] then
		surface.CreateFont( "WHBHelvetica42", {
			font = system.IsOSX() and [[Helvetica]] or [[Tahoma]],
			size = 48,
		})
		WHBFontCache["WHBHelvetica42"] = true
	end
	if not WHBFontCache["WHBHelvetica36"] then
		surface.CreateFont( "WHBHelvetica36", {
			font = system.IsOSX() and [[Helvetica]] or [[Tahoma]],
			size = 42,
		})
		WHBFontCache["WHBHelvetica36"] = true
	end
	if not WHBFontCache["WHBHelvetica30"] then
		surface.CreateFont( "WHBHelvetica30", {
			font = system.IsOSX() and [[Helvetica]] or [[Tahoma]],
			size = 36,
		})
		WHBFontCache["WHBHelvetica30"] = true
	end
	if not WHBFontCache["WHBHelvetica36"] then
		surface.CreateFont( "WHBHelvetica36", {
			font = system.IsOSX() and [[Helvetica]] or [[Tahoma]],
			size = 42,
		})
		WHBFontCache["WHBHelvetica36"] = true
	end
	if not WHBFontCache["WHBHelvetica30"] then
		surface.CreateFont( "WHBHelvetica30", {
			font = system.IsOSX() and [[Helvetica]] or [[Tahoma]],
			size = 36,
		})
		WHBFontCache["WHBHelvetica30"] = true
	end
	if not WHBFontCache["WHBHelvetica24"] then
		surface.CreateFont( "WHBHelvetica24", {
			font = system.IsOSX() and [[Helvetica]] or [[Tahoma]],
			size = 30,
		})
		WHBFontCache["WHBHelvetica24"] = true
	end
end




function HUDHide(oldHUD)
	for	k, v in pairs{"CHudHealth", "CHUDBattery"} do
		
		if oldHUD == v 
		then return false end
			
	end

end

hook.Add("HUDShouldDraw","HUDHide",HUDHide)

local gradient = surface.GetTextureID( "gui/gradient.vtf" )




function GM:HUDPaint()
	
	KryptonHud()

	
end 


function KryptonHud()



surface.SetDrawColor(Color(7, 7, 7, 200))
surface.SetTexture(gradient)
draw.RoundedBox(6, 0, ScrH()-196, 473, 173, Color(5, 5, 5, 216) ) --6 is roundness, 3 is x, ScrH is y, 473 is width, 173 is height THIS is our black box
draw.RoundedBox(6, 272, ScrH()-197, 203, 83, Color(191, 189, 189, 255))
draw.DrawText(HP .. " HP", "HudHintTextLarge",5, ScrH() -40, Color(255, 0, 0, 220))


do -- This draws in the round state into our gray box!
	local x, y = 291, ScrH() - 189
	
	
	--[[Data variables]]
	local ttt_round_state = "[not ttt]" -- Display This if NOT playing TTT
	if ROUND_WAIT then
		local roundstate_string = { -- table of possible round states
			[ROUND_WAIT] = "round_wait", [ROUND_PREP] = "round_prep",  
			[ROUND_ACTIVE] = "round_active", [ROUND_POST] = "round_post"
		}
		ttt_round_state = LANG.GetTranslation( roundstate_string[GAMEMODE.round_state] ) -- check our table to see if it matches, then translate to text
	end
	
	surface.SetTextColor(244, 238, 238, 255) -- white basically, color of the state
	surface.SetTextPos(x, y)
	surface.SetFont("WHBHelvetica28")
	surface.DrawText([[]] .. ttt_round_state .. [[]])
end

do -- This displays the actual round time left, under the state
	local x, y = 298, ScrH() - 150
	
	
	--[[Data variables]]
	local ttt_round_timer = "not ttt" -- similar, if you're not playing TTT, etc.
	if util and util.SimpleTime then 
		local is_haste = HasteMode() and round_state == ROUND_ACTIVE -- set up the local variables, HasteMode() probably returns true or false
		local endtime = GetGlobalFloat("ttt_round_end", 0) - CurTime() -- determine what time the round ends, etc.
		local is_traitor = LocalPlayer():IsActiveTraitor()
		if is_haste then -- self explained
			local hastetime = GetGlobalFloat("ttt_haste_end", 0) - CurTime()
			if hastetime < 0 then -- if not time expired
				ttt_round_timer = util.SimpleTime(math.max(0, endtime), "%02i:%02i")
			else
				local t = hastetime
				if is_traitor and math.ceil(CurTime()) % 6 < 2 then
					t = endtime
				end
				ttt_round_timer = util.SimpleTime(math.max(0, t), "%02i:%02i")
			end
		else
				ttt_round_timer = util.SimpleTime(math.max(0, endtime), "%02i:%02i")
		end
	end
	
	surface.SetTextColor(249, 246, 246, 255)
	surface.SetTextPos(x, y)
	surface.SetFont("WHBHelvetica24")
	surface.DrawText([[]] .. ttt_round_timer .. [[]])
end


do -- Display the Role of the Player
	local x, y = 55, ScrH() - 171
	
	
	--[[Data variables]]
	local ttt_role, ttt_role_color = "[not ttt]", Color(255, 255, 255)
	if ply.GetRoleString then 
		ttt_role = ply:GetRoleString() -- Will return text of role
		ttt_role_color = COLOR_GREEN -- Set to green if inno
		if ply:GetRole() == ROLE_TRAITOR then ttt_role_color = COLOR_RED end -- red if traitor
		if ply:GetRole() == ROLE_DETECTIVE then ttt_role_color = COLOR_BLUE end
	end
	
	surface.SetTextColor(ttt_role_color)
	surface.SetTextPos(x, y)
	surface.SetFont("WHBHelvetica42")
	surface.DrawText([[]] .. ttt_role .. [[]])
end


do -- draws the red box for health
	local x, y = 0, ScrH() - 115
	local w, h = 476, 48
	
	draw.RoundedBox( 6, x, y, w, h, Color(187, 40, 40, 255) ) 
	draw.RoundedBox( 6, x, y, math.max(w * (ply:Health()/100), 10), h, Color(225, 18, 18, 255) ) 
end

do -- hit points (numerical Value)
	local x, y = 54, ScrH() - 112
	
	surface.SetTextColor(255, 255, 255, 255)
	surface.SetTextPos(x, y)
	surface.SetFont("WHBHelvetica36")
	surface.DrawText([[]] .. LocalPlayer():Health() .. " Health" .. [[]])
end

do -- Draws the Role of the players, self explained
	local x, y = 62, ScrH() - 182
	
	
	--[[Data variables]]
	local ttt_role, ttt_role_color = "[not ttt]", Color(255, 255, 255)
	if ply.GetRoleString then
		ttt_role = ply:GetRoleString()
		ttt_role_color = COLOR_GREEN
		if ply:GetRole() == ROLE_TRAITOR then ttt_role_color = COLOR_RED end
		if ply:GetRole() == ROLE_DETECTIVE then ttt_role_color = COLOR_BLUE end
	end
	
	surface.SetTextColor(ttt_role_color)
	surface.SetTextPos(x, y)
	surface.SetFont("WHBHelvetica42")
	surface.DrawText([[]] .. ttt_role .. [[]])
end


do -- draws the background of the role box
	local x, y = 0, ScrH() - 197
	local w, h = 278, 82
	
	draw.RoundedBox( 4, x, y, w, h, (LocalPlayer().IsActiveTraitor and LocalPlayer():IsActiveTraitor()) and COLOR_RED or ((LocalPlayer().IsActiveDetective and LocalPlayer():IsActiveDetective()) and COLOR_BLUE or Color(0, 255, 0)) ) 
end



do 
	local x, y = 0, ScrH() - 68
	local w, h = 475, 48
	
	local ammo_clip = (not IsValid(weap)) and -1 or (weap.Clip1 and weap:Clip1() or 0)
	local ammo_max = (not IsValid(weap)) and -1 or ((weap.Primary and weap.Primary.ClipSize) or 0)
	
	draw.RoundedBox( 6, x, y, w, h, Color(73, 80, 7, 255) ) 
	draw.RoundedBox( 6, x, y, math.max(w * (ammo_clip / ammo_max), 10), h, Color(199, 209, 8, 255) ) 
end

do
	local x, y = 41, ScrH() - 65
	
	
	--[[Data variables]]
	local ammo_clip = (not IsValid(weap)) and -1 or (weap.Clip1 and weap:Clip1() or 0)
	
	surface.SetTextColor(0, 0, 0, 255)
	surface.SetTextPos(x, y)
	surface.SetFont("WHBHelvetica30")
	surface.DrawText([[]] .. ammo_clip .. [[]])
end
--[[WyoziHudBuilder:text]]
do
	local x, y = 200, ScrH() - 65
	
	surface.SetTextColor(0, 0, 0, 255)
	surface.SetTextPos(x, y)
	surface.SetFont("WHBHelvetica36")
	surface.DrawText([[/]])
end
--[[WyoziHudBuilder:text]]
do
	local x, y = 231, ScrH() - 65
	
	
	--[[Data variables]]
	local ammo_max = (not IsValid(weap)) and -1 or ((weap.Primary and weap.Primary.ClipSize) or 0)
	
	surface.SetTextColor(206, 229, 29, 255)
	surface.SetTextPos(x, y)
	surface.SetFont("WHBHelvetica30")
	surface.DrawText([[]] .. ammo_max .. [[]])
end




end




local sf = surface
local dr = draw


local margin = 10

-- Paint punch-o-meter
local function PunchPaint(ply)
   local L = GetLang()
   local punch = ply: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 = ply: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 key_params = { usekey = Key("+use", "USE") }

local function SpecHUDPaint(ply)
   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(8, x, round_y, width, height, bg_colors.background_main)
   draw.RoundedBox(8, 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 = ply: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) == ply then
      PunchPaint(ply)
   else
      ShadowedText(interp(L.spec_help, key_params), "TabLarge", ScrW() / 2, margin, COLOR_WHITE, TEXT_ALIGN_CENTER)
   end
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