• Nook Retro HUD
    20 replies, posted
Hey! My name is Nookyava and I just recently started coding in the past three weeks. I've worked on small things and odd jobs, but I coded a HUD that works both for TTT and Sandbox. I was hoping to post it here and get some critiques or ideas of what I can do better. I'm also going to post the code so you can see how horribly optimized and setup it is. [video]http://youtube.com/watch?v=6f5DywNEKFc[/video] [b]Screenshot showing TTT version of the HUD.[/b] [t]http://cloud-3.steampowered.com/ugc/920146124959934177/371460ABBAF9D4991C26E9E5908B97B214FCD852/637x358.resizedimage[/t] [b]Screenshot showing the gamemode selection part of the HUD, as well as Sandbox.[/b] [t]http://cloud-4.steampowered.com/ugc/920146125007828174/18D30E1EA19AAF04E8B3F50FD739B2868D706AFC/637x358.resizedimage[/t] [b]cl_hud.lua[/b] [CODE]--------------------------------- ----- This is the Menu part ----- --------------------------------- function TestVGUI( ) if LocalPlayer():IsSuperAdmin() then local NookMenu = vgui.Create( "DFrame" ) NookMenu:SetSize( 500, 75 ) NookMenu:SetPos( ScrW()/2 - 200, ScrH()/2 - 100 ) NookMenu:ShowCloseButton( true ) NookMenu:SetVisible( true ) NookMenu:MakePopup( ) NookMenu:SetTitle( "Nookyava's Retro Hud Settings" ) local Sandbox = vgui.Create( "Button", NookMenu ) Sandbox:SetText( "Sandbox" ) Sandbox:SetPos( 25, 35 ) Sandbox:SetWide( 100 ) function Sandbox:DoClick( ) self:SetText( "Sandbox Mode Set" ) timer.Simple( 0.5, function() self:SetText( "Sandbox" ) end) net.Start( "Gamemode Setting" ) net.WriteDouble( 0 ) net.SendToServer() end local DarkRP = vgui.Create( "Button", NookMenu ) DarkRP:SetText( "DarkRP" ) DarkRP:SetPos( 200, 35 ) DarkRP:SetWide( 100 ) function DarkRP:DoClick( ) --self:SetText( "DarkRP Mode Set" ) --timer.Simple( 3, function() -- self:SetText( "DarkRP" ) --end) LocalPlayer():ChatPrint("DarkRP Mode has not been created yet, thank you for your interest though!") end local TTT = vgui.Create( "Button", NookMenu ) TTT:SetText( "TTT" ) TTT:SetPos( 375, 35 ) TTT:SetWide( 100 ) function TTT:DoClick( ) self:SetText( "TTT Mode Set" ) timer.Simple( 0.5, function() self:SetText( "TTT" ) end) net.Start( "Gamemode Setting" ) net.WriteDouble( 1 ) net.SendToServer() end else return end end concommand.Add("nookhud", TestVGUI) ---------------------------------------------- -- This is just setting up the materials. -- -- Thank you [find me] for the suggestion! -- ---------------------------------------------- HeartMat = {} HeartMat[10] = Material("nook/heart_hud/horizontal_heart/full.png") HeartMat[9] = Material("nook/heart_hud/horizontal_heart/hurt_once.png") HeartMat[8] = Material("nook/heart_hud/horizontal_heart/hurt_twice.png") HeartMat[7] = Material("nook/heart_hud/horizontal_heart/hurt_thrice.png") HeartMat[6] = Material("nook/heart_hud/horizontal_heart/hurt_four.png") HeartMat[5] = Material("nook/heart_hud/horizontal_heart/hurt_five.png") HeartMat[4] = Material("nook/heart_hud/horizontal_heart/hurt_six.png") HeartMat[3] = Material("nook/heart_hud/horizontal_heart/hurt_seven.png") HeartMat[2] = Material("nook/heart_hud/horizontal_heart/hurt_eight.png") HeartMat[1] = Material("nook/heart_hud/horizontal_heart/hurt_nine.png") HeartMat[0] = Material("nook/heart_hud/horizontal_heart/hurt_ten.png") ArmorMat = {} ArmorMat[10] = Material("nook/heart_hud/shield/full.png") ArmorMat[9] = Material("nook/heart_hud/shield/hurt_once.png") ArmorMat[8] = Material("nook/heart_hud/shield/hurt_twice.png") ArmorMat[7] = Material("nook/heart_hud/shield/hurt_thrice.png") ArmorMat[6] = Material("nook/heart_hud/shield/hurt_four.png") ArmorMat[5] = Material("nook/heart_hud/shield/hurt_five.png") ArmorMat[4] = Material("nook/heart_hud/shield/hurt_six.png") ArmorMat[3] = Material("nook/heart_hud/shield/hurt_seven.png") ArmorMat[2] = Material("nook/heart_hud/shield/hurt_eight.png") ArmorMat[1] = Material("nook/heart_hud/shield/hurt_nine.png") ArmorMat[0] = Material("nook/heart_hud/shield/hurt_ten.png") local PistolAmmo = Material("nook/heart_hud/ammo/pistol.png") local ShotgunAmmo = Material("nook/heart_hud/ammo/shotgun.png") local SMGAmmo = Material("nook/heart_hud/ammo/smg.png") local RifleAmmo = Material("nook/heart_hud/ammo/rifle.png") ------------------------------- -- This is creating the text -- ------------------------------- surface.CreateFont( "HeartText", { font = "MenuLarge", size = 25, weight = 500, blursize = 0, scanlines = 0, antialias = false, underline = false, italic = false, strikeout = false, symbol = false, rotary = false, shadow = true, additive = false, outline = true } ) surface.CreateFont( "WeaponText", { font = "TitleFont", size = 25, weight = 500, blursize = 0, scanlines = 0, antialias = false, underline = false, italic = false, strikeout = false, symbol = false, rotary = false, shadow = true, additive = false, outline = true } ) surface.CreateFont( "RoleText", { font = "TargetID", size = 25, weight = 500, blursize = 0, scanlines = 0, antialias = false, underline = false, italic = false, strikeout = false, symbol = false, rotary = false, shadow = true, additive = false, outline = false } ) surface.CreateFont( "ClockText", { font = "HUDNumber", size = 35, weight = 500, blursize = 0, scanlines = 0, antialias = false, underline = false, italic = false, strikeout = false, symbol = false, rotary = false, shadow = true, additive = false, outline = true } ) ------------------------------ -- This is creating our HUD -- ------------------------------ local function HealthHud() if !LocalPlayer():Alive() then return end if LocalPlayer():Team() == TEAM_SPEC then return end local health = LocalPlayer():Health() local Health_Increment = math.Round( health/10 ) local Width = 203 local Height = 203 surface.SetDrawColor(255,255,255,255) surface.SetMaterial( HeartMat[Health_Increment] ) surface.DrawTexturedRect(0, ScrH() - Height + 25, Width, Height ) draw.DrawText( health, "HeartText", 102, ScrH() - Height + 110, Color( 255, 255, 255, 255), TEXT_ALIGN_CENTER) end hook.Add("HUDPaint", "HeartHUD", HealthHud) local function ArmorHud() if !LocalPlayer():Alive() then return end if LocalPlayer():Team() == TEAM_SPEC then return end local armor = LocalPlayer():Armor() local Armor_Increment = math.Round( armor/10 ) local Width = 110 local Height = 120 surface.SetDrawColor(255,255,255,255) if GetConVar("NookHUD_Gamemode"):GetInt() == 0 then surface.SetMaterial( ArmorMat[Armor_Increment] ) surface.DrawTexturedRect(200, ScrH() - Height - 15, Width, Height ) draw.DrawText( armor, "HeartText", 255, ScrH() - Height + 27, Color( 255, 255, 255, 255), TEXT_ALIGN_CENTER) elseif GetConVar("NookHUD_Gamemode"):GetInt() == 1 then if LocalPlayer():HasEquipmentItem(EQUIP_ARMOR) then surface.SetMaterial( ArmorMat[10] ) surface.DrawTexturedRect(200, ScrH() - Height - 25, Width, Height ) elseif !LocalPlayer():HasEquipmentItem(EQUIP_ARMOR) then surface.SetDrawColor(255,255,255,55) surface.SetMaterial( ArmorMat[0] ) surface.DrawTexturedRect(200, ScrH() - Height - 25, Width, Height ) end end end hook.Add("HUDPaint", "ShieldHUD", ArmorHud) local function AmmoHud() if !LocalPlayer():Alive() then return end if GetConVar("NookHUD_Gamemode"):GetInt() == 1 then -- This is the TTT config at the top. if !LocalPlayer():IsTerror() then return end end weapon = LocalPlayer():GetActiveWeapon() ammo = IsValid( weapon ) and LocalPlayer():GetActiveWeapon():Clip1() ammo2 = IsValid( weapon ) and LocalPlayer():GetAmmoCount(LocalPlayer():GetActive Weapon():GetPrimaryAmmoType()) ammo3 = IsValid( weapon ) and LocalPlayer():GetActiveWeapon():GetPrimaryAmmoType () --print(ammo3) if ammo == nil then return end -- These are to prevent a small error that will appear on death in TTT. :IsA
Love it
I think it is very ugly
[QUOTE=Snorlaxs;41987148]I think it is very ugly[/QUOTE] Could you please tell me what about it is ugly, and what could be improved then please?
Sweet :3.. It Looks really cool :D. I tried it out on my TTT server, and i think i installed it correcly but im getting this error: [code][ERROR] gamemodes/terrortown/gamemode/cl_hud.lua:291: function arguments expecte d near 'Weapon' 1. unknown - gamemodes/terrortown/gamemode/cl_hud.lua:0[/code] But maybe I installed it incorrecly? So maybe could you give a guide on how you install? Thanks and nice work :P
Really love the health and armor. As for the ammo and time displays, they're a bit bland.
[QUOTE=code_gs;41987270]Really love the health and armor. As for the ammo and time displays, they're a bit bland.[/QUOTE] Yea, I was trying to work in an 8-bit version but no luck so far. [QUOTE]Sweet :3.. It Looks really cool :D. I tried it out on my TTT server, and i think i installed it correcly but im getting this error: [ERROR] gamemodes/terrortown/gamemode/cl_hud.lua:291: function arguments expecte d near 'Weapon' 1. unknown - gamemodes/terrortown/gamemode/cl_hud.lua:0 But maybe I installed it incorrecly? So maybe could you give a guide on how you install? Thanks and nice work :P[/QUOTE] I probably should have mentioned it's an addon, so running it in as the actual HUD will cause errors. Revert the cl_hud.lua to the original of TTT, and put these in an addon. I'll put in a download of the addon as well as a link to the workshop.
Why do you have pictures for everything? You could simply draw it and it would reduce the files to download.. I personally hate this minecrafty-pixel thing - but it is nicely coded.
[QUOTE=freakyy;41987357]Why do you have pictures for everything? You could simply draw it and it would reduce the files to download.. I personally hate this minecrafty-pixel thing - but it is nicely coded.[/QUOTE] I use the pictures since I didn't exactly see a way to have the heart filled with the box without having to put multiple boxes for one part. In the future I might fix that though.
Where's the problem with multiple boxes?
[QUOTE=freakyy;41987420]Where's the problem with multiple boxes?[/QUOTE] There isn't an issue I suppose, looking at it now. I'll look into it.
Nope there is no issue :)
[QUOTE=freakyy;41987509]Nope there is no issue :)[/QUOTE] Thank you for the suggestion. I'll post an update soon with less downloads with the heart being drawn primarily by boxes.
Idea, focus on tables more as they can do wonders for your "horribly optimized code". By the way it's not horrible, just basic. Here's an example of a really useful table use in your code. [lua] local Heart100 = Material("nook/heart_hud/horizontal_heart/full.png") local Heart90 = Material("nook/heart_hud/horizontal_heart/hurt_once.png") local Heart80 = Material("nook/heart_hud/horizontal_heart/hurt_twice.png") local Heart70 = Material("nook/heart_hud/horizontal_heart/hurt_thrice.png") local Heart60 = Material("nook/heart_hud/horizontal_heart/hurt_four.png") local Heart50 = Material("nook/heart_hud/horizontal_heart/hurt_five.png") local Heart40 = Material("nook/heart_hud/horizontal_heart/hurt_six.png") local Heart30 = Material("nook/heart_hud/horizontal_heart/hurt_seven.png") local Heart20 = Material("nook/heart_hud/horizontal_heart/hurt_eight.png") local Heart10 = Material("nook/heart_hud/horizontal_heart/hurt_nine.png") local Heart0 = Material("nook/heart_hud/horizontal_heart/hurt_ten.png") ---- if health >= 100 then surface.SetMaterial( Heart100 ) surface.DrawTexturedRect(0, ScrH() - Height + 25, Width, Height ) draw.DrawText( health, "HeartText", 102, ScrH() - Height + 110, Color( 255, 255, 255, 255), TEXT_ALIGN_CENTER) elseif health >= 90 then surface.SetMaterial( Heart90 ) surface.DrawTexturedRect(0, ScrH() - Height + 25, Width, Height ) draw.DrawText( health, "HeartText", 102, ScrH() - Height + 110, Color( 255, 255, 255, 255), TEXT_ALIGN_CENTER) elseif health >= 80 then surface.SetMaterial( Heart80 ) surface.DrawTexturedRect(0, ScrH() - Height + 25, Width, Height ) draw.DrawText( health, "HeartText", 102, ScrH() - Height + 110, Color( 255, 255, 255, 255), TEXT_ALIGN_CENTER) elseif health >= 70 then surface.SetMaterial( Heart70 ) surface.DrawTexturedRect(0, ScrH() - Height + 25, Width, Height ) draw.DrawText( health, "HeartText", 102, ScrH() - Height + 110, Color( 255, 255, 255, 255), TEXT_ALIGN_CENTER) elseif health >= 60 then surface.SetMaterial( Heart60 ) surface.DrawTexturedRect(0, ScrH() - Height + 25, Width, Height ) draw.DrawText( health, "HeartText", 102, ScrH() - Height + 110, Color( 255, 255, 255, 255), TEXT_ALIGN_CENTER) elseif health >= 50 then surface.SetMaterial( Heart50 ) surface.DrawTexturedRect(0, ScrH() - Height + 25, Width, Height ) draw.DrawText( health, "HeartText", 102, ScrH() - Height + 110, Color( 255, 255, 255, 255), TEXT_ALIGN_CENTER) elseif health >= 40 then surface.SetMaterial( Heart40 ) surface.DrawTexturedRect(0, ScrH() - Height + 25, Width, Height ) draw.DrawText( health, "HeartText", 102, ScrH() - Height + 110, Color( 255, 255, 255, 255), TEXT_ALIGN_CENTER) elseif health >= 30 then surface.SetMaterial( Heart30 ) surface.DrawTexturedRect(0, ScrH() - Height + 25, Width, Height ) draw.DrawText( health, "HeartText", 102, ScrH() - Height + 110, Color( 255, 255, 255, 255), TEXT_ALIGN_CENTER) elseif health >= 20 then surface.SetMaterial( Heart20 ) surface.DrawTexturedRect(0, ScrH() - Height + 25, Width, Height ) draw.DrawText( health, "HeartText", 102, ScrH() - Height + 110, Color( 255, 255, 255, 255), TEXT_ALIGN_CENTER) elseif health >= 10 || health >= 1 then surface.SetMaterial( Heart10 ) surface.DrawTexturedRect(0, ScrH() - Height + 25, Width, Height ) draw.DrawText( health, "HeartText", 102, ScrH() - Height + 110, Color( 255, 255, 255, 255), TEXT_ALIGN_CENTER) elseif health == 0 then surface.SetMaterial( Heart0 ) surface.DrawTexturedRect(0, ScrH() - Height + 25, Width, Height ) end [/lua] [B][U]TO THIS[/U][/B] [lua] Materials = {} Materials[10] = Material("nook/heart_hud/horizontal_heart/full.png") Materials[9] = Material("nook/heart_hud/horizontal_heart/hurt_once.png") Materials[8] = Material("nook/heart_hud/horizontal_heart/hurt_twice.png") Materials[7] = Material("nook/heart_hud/horizontal_heart/hurt_thrice.png") Materials[6] = Material("nook/heart_hud/horizontal_heart/hurt_four.png") Materials[5] = Material("nook/heart_hud/horizontal_heart/hurt_five.png") Materials[4] = Material("nook/heart_hud/horizontal_heart/hurt_six.png") Materials[3] = Material("nook/heart_hud/horizontal_heart/hurt_seven.png") Materials[2] = Material("nook/heart_hud/horizontal_heart/hurt_eight.png") Materials[1] = Material("nook/heart_hud/horizontal_heart/hurt_nine.png") Materials[0] = Material("nook/heart_hud/horizontal_heart/hurt_ten.png") local Health_Increment = math.Round( health/10 ) surface.SetMaterial( Materials[Health_Increment] ) surface.DrawTexturedRect(0, ScrH() - Height + 25, Width, Height ) draw.DrawText( health, "HeartText", 102, ScrH() - Height + 110, Color( 255, 255, 255, 255), TEXT_ALIGN_CENTER) [/lua]
Yeah I was going to say the code is very ugly. You should have used [URL="http://wiki.garrysmod.com/page/render/SetScissorRect"]render.SetScrissorRect[/URL] for the health code.
[QUOTE=freakyy;41987357]I personally hate this minecrafty-pixel thing - but it is nicely coded.[/QUOTE] Minecraft wasn't the first game to utilize pixels. Infiniminer is a thing, you know.
[QUOTE=NightmareX91;41991152]Minecraft wasn't the first game to utilize pixels. Infiniminer is a thing, you know.[/QUOTE] I don't think I have played a game without pixels before and the thing is that minecraft popularized voxel based games or is at least the most popular voxel based game today. So making a reference to minecraft would allow for more people to understand what he was saying than if he instead said "this Infiniminer-pixel thing". Anyways, I like the HUD and thank you for releasing it.
It's a nice HUD, but my previous comment on it I still think you should do. (It was to make the shield the same size as the heart)
[QUOTE=find me;41989870]Idea, focus on tables more as they can do wonders for your "horribly optimized code". By the way it's not horrible, just basic. Here's an example of a really useful table use in your code. [lua] local Heart100 = Material("nook/heart_hud/horizontal_heart/full.png") local Heart90 = Material("nook/heart_hud/horizontal_heart/hurt_once.png") local Heart80 = Material("nook/heart_hud/horizontal_heart/hurt_twice.png") local Heart70 = Material("nook/heart_hud/horizontal_heart/hurt_thrice.png") local Heart60 = Material("nook/heart_hud/horizontal_heart/hurt_four.png") local Heart50 = Material("nook/heart_hud/horizontal_heart/hurt_five.png") local Heart40 = Material("nook/heart_hud/horizontal_heart/hurt_six.png") local Heart30 = Material("nook/heart_hud/horizontal_heart/hurt_seven.png") local Heart20 = Material("nook/heart_hud/horizontal_heart/hurt_eight.png") local Heart10 = Material("nook/heart_hud/horizontal_heart/hurt_nine.png") local Heart0 = Material("nook/heart_hud/horizontal_heart/hurt_ten.png") ---- if health >= 100 then surface.SetMaterial( Heart100 ) surface.DrawTexturedRect(0, ScrH() - Height + 25, Width, Height ) draw.DrawText( health, "HeartText", 102, ScrH() - Height + 110, Color( 255, 255, 255, 255), TEXT_ALIGN_CENTER) elseif health >= 90 then surface.SetMaterial( Heart90 ) surface.DrawTexturedRect(0, ScrH() - Height + 25, Width, Height ) draw.DrawText( health, "HeartText", 102, ScrH() - Height + 110, Color( 255, 255, 255, 255), TEXT_ALIGN_CENTER) elseif health >= 80 then surface.SetMaterial( Heart80 ) surface.DrawTexturedRect(0, ScrH() - Height + 25, Width, Height ) draw.DrawText( health, "HeartText", 102, ScrH() - Height + 110, Color( 255, 255, 255, 255), TEXT_ALIGN_CENTER) elseif health >= 70 then surface.SetMaterial( Heart70 ) surface.DrawTexturedRect(0, ScrH() - Height + 25, Width, Height ) draw.DrawText( health, "HeartText", 102, ScrH() - Height + 110, Color( 255, 255, 255, 255), TEXT_ALIGN_CENTER) elseif health >= 60 then surface.SetMaterial( Heart60 ) surface.DrawTexturedRect(0, ScrH() - Height + 25, Width, Height ) draw.DrawText( health, "HeartText", 102, ScrH() - Height + 110, Color( 255, 255, 255, 255), TEXT_ALIGN_CENTER) elseif health >= 50 then surface.SetMaterial( Heart50 ) surface.DrawTexturedRect(0, ScrH() - Height + 25, Width, Height ) draw.DrawText( health, "HeartText", 102, ScrH() - Height + 110, Color( 255, 255, 255, 255), TEXT_ALIGN_CENTER) elseif health >= 40 then surface.SetMaterial( Heart40 ) surface.DrawTexturedRect(0, ScrH() - Height + 25, Width, Height ) draw.DrawText( health, "HeartText", 102, ScrH() - Height + 110, Color( 255, 255, 255, 255), TEXT_ALIGN_CENTER) elseif health >= 30 then surface.SetMaterial( Heart30 ) surface.DrawTexturedRect(0, ScrH() - Height + 25, Width, Height ) draw.DrawText( health, "HeartText", 102, ScrH() - Height + 110, Color( 255, 255, 255, 255), TEXT_ALIGN_CENTER) elseif health >= 20 then surface.SetMaterial( Heart20 ) surface.DrawTexturedRect(0, ScrH() - Height + 25, Width, Height ) draw.DrawText( health, "HeartText", 102, ScrH() - Height + 110, Color( 255, 255, 255, 255), TEXT_ALIGN_CENTER) elseif health >= 10 || health >= 1 then surface.SetMaterial( Heart10 ) surface.DrawTexturedRect(0, ScrH() - Height + 25, Width, Height ) draw.DrawText( health, "HeartText", 102, ScrH() - Height + 110, Color( 255, 255, 255, 255), TEXT_ALIGN_CENTER) elseif health == 0 then surface.SetMaterial( Heart0 ) surface.DrawTexturedRect(0, ScrH() - Height + 25, Width, Height ) end [/lua] [B][U]TO THIS[/U][/B] [lua] Materials = {} Materials[10] = Material("nook/heart_hud/horizontal_heart/full.png") Materials[9] = Material("nook/heart_hud/horizontal_heart/hurt_once.png") Materials[8] = Material("nook/heart_hud/horizontal_heart/hurt_twice.png") Materials[7] = Material("nook/heart_hud/horizontal_heart/hurt_thrice.png") Materials[6] = Material("nook/heart_hud/horizontal_heart/hurt_four.png") Materials[5] = Material("nook/heart_hud/horizontal_heart/hurt_five.png") Materials[4] = Material("nook/heart_hud/horizontal_heart/hurt_six.png") Materials[3] = Material("nook/heart_hud/horizontal_heart/hurt_seven.png") Materials[2] = Material("nook/heart_hud/horizontal_heart/hurt_eight.png") Materials[1] = Material("nook/heart_hud/horizontal_heart/hurt_nine.png") Materials[0] = Material("nook/heart_hud/horizontal_heart/hurt_ten.png") local Health_Increment = math.Round( health/10 ) surface.SetMaterial( Materials[Health_Increment] ) surface.DrawTexturedRect(0, ScrH() - Height + 25, Width, Height ) draw.DrawText( health, "HeartText", 102, ScrH() - Height + 110, Color( 255, 255, 255, 255), TEXT_ALIGN_CENTER) [/lua][/QUOTE] Thank you, I'll make sure to try and compact the code more, this will help a lot. Hopefully it will be using less downloads anyway. [QUOTE]Yeah I was going to say the code is very ugly. You should have used render.SetScrissorRect for the health code.[/QUOTE] I'll take that into effect when coding it, thank you.
Updated cl_hud.lua to Find Me's suggestions. Thanks a lot! Also made the shield the same size as the heart.
This is starting to look alot better from when it was first posted well done!!
Sorry, you need to Log In to post a reply to this thread.