General > Developers Corner
Health Bar Issues
JamminR:
There are several ways, each with pros/cons.
Perhaps you could use PLAYER:Loadout to call that function then return as normal to prevent it from modifying loadout weapons.
Suicidal Dog:
--- Quote from: MrPresident on May 08, 2017, 12:43:03 PM ---I gave you the way to do it. Please do not come on here demanding that people do work for you. This forum is for getting assistance with things, not for having people do things for you.
If you can't be bothered to do the research yourself.. then no one else can be bothered to do it for you.
--- End quote ---
Dude I didn't mean to seem bossy and 'demand' anything but I literally have the most important time of my life in these few weeks with GCSEs and after doing stuff for school I'm tired and can't focus properly but now I've thought about it I've probably figured out an issue so don't jump to a conclusion I am too lazy to do things myself.
Suicidal Dog:
When trying to do this is still doesn't work and sets the hud to an old look upon joining until I resave the file so it updates on the player.
--- Code: ---if IsValid( LocalPlayer() ) then
local smoothHealth = LocalPlayer():GetMaxHealth()
end
local function healtharmorBase()
draw.RoundedBox( 0, 0, ScrH () - 75 - 10, 450, 75, Color( 0, 0, 0, 200 ) )
draw.RoundedBox( 0, 0, ScrH() - 85 - 60, 350, 50, Color( 0, 0, 0, 200 ))
surface.SetDrawColor( Color( 255, 255, 255, 255 ) )
surface.DrawOutlinedRect( -1, ScrH() - 83, 449, 71 )
surface.DrawOutlinedRect( -1, ScrH() - 143, 349, 46 )
end
local function healtharmorBar()
smoothHealth = Lerp( 5 * FrameTime(), smoothHealth, LocalPlayer():Health() )
draw.RoundedBox( 0, 0, ScrH() - 75- 5, 446 * smoothHealth /100, 65, Color( 200, 50, 50 ))
end
--- End code ---
MrPresident:
Code outside of functions gets called when the file is loaded.
Your valid checks need to be in the functions where the information is needed.
Suicidal Dog:
This one isn't working but the 2nd one works on a different server I've got where I was doing gamemode stuff.
--- Code: ---local function healtharmorBar()
maxHealth = LocalPlayer():GetMaxHealth()
smoothHealth = Lerp( 5 * FrameTime(), 100, LocalPlayer():Health() )
surface.SetDrawColor( 200, 50, 50, 255 )
--surface.DrawTexturedRect( 0, ScrH() - 75- 5, 445 * ( LocalPlayer():Health() / LocalPlayer():GetMaxHealth() ) , 65)
draw.RoundedBox( 0, 0, ScrH() - 85 - 55, 345 * smoothHealth / 100, 40,Color( 200, 50, 50 ))
surface.SetDrawColor( 50, 50, 255, 255 )
--surface.DrawTexturedRect( 0, ScrH() - 85 - 55, 345 * ( LocalPlayer():Health() / 100 ) , 40)
draw.RoundedBox( 0, 0, ScrH() - 70 - 11, 245 * ( LocalPlayer():Armor() / 100 ), 16, Color( 30, 30, 255 ) )
end
--- End code ---
A short video on what happens when I try the first one on the screen: https://www.youtube.com/watch?v=02dwOjvSiIw&feature=youtu.be
From that video you see the health bar was jumping back and forth between random points it seems, now I've no idea what that could be caused by.
--- Code: ---local smoothHealth = 250
local function HealthBar()
smoothHealth = Lerp( 5 * FrameTime(), smoothHealth, LocalPlayer():Health() )
draw.RoundedBox( 0, 12, ScrH() / 2 - 132, 96, 264, Color( 0, 0, 0, 175 ) )
draw.RoundedBox( 0, 19, ScrH() / 2 - 124.25, 82, smoothHealth, Color( 200, 50, 50, 255 ) )
draw.RoundedBox( 0, 12, ScrH() / 2 - 17.5, 96, 35, Color( 0, 0, 0, 175 ) )
surface.SetDrawColor( Color( 200, 200, 200, 255 ) )
surface.DrawOutlinedRect( 15, ScrH() / 2 - 129, 90, 258 )
surface.DrawOutlinedRect( 15, ScrH() / 2 - 16, 90, 30 )
draw.SimpleTextOutlined( LocalPlayer():Health(), "CloseCaption_Bold", 60, ScrH() / 2 - 1, Color( 255, 255, 255 ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER , 1, Color( 0, 0, 0, 100 ) )
end
--- End code ---
Navigation
[0] Message Index
[*] Previous page
Go to full version