• Help Coding a Custom TTT HUD?
    7 replies, posted
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. [URL="http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index1064.html"]Here's another[/URL]
[QUOTE=Aeternal;44835253]coderhire.com is one resource. [URL="http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index1064.html"]Here's another[/URL][/QUOTE] 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
[QUOTE]Thanks to anyone and everyone who tries and help![/QUOTE] I tried and I helped. I gave you two resources. Where's my "Thanks"? [editline]17th May 2014[/editline] [URL="http://facepunch.com/showthread.php?t=1244977&p=39476645&viewfull=1#post39476645"]Another resource for you.[/URL]
[QUOTE=Aeternal;44835320]I tried and I helped. I gave you two resources. Where's my "Thanks"? [editline]17th May 2014[/editline] [URL="http://facepunch.com/showthread.php?t=1244977&p=39476645&viewfull=1#post39476645"]Another resource for you.[/URL][/QUOTE] 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())
[QUOTE=brandonj4;44835356]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())[/QUOTE] Thanks, what I'm currently doing my self if using [code] function HUD() local ply = LocalPlayer() local HP = LocalPlayer():Health() end [/code] and just writing the variable names in fact here is my previous code, using the recent HUD drawing tutorial just posted :P [code] 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 [/code]
[QUOTE=leyshadow;44835378]-snip-[/QUOTE] 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() [code] -- 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
Sorry, you need to Log In to post a reply to this thread.