• hud problems
    5 replies, posted
Can somebody tell me where I went wrong with this HUD code? [lua] local vars = { font = "TargetID", padding = 10, margin = 35, text_spacing = 2, bar_spacing = 5, bar_height = 16, width = 0.25 }; local colors = { background = { border = Color( 190, 255, 128, 255 ), background = Color( 120, 240, 0, 75 ) }, text = { shadow = Color( 0, 0, 0, 200 ), text = Color( 255, 255, 255, 255 ) }, health_bar = { border = Color( 255, 0, 0, 255 ), background = Color( 255, 0, 0, 75 ), shade = Color( 255, 104, 104, 255 ), fill = Color( 232, 0, 0, 255 ) }, suit_bar = { border = Color( 0, 0, 255, 255 ), background = Color( 0, 0, 255, 75 ), shade = Color( 136, 136, 255, 255 ), fill = Color( 0, 0, 219, 255 ) } }; local function HUDPaint( ) client = client or LocalPlayer( ); -- set a shortcut to the client if( !client:Alive( ) ) then return; end -- don't draw if the client is dead local _, th = good_hud:TextSize( "TEXT", vars.font ); -- get text size( height in this case ) local i = 2; -- shortcut to how many items( bars + text ) we have local width = vars.width * ScrW( ); -- calculate width local bar_width = width - ( vars.padding * i ); -- calculate bar width and element height local height = ( vars.padding * i ) + ( th * i ) + ( vars.text_spacing * i ) + ( vars.bar_height * i ) + vars.bar_spacing; local x = vars.margin; -- get x position of element local y = ScrH( ) - vars.margin - height; -- get y position of element local cx = x + vars.padding; -- get x and y of contents local cy = y + vars.padding; good_hud:PaintPanel( x, y, width, height, colors.background ); -- paint the background panel local by = th + vars.text_spacing; -- calc text position local text = string.format( "Health: ", client:Health( ) ); -- get health text good_hud:PaintText( cx, cy, text, vars.font, colors.text ); -- paint health text and health bar good_hud:PaintBar( cx, cy + by, bar_width, vars.bar_height, colors.health_bar, client:Health( ) / 100 ); by = by + vars.bar_height + vars.bar_spacing; -- increment text position local text = string.format( "Armor: ", client:Armor( ) ); -- get suit text good_hud:PaintText( cx, cy + by, text, vars.font, colors.text ); -- paint suit text and suit bar good_hud:PaintBar( cx, cy + by + th + vars.text_spacing, bar_width, vars.bar_height, colors.suit_bar, client:Armor( ) / 100 ); end hook.Add( "HUDPaint", "PaintOurHud", HUDPaint ); function hidehud(name) for k, v in pairs{"CHudHealth", "CHudBattery"} do if name == v then return false end end end hook.Add("HUDShouldDraw", "hidehud", hidehud) [/lua]
Isn't that stolen from a HUD on Garrysmod.org? I remember looking at something that looks about that.
[QUOTE=HeavyMtl123;21623747]Isn't that stolen from a HUD on Garrysmod.org? I remember looking at something that looks about that.[/QUOTE] Nope. It's from the wiki.
May help if you tell us whats not working and if your getting any errors
Everything is at the wiki tutorial. Ive red this and had the same problem because of bad reading.
[QUOTE=|King Flawless|;21624964]May help if you tell us whats not working and if your getting any errors[/QUOTE] That's just it, I'm getting absolutely no errors. But I'm gonna see if Yuriman is right and go read the wiki again. EDIT: Found the problem, I hadn't included it with cl_init.
Sorry, you need to Log In to post a reply to this thread.