1. This forum is ARCHIVED! Visit the new Cloud Sixteen forums, codename Eden, at https://eden.cloudsixteen.com. These forums will remain archived for a few months before being closed down, so try to encourage plugin developers to begin moving their content across to the new forums.
Dismiss Notice
Hi Guest, you need a Steam account to register and post on these forums. Login with Steam at the top of the forums to get started!
Dismiss Notice
Hi Guest, do you want to buy HL2RP or another Clockwork schema? Visit the Cloud Sixteen Store to get started!

[Fixed] Need Help with some Code.

Discussion in 'Development' started by Sheeplie, Nov 22, 2014.

  1. Sheeplie

    Sheeplie Hi.

    Update: Fixed, for anyone's reference this was because I was using the grey gordon model as a playermodel. Setting the playermodel to anything else in your gamemode fixes this.



    Code:
    function CoolHUD()
    	local ply = LocalPlayer()
    	local HP = ply:Health()
    	local Armor = ply:Armor()
    	
    	
    	draw.RoundedBox( 0, 130, ScrH() - 120, 200, 20, Color( 0, 0, 0, 230 ) ) -- Black Box
    	draw.RoundedBox( 0, 130, ScrH() - 60, 200, 20, Color( 0, 0, 0, 230 ) ) -- Black Box 2
    	draw.RoundedBox( 0, 110, ScrH() - 120, 20, 80, Color( 0, 0, 0, 230 ) ) -- Black Box Side
    	draw.RoundedBox( 0, 330, ScrH() - 120, 20, 80, Color( 0, 0, 0, 230 ) ) -- Black Box Side 2
    	draw.RoundedBox( 4, 130, ScrH() - 100, 200, 40, Color( 40, 40, 40, 120 ) )
    	draw.RoundedBox( 4, 130, ScrH() - 100, math.Clamp( HP, 0, 200 )*2, 40, Color( 220, 108, 108, 255 ) )
    
    	
    	draw.DrawText( "Health", "Hudfont", 300, ScrH() - 120, Color( 255, 255, 255, 255 ), TEXT_ALIGN_CENTER )
    	
    
    end
    hook.Add( "HUDPaint", "CoolHUD", CoolHUD )
    
    surface.CreateFont( "Hudfont", {
    	font = "Arial", 
    	size = 20, 
    	weight = 500, 
    	blursize = 0, 
    	scanlines = 0, 
    	antialias = true, 
    	underline = false, 
    	italic = false, 
    	strikeout = false, 
    	symbol = false, 
    	rotary = false, 
    	shadow = false, 
    	additive = false, 
    	outline = true, 
    } )
    

    I made this health bar with vgui (Based it off a youtube tutorial I watched), but there's a problem. When the bar representing health runs out (when my health hits zero) Garry's Mod crashes. I guess this is because there's nothing to tell the red health bar to end when it runs out?

    I tried adding this:
    Code:
    if !(LocalPlayer() and LocalPlayer():Alive()) then return end
    right after Function CoolHUD() and still got no new results.


    Note: This isn't anything clockwork related.

    Can someone here explain what I should do?
    Thanks.
     
  2. Re: Need Help with some Code.

    Maybe try to use 'if (HP <= 0) then return end' after setting variables and before drawing the hud.
     
  3. Sheeplie

    Sheeplie Hi.

    Re: Need Help with some Code.

    Update: Did a test to remove the modified HUD code entirely, oddly enough the game still crashes upon death. I'm just running this off a little gamemode I threw together (If you'd even call it a 'gamemode'.) Is there anything I need to specify in a gamemode involving player death?

    Note: I'm not running off sandbox.
     

Previous Readers (Total: 0)