• HUD Coding Help?
    17 replies, posted
Hello! So i was making my first hud and when i added the surface.DrawText the text showed up behind my roundedbox like below [IMG]http://i.imgur.com/igUXgM5.jpg[/IMG] I'm attempting to place the text on top of the box and have another text just below that as well. My cl_init.lua [CODE]/* Clientside Stuff Only Here */ include( 'shared.lua' ) hook.Add( "HUDShouldDraw", "hide hud", function( name ) if ( name == "CHudHealth" or name == "CHudBattery" or name == "CHudAmmo" ) then return false end end) surface.CreateFont( "NameF", { font = "Bebas Neue", size = 40, weight = 100, blursize = 0, scanlines = 0, antialias = true } ) function HealthHUD() local ply = LocalPlayer() surface.SetTextColor( 255, 255, 255, 255 ) surface.SetTextPos( ScrW() - 1500, 735 ) surface.SetFont( "NameF" ) surface.DrawText( ply:Name() ) end hook.Add( "HUDPaint", "HealthHUD", HealthHUD ) function GM:HUDPaint() self.BaseClass:HUDPaint() local ply = LocalPlayer() local wep = LocalPlayer():GetActiveWeapon() local HP = LocalPlayer():Health() local ARM = LocalPlayer():Armor() draw.RoundedBox( 4, 9, ScrH() - 143, 392, 133, Color( 0, 0, 0, 255 ) ) draw.RoundedBox( 4, 10, ScrH() - 142, 390, 132, Color( 38, 38, 38, 255 ) ) draw.RoundedBoxEx( 4, 385 - 156, ScrH() - 142, 170 - 0.3, 80, Color( 54, 54, 54, 255 ), false, true, false, false ) surface.SetDrawColor( 0, 0, 0, 255 ) surface.DrawLine( ScrW() - 1550, ScrH() -11, 50, ScrH() - 62 ) surface.SetDrawColor( 63, 63, 63, 100 ) surface.DrawLine( ScrW() - 1551, ScrH() -11, 49, ScrH() - 62 ) surface.SetDrawColor( 4, 4, 4, 255 ) surface.DrawLine( 10, ScrH() - 62, 400, ScrH() - 62 ) surface.SetDrawColor( 61, 61, 61, 100 ) surface.DrawLine( 10, ScrH() - 61, 400, ScrH() - 61 ) surface.SetDrawColor( 65, 65, 65, 100 ) surface.DrawLine( 11, ScrH() - 142, 398, ScrH() - 142 ) surface.SetDrawColor( 24, 24, 24, 255 ) surface.DrawLine( 385 - 156, ScrH() - 142, 385 - 156, ScrH() - 62 ) surface.SetDrawColor( 65, 65, 65, 50 ) surface.DrawLine( 384 - 156, ScrH() - 142, 384 - 156, ScrH() - 62 ) surface.SetDrawColor( 0, 0, 0, 255 ) surface.DrawLine( 10, ScrH() - 35, 400, ScrH() - 35 ) surface.SetDrawColor( 63, 63, 63, 100 ) surface.DrawLine( 10, ScrH() - 34, 400, ScrH() - 34 ) do local x, y = 20, ScrH() - 55 local w, h = 12, 12 surface.SetMaterial(Material("icon16/heart.png")) surface.SetDrawColor(255, 255, 255) surface.DrawTexturedRect(x, y, w, h) end do local x, y = 20, ScrH() - 30 local w, h = 12, 12 surface.SetMaterial(Material("icon16/shield.png")) surface.SetDrawColor(255, 255, 255) surface.DrawTexturedRect(x, y, w, h) end do local x, y = 231, ScrH() - 142 local w, h = 169, 79 local CamData = {} CamData.angles = Angle(90,LocalPlayer():EyeAngles().yaw,0) CamData.origin = Vector(LocalPlayer():GetPos().X,LocalPlayer():GetPos().Y,950) CamData.x = x CamData.y = y CamData.drawviewmodel = true CamData.w = w CamData.h = h render.RenderView( CamData ) local wastelander = Material("icon16/bullet_black.png") surface.SetMaterial(wastelander) surface.SetDrawColor( 255, 255, 255, 255) surface.DrawTexturedRect(x+w/2-8, y+h/2-8, 16, 16) end end function Factions() local base = vgui.Create( "DFrame" ) local button = vgui.Create( "DButton" ) local button2 = vgui.Create( "DButton" ) base:SetPos( ScrW()/2 - 225, ScrH()/2 - 100 ) base:SetSize( 450, 200 ) base:SetVisible( true ) base:SetTitle( "Join a team!" ) base:SetDraggable( false ) base:ShowCloseButton( true ) base:MakePopup() button:SetParent( base ) button:SetText( "Raiders" ) button:Center() button:SetSize( 40, 60 ) button.DoClick = function() ply:ConCommand( "RAIDFAC" ) end button2:Center() button2:SetParent( base ) button2:SetText( "Base Defenders" ) button2:SetSize( 40, 60 ) button2.DoClick = function() ply:ConCommand( "Defender" ) end end[/CODE] *I have no errors in the coding btw* [URL="http://steamcommunity.com/id/swegggggggg"]If you could add me on this steam profile here![/URL]
Draw the text after you draw the box.
[QUOTE=StonedPenguin;46650579]Draw the text after you draw the box.[/QUOTE] I've tried that but i will again! Inside the function? or in a seperate one? **EDIT** Yeah i moved the function and hook below the HUDPaint and it did not change.
Alright i was able to fix it, new question though. How would i go about creating a blowtorch? (Weapon that is able to destroy props [left click] and is able to repair them [right click] through a swep? Also how would i go about enabling the standard sandbox spawnmenu (Q Button) on my gamemode?
[QUOTE=michaelclaw;46651564]Alright i was able to fix it, new question though. How would i go about creating a blowtorch? (Weapon that is able to destroy props [left click] and is able to repair them [right click] through a swep? Also how would i go about enabling the standard sandbox spawnmenu (Q Button) on my gamemode?[/QUOTE] for your second question, set your derived gamemode to sandbox instead of base
You draw the text before the boxes. It should be; [lua]function GM:HUDPaint() self.BaseClass:HUDPaint() local ply = LocalPlayer() local wep = LocalPlayer():GetActiveWeapon() local HP = LocalPlayer():Health() local ARM = LocalPlayer():Armor() draw.RoundedBox( 4, 9, ScrH() - 143, 392, 133, Color( 0, 0, 0, 255 ) ) draw.RoundedBox( 4, 10, ScrH() - 142, 390, 132, Color( 38, 38, 38, 255 ) ) draw.RoundedBoxEx( 4, 385 - 156, ScrH() - 142, 170 - 0.3, 80, Color( 54, 54, 54, 255 ), false, true, false, false ) surface.SetDrawColor( 0, 0, 0, 255 ) surface.DrawLine( ScrW() - 1550, ScrH() -11, 50, ScrH() - 62 ) surface.SetDrawColor( 63, 63, 63, 100 ) surface.DrawLine( ScrW() - 1551, ScrH() -11, 49, ScrH() - 62 ) surface.SetDrawColor( 4, 4, 4, 255 ) surface.DrawLine( 10, ScrH() - 62, 400, ScrH() - 62 ) surface.SetDrawColor( 61, 61, 61, 100 ) surface.DrawLine( 10, ScrH() - 61, 400, ScrH() - 61 ) surface.SetDrawColor( 65, 65, 65, 100 ) surface.DrawLine( 11, ScrH() - 142, 398, ScrH() - 142 ) surface.SetDrawColor( 24, 24, 24, 255 ) surface.DrawLine( 385 - 156, ScrH() - 142, 385 - 156, ScrH() - 62 ) surface.SetDrawColor( 65, 65, 65, 50 ) surface.DrawLine( 384 - 156, ScrH() - 142, 384 - 156, ScrH() - 62 ) surface.SetDrawColor( 0, 0, 0, 255 ) surface.DrawLine( 10, ScrH() - 35, 400, ScrH() - 35 ) surface.SetDrawColor( 63, 63, 63, 100 ) surface.DrawLine( 10, ScrH() - 34, 400, ScrH() - 34 ) do local x, y = 20, ScrH() - 55 local w, h = 12, 12 surface.SetMaterial(Material("icon16/heart.png")) surface.SetDrawColor(255, 255, 255) surface.DrawTexturedRect(x, y, w, h) end do local x, y = 20, ScrH() - 30 local w, h = 12, 12 surface.SetMaterial(Material("icon16/shield.png")) surface.SetDrawColor(255, 255, 255) surface.DrawTexturedRect(x, y, w, h) end do local x, y = 231, ScrH() - 142 local w, h = 169, 79 local CamData = {} CamData.angles = Angle(90,LocalPlayer():EyeAngles().yaw,0) CamData.origin = Vector(LocalPlayer():GetPos().X,LocalPlayer():GetPos().Y,950) CamData.x = x CamData.y = y CamData.drawviewmodel = true CamData.w = w CamData.h = h render.RenderView( CamData ) local wastelander = Material("icon16/bullet_black.png") surface.SetMaterial(wastelander) surface.SetDrawColor( 255, 255, 255, 255) surface.DrawTexturedRect(x+w/2-8, y+h/2-8, 16, 16) -- TEXT NOW DRAWS AFTER THE BOXES surface.SetTextColor( 255, 255, 255, 255 ) surface.SetTextPos( ScrW() - 1500, 735 ) surface.SetFont( "NameF" ) surface.DrawText( ply:Name() ) end[/lua]
[QUOTE=Author.;46651768]You draw the text before the boxes. It should be; [lua]function GM:HUDPaint() self.BaseClass:HUDPaint() local ply = LocalPlayer() local wep = LocalPlayer():GetActiveWeapon() local HP = LocalPlayer():Health() local ARM = LocalPlayer():Armor() draw.RoundedBox( 4, 9, ScrH() - 143, 392, 133, Color( 0, 0, 0, 255 ) ) draw.RoundedBox( 4, 10, ScrH() - 142, 390, 132, Color( 38, 38, 38, 255 ) ) draw.RoundedBoxEx( 4, 385 - 156, ScrH() - 142, 170 - 0.3, 80, Color( 54, 54, 54, 255 ), false, true, false, false ) surface.SetDrawColor( 0, 0, 0, 255 ) surface.DrawLine( ScrW() - 1550, ScrH() -11, 50, ScrH() - 62 ) surface.SetDrawColor( 63, 63, 63, 100 ) surface.DrawLine( ScrW() - 1551, ScrH() -11, 49, ScrH() - 62 ) surface.SetDrawColor( 4, 4, 4, 255 ) surface.DrawLine( 10, ScrH() - 62, 400, ScrH() - 62 ) surface.SetDrawColor( 61, 61, 61, 100 ) surface.DrawLine( 10, ScrH() - 61, 400, ScrH() - 61 ) surface.SetDrawColor( 65, 65, 65, 100 ) surface.DrawLine( 11, ScrH() - 142, 398, ScrH() - 142 ) surface.SetDrawColor( 24, 24, 24, 255 ) surface.DrawLine( 385 - 156, ScrH() - 142, 385 - 156, ScrH() - 62 ) surface.SetDrawColor( 65, 65, 65, 50 ) surface.DrawLine( 384 - 156, ScrH() - 142, 384 - 156, ScrH() - 62 ) surface.SetDrawColor( 0, 0, 0, 255 ) surface.DrawLine( 10, ScrH() - 35, 400, ScrH() - 35 ) surface.SetDrawColor( 63, 63, 63, 100 ) surface.DrawLine( 10, ScrH() - 34, 400, ScrH() - 34 ) do local x, y = 20, ScrH() - 55 local w, h = 12, 12 surface.SetMaterial(Material("icon16/heart.png")) surface.SetDrawColor(255, 255, 255) surface.DrawTexturedRect(x, y, w, h) end do local x, y = 20, ScrH() - 30 local w, h = 12, 12 surface.SetMaterial(Material("icon16/shield.png")) surface.SetDrawColor(255, 255, 255) surface.DrawTexturedRect(x, y, w, h) end do local x, y = 231, ScrH() - 142 local w, h = 169, 79 local CamData = {} CamData.angles = Angle(90,LocalPlayer():EyeAngles().yaw,0) CamData.origin = Vector(LocalPlayer():GetPos().X,LocalPlayer():GetPos().Y,950) CamData.x = x CamData.y = y CamData.drawviewmodel = true CamData.w = w CamData.h = h render.RenderView( CamData ) local wastelander = Material("icon16/bullet_black.png") surface.SetMaterial(wastelander) surface.SetDrawColor( 255, 255, 255, 255) surface.DrawTexturedRect(x+w/2-8, y+h/2-8, 16, 16) -- TEXT NOW DRAWS AFTER THE BOXES surface.SetTextColor( 255, 255, 255, 255 ) surface.SetTextPos( ScrW() - 1500, 735 ) surface.SetFont( "NameF" ) surface.DrawText( ply:Name() ) end[/lua][/QUOTE] Thank you, i was able to fix it by re-writing the text and i moved it below the function HUDPaint() **Just in case anyone wants to see the new code** [CODE]/* Clientside Stuff Only Here */ include( 'shared.lua' ) hook.Add( "HUDShouldDraw", "hide hud", function( name ) if ( name == "CHudHealth" or name == "CHudBattery" or name == "CHudAmmo" ) then return false end end) surface.CreateFont( "NameF", { font = "Bebas Neue", size = 40, weight = 100, blursize = 0, scanlines = 0, antialias = true } ) surface.CreateFont( "TeamF", { font = "Bebas Neue", size = 55, weight = 100, blursize = 0, scanlines = 0, antialias = true } ) surface.CreateFont( "TeamSF", { font = "Bebas Neue", size = 30, weight = 100, blursize = 0, scanlines = 0, antialias = true } ) /*function HealthHUD() local ply = LocalPlayer() surface.SetTextColor( 255, 255, 255, 255 ) surface.SetTextPos( ScrW() - 1500, 735 ) surface.SetFont( "NameF" ) surface.DrawText( ply:Name() ) end hook.Add( "HUDPaint", "HealthHUD", HealthHUD )*/ function GM:HUDPaint() self.BaseClass:HUDPaint() local ply = LocalPlayer() local wep = LocalPlayer():GetActiveWeapon() local HP = LocalPlayer():Health() local ARM = LocalPlayer():Armor() draw.RoundedBox( 4, 9, ScrH() - 143, 392, 133, Color( 0, 0, 0, 255 ) ) draw.RoundedBox( 4, 10, ScrH() - 142, 390, 132, Color( 38, 38, 38, 255 ) ) draw.RoundedBoxEx( 4, 385 - 156, ScrH() - 142, 170 - 0.3, 80, Color( 54, 54, 54, 255 ), false, true, false, false ) surface.SetDrawColor( 0, 0, 0, 255 ) surface.DrawLine( ScrW() - 1550, ScrH() -11, 50, ScrH() - 62 ) surface.SetDrawColor( 63, 63, 63, 100 ) surface.DrawLine( ScrW() - 1551, ScrH() -11, 49, ScrH() - 62 ) surface.SetDrawColor( 4, 4, 4, 255 ) surface.DrawLine( 10, ScrH() - 62, 400, ScrH() - 62 ) surface.SetDrawColor( 61, 61, 61, 100 ) surface.DrawLine( 10, ScrH() - 61, 400, ScrH() - 61 ) surface.SetDrawColor( 65, 65, 65, 100 ) surface.DrawLine( 11, ScrH() - 142, 398, ScrH() - 142 ) surface.SetDrawColor( 24, 24, 24, 255 ) surface.DrawLine( 385 - 156, ScrH() - 142, 385 - 156, ScrH() - 62 ) -- surface.SetDrawColor( 24, 24, 24, 255 ) -- surface.DrawLine( 385 - 156, ScrH() - 142, 385 - 156, ScrH() - 62 ) surface.SetDrawColor( 65, 65, 65, 50 ) surface.DrawLine( 384 - 156, ScrH() - 142, 384 - 156, ScrH() - 62 ) surface.SetDrawColor( 0, 0, 0, 255 ) surface.DrawLine( 10, ScrH() - 35, 400, ScrH() - 35 ) surface.SetDrawColor( 63, 63, 63, 100 ) surface.DrawLine( 10, ScrH() - 34, 400, ScrH() - 34 ) do local x, y = 20, ScrH() - 55 local w, h = 12, 12 surface.SetMaterial(Material("icon16/heart.png")) surface.SetDrawColor(255, 255, 255) surface.DrawTexturedRect(x, y, w, h) end do local x, y = 20, ScrH() - 30 local w, h = 12, 12 surface.SetMaterial(Material("icon16/shield.png")) surface.SetDrawColor(255, 255, 255) surface.DrawTexturedRect(x, y, w, h) end do local x, y = 231, ScrH() - 142 local w, h = 169, 79 local CamData = {} CamData.angles = Angle(90,LocalPlayer():EyeAngles().yaw,0) CamData.origin = Vector(LocalPlayer():GetPos().X,LocalPlayer():GetPos().Y,950) CamData.x = x CamData.y = y CamData.drawviewmodel = true CamData.w = w CamData.h = h render.RenderView( CamData ) local wastelander = Material("icon16/bullet_black.png") surface.SetMaterial(wastelander) surface.SetDrawColor( 255, 255, 255, 255) surface.DrawTexturedRect(x+w/2-8, y+h/2-8, 16, 16) end draw.DrawText( ply:Name(), "NameF", ScrW() - 1485, 760, Color(255,255,255,255)) local Avatar = vgui.Create( "AvatarImage", Panel ) Avatar:SetSize( 79, 79 ) Avatar:SetPos( ScrW() - 1590, ScrH() - 142 ) Avatar:SetPlayer( LocalPlayer(), 64 ) draw.RoundedBox(0, ScrW() - 1548, ScrH() - 61 , 248, 25, Color( 0, 0, 0, 125)) draw.RoundedBox(0, ScrW() - 1549, ScrH() - 61 , math.Clamp( HP, 0, 200 )+248, 25, Color( 230, 59, 59, 255)) draw.RoundedBox(0, ScrW() - 1549, ScrH() - 33 , math.Clamp( ARM, 0, 200 )+248, 21, Color( 63, 121, 208, 255)) end function Factions() local base = vgui.Create( "DFrame" ) base:SetSize( 400, 80 ) base:SetPos( (ScrW()/2)-base:GetWide()/2, (ScrH()/2)-base:GetTall()/2) base:SetTitle( "Pick your team!") base:SetVisible( true ) base:SetDraggable( true ) base:ShowCloseButton( true ) base:MakePopup() local button = vgui.Create( "DButton" ) button:SetParent( base ) button:SetSize( 160, 40 ) button:SetText( "Raiders") button:SetPos( 20, 30 ) button.DoClick = function() RunConsoleCommand( "RaiderJoin"
Just a tip, don't use silk icons on your hud. They are pretty gross Use one of these sites for the icons instead: [url]http://www.flaticon.com/[/url] [url]http://thenounproject.com/[/url] [url]http://fontello.com/[/url]
where would i place the .png into in my gamemodes folder? my content folder? How would i swap the material line for the image in **gamemode/content/heart.png for this line of code? surface.SetMaterial(Material("icon16/heart.png"))
Content/materials/vgui And reference as "vgui/whatever.png" IIRC
[QUOTE=Exho;46653997]Content/materials/vgui And reference as "vgui/whatever.png" IIRC[/QUOTE] Thanks i will try it out, i just added you on steam btw, thanks so much for the help dude!
Put the .png anywhere inside the garrysmod/material/ directory. Then this is how to draw a textured rectangle. [lua] local icon = Material("material.png") -- you're material file here surface.SetDrawColor(255,255,255) -- make sure you're color is the color of a mirror so it reflects all 16.8 million colors the png can have surface.SetMaterial(icon) surface.DrawTexturedRect(x, y, w, h)[/lua]
[QUOTE=Author.;46654095]Put the .png anywhere inside the garrysmod/material/ directory. Then this is how to draw a textured rectangle. [lua] local icon = Material("material.png") -- you're material file here surface.SetDrawColor(255,255,255) -- make sure you're color is the color of a mirror so it reflects all 16.8 million colors the png can have surface.SetMaterial(icon) surface.DrawTexturedRect(x, y, w, h)[/lua][/QUOTE] Thanks, was able to figure out that part just didnt know where to place the material.
Do anyone know why my playermodel has like zero animation? and i cant see my arms while holding the physicsgun. [IMG]http://i.imgur.com/XocekVH.png[/IMG]
[QUOTE=michaelclaw;46657947]Do anyone know why my playermodel has like zero animation? and i cant see my arms while holding the physicsgun. [/QUOTE] Are you using the Ragdoll ("models/Combine_Super_Soldier.mdl") model or the player ("models/player/Combine_Super_Soldier.mdl") model? Ragdoll: [t]http://puu.sh/dkifi/92d53ff2bc.jpg[/t] Player: [t]http://puu.sh/dkigj/a632de3878.jpg[/t]
[QUOTE=Pandaman09;46657972]Are you using the Ragdoll ("models/Combine_Super_Soldier.mdl") model or the player ("models/player/Combine_Super_Soldier.mdl") model? Ragdoll: [t]http://puu.sh/dkifi/92d53ff2bc.jpg[/t] Player: [t]http://puu.sh/dkigj/a632de3878.jpg[/t][/QUOTE] That was it, thanks! Also How would i go about making props have health and making a swep that destroys them?
[QUOTE=michaelclaw;46658318]That was it, thanks! Also How would i go about making props have health and making a swep that destroys them?[/QUOTE] Do you want health to props so only the swep can destroy them? Instant destroy or like 2 hits or more?
[QUOTE=SteppuFIN;46659428]Do you want health to props so only the swep can destroy them? Instant destroy or like 2 hits or more?[/QUOTE] Well i wanted the props to have health and blowtorches to remove like 5 health every second.
Sorry, you need to Log In to post a reply to this thread.