• Need help with making a Custom HUD please.
    2 replies, posted
Hello, Names Jacklin (not my real name but thats what most people know me as now). I tried lua coding for garry's mod before and it turned into a complete Fail, so now im having a fresh start and rather then being creative im taking it step by step till i get the hang of coding. So my problem is I made my HUD, works great, now im wanting to add a logo on it, it took a while for me to get the logo implemented, but once i got there and scaled and positioned it, it worked great! 1 problem though, I set it up for a screen resolution of 1920 x 1080, if you change your screen size it either changes position or goes off the screen, thats where I need help, to keep it within my HUD. Here is my cl_init.lua [CODE]include( 'shared.lua' ) function HUDHide( myhud ) for k, v in pairs{"CHudHealth","CHudBattery"} do if myhud == v then return false end end end hook.Add("HUDShouldDraw","HUDHide",HUDHide) function HUD() local ply = LocalPlayer() local HP = ply:Health() local Armor = ply:Armor() // local mat = Material ("vgui/logo") draw.RoundedBox( 4, 110, ScrH() - 250, 240, 200, Color( 40, 40, 40, 255 ) ) draw.RoundedBox( 4, 130, ScrH() - 100, 200, 40, Color( 255, 255, 255, 15 ) ) draw.RoundedBox( 4, 130, ScrH() - 100, math.Clamp( HP, 1, 100 )*2, 40, Color( 255, 41, 33, 255 ) ) draw.DrawText("HP", "DebugFixed", 232, ScrH() - 90, Color( 255, 255, 255, 255 ),TEXT_ALIGN_CENTER) draw.DrawText( HP, "DebugFixed", 315, ScrH() - 90, Color( 255, 255, 255, 255 ),TEXT_ALIGN_CENTER) //draw.DrawText( , "DebugFixed", 315, ScrH() - 90, Color( 255, 255, 255, 255 ),TEXT_ALIGN_CENTER) draw.RoundedBox( 4, 130, ScrH() - 150, 200, 40, Color( 255, 255, 255, 15 ) ) draw.RoundedBox( 4, 130, ScrH() - 150, math.Clamp( Armor, 1, 100 )*2, 40, Color( 0, 172, 221, 255 ) ) draw.DrawText("Armor", "DebugFixed", 232, ScrH() - 140, Color( 255, 255, 255, 255 ),TEXT_ALIGN_CENTER) draw.DrawText( Armor, "DebugFixed", 315, ScrH() - 140, Color( 255, 255, 255, 255 ),TEXT_ALIGN_CENTER) // render.SetMaterial( mat ) draw.DrawText( "Work In Progress", "DebugFixed", 235, ScrH() - 250, Color( 255, 255, 255, 255 ),TEXT_ALIGN_CENTER) draw.DrawText( "HUD", "DebugFixed", 235, ScrH() - 235, Color( 255, 255, 255, 255 ),TEXT_ALIGN_CENTER) draw.DrawText( "[LOGO GOES HERE]", "DebugFixed", 235, ScrH() - 200, Color( 255, 255, 255, 255 ),TEXT_ALIGN_CENTER) --[[ Note: This is what its set to work for 1920 x 1080 resolution, It needs to be able to work for all resolutions. draw.TexturedQuad { texture = surface.GetTextureID "vgui/logo", color = Color(255, 255, 255, 255), x = 115, y = 810, w = ScrW() - 1700, h = ScrH() - 900 } --]] end hook.Add( "HUDPaint", "HUD", HUD )[/CODE] If you need anymore information, Contact me on steam 'Westernholmrs' or on Skype 'westernholmes' ( Yes I know them 2 are different, I spelt my name wrong on steam when i first signed up in 2007 :P ) Also I have a server that is running the gamemode this is for, you can access it by joining the ip [URL="steam://connect/192.168.0.150:27015"]5.67.98.176:27015[/URL] and typing in the password 'GMBeta2014' oh and also, if you need to download the files for the logo there here, [URL="http://portablepro.marcuz.co.uk/garrysmod/materials/vgui/logo.vtf"]logo.vtf[/URL] and [URL="http://portablepro.marcuz.co.uk/garrysmod/materials/vgui/logo.vmt"]logo.vmt[/URL]
[QUOTE=Jacklin_G;45638719] [CODE] --[[ Note: This is what its set to work for 1920 x 1080 resolution, It needs to be able to work for all resolutions. draw.TexturedQuad { texture = surface.GetTextureID "vgui/logo", color = Color(255, 255, 255, 255), x = 115, y = 810, w = ScrW() - 1700, h = ScrH() - 900 } --]][/CODE] [/QUOTE] So if you have a screen with the resolution 1920x1080 the following variables would be like this: x = 115 y = 810 w = 200 h = 180 What I don't understand is, why would you want to calculate the width / height using ScrW and ScrH? And besides that, the calculations you made ScrW - 1700 doesn't really make sense to me :D You probabbly want to make the position relative to your Screen Size, so you should use something like: x = ScrW() * 0.5 y = ScrH() - 200 Besides all that, I suggest you don't add a Logo to your HUD. Of course, drawing a texture is an important thing every developer needs to have done once at least, but I know (from my own experience) that logos are pretty annoying if they are there all the time :)
Proper HUD Creation: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/proper_hud_creation.lua.html[/url] Note, don't use HUDShouldDraw with a table / loop. Look at the Proper HUD Creation, notice how it uses a table, direct access to see whether or not the hud should draw? Running table.HasValue ( essentially the same thing you have ) 100 million times, vs running the direct access example 100 million times gives a result whereby using the table to search is 15+ seconds where-as the direct-access is 0.08 seconds. A HUGE difference. If you want an easy way to scale your hud, hardcode your screensize and use a modifier that you multiply x/y/w/h values by: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/understanding_hardcoding_of_screensizes.lua.html[/url]
Sorry, you need to Log In to post a reply to this thread.