HUD health sliding down instead of going directly down
18 replies, posted
Well, my HUD has a health bar. But when I get damaged the hud goes from "old health" to current health directly. What I want it to do instead is to slide down from the 'old health' to the current. Hope you understand me.
Uh, I don't even know what it is. But I will try doing something with it
[lua]
-- Created by CowThing
local smooth = 0 -- Setting up the variable that will get smoothed.
hook.Add("HUDPaint", "HealthBar", function()
local health = math.Clamp(LocalPlayer():Health(), 0, 100) -- clamps the health to [0, 100] meaning it will not go above 100 or below 0
smooth = math.Approach(smooth, health, 50*FrameTime()) -- smooth the health value, this looks a lot better than just using the raw health value.
-- You should use FrameTime() for things like this so it will look smooth even if your FPS is low.
local red = (1 - smooth/100)^(1/2) * 255 -- Create a linear equation for the red value, as health drops red increases.
local grn = (smooth/110)^(1/2) * 255 -- same for green, as health drops green decreases.
local blu = (smooth/200)^2 * 255 -- and for blue
local col = Color(red, grn, blu) -- create a single color object with the values.
local w, h = 60, 200
local spacing = 32
local equation = (h-8)*(smooth/100)+8 -- this equation is so the bar will shrink as you lose health.
draw.RoundedBox(
4,
ScrW() - w - spacing - 2,
ScrH() - h - spacing - 2,
w + 4,
h + 4,
Color( 30, 30, 30 )
)
draw.RoundedBox(
4,
ScrW() - w - spacing,
ScrH() - equation - spacing,
w,
equation,
col
)
end)
[/lua]
Taken from the wiki it should help
Thanks, I realy appreciate that.
[editline]2nd April 2011[/editline]
Well, does it work the same way with VTF's? Like my healthbar is a VTF file, and not a RoundedBox.
[editline]2nd April 2011[/editline]
I realy don't get it. Could you help me?
[lua]
local client = LocalPlayer( )
if !client:Alive( ) then return end
if( client:GetActiveWeapon( ) == NULL or client:GetActiveWeapon( ) == "Camera" ) then return end
healthwidth = client:Health() * 1.966
local tex1 = surface.GetTextureID("gui/zombie/bars/healthbargreen")
local tex2 = surface.GetTextureID("gui/zombie/bars/healthbaryellow")
local tex3 = surface.GetTextureID("gui/zombie/bars/healthbarred")
local health1 = surface.GetTextureID("gui/zombie/cross/healthgreen")
local health2 = surface.GetTextureID("gui/zombie/cross/healthyellow")
local health3 = surface.GetTextureID("gui/zombie/cross/healthred")
local main = surface.GetTextureID("gui/zombie/main/main")
local heal = surface.GetTextureID("gui/zombie/icons/heal")
surface.SetTexture(main)
surface.SetDrawColor(255,255,255,255)
surface.DrawTexturedRect(4, ScrH()/2 + 310,200,56)
if client:Health() > 60 then
surface.SetTexture(tex1)
surface.SetDrawColor(255,255,255,255)
surface.DrawTexturedRect(6, ScrH()/2 + 339,healthwidth,25)
surface.SetTexture(health1)
surface.SetDrawColor(255,255,255,255)
surface.DrawTexturedRect(8, ScrH()/2 + 313,23,23)
elseif client:Health() > 30 then
surface.SetTexture(tex2)
surface.SetDrawColor(255,255,255,255)
surface.DrawTexturedRect(6, ScrH()/2 + 339,healthwidth,25)
surface.SetTexture(health2)
surface.SetDrawColor(255,255,255,255)
surface.DrawTexturedRect(8, ScrH()/2 + 313,23,23)
elseif client:Health() < 30 then
surface.SetTexture(tex3)
surface.SetDrawColor(255,255,255,255)
surface.DrawTexturedRect(6, ScrH()/2 + 339,healthwidth,25)
surface.SetTexture(health3)
surface.SetDrawColor(255,255,255,255)
surface.DrawTexturedRect(8, ScrH()/2 + 313,23,23)
surface.SetTexture(heal)
surface.SetDrawColor(255,255,255,255)
surface.DrawTexturedRect(98, ScrH()/2 + 320,13,13)
end
if client:Health() > 60 then
draw.SimpleText(client:Health(), "Trebuchet24", 40, ScrH()/2 + 313, Color(0,150,0,255) )
elseif client:Health() > 30 then
draw.SimpleText(client:Health(), "Trebuchet24", 40, ScrH()/2 + 313, Color( 200,200,0,255) )
elseif client:Health() < 30 then
draw.SimpleText(client:Health(), "Trebuchet24", 40, ScrH()/2 + 313, Color( 150,0,0,255) )
end
[/lua]
Just copy the calculations and then use equation to instead of your healthwidth
Okay, let me try that.
[editline]2nd April 2011[/editline]
And where is h validated?
[editline]2nd April 2011[/editline]
Nevermind.
[editline]2nd April 2011[/editline]
Ugh, my hud just got fucked up. Works but its like shrinking all the time and is way too small. Would you be nice enough to do it for me, and get the size fully working?
Flawless could you?
I am on my linux laptop atm because I am having some pc issues I will when I get on my pc
Thanks mate. I'll just wait then.
'
[editline]3rd April 2011[/editline]
How did I post that...
Still on my laptop trying to get gmod working but give this a try untested
[lua]
local smooth = 0
local tex2 = surface.GetTextureID("gui/zombie/bars/healthbaryellow")
hook.Add("HUDPaint", "HealthBar", function()
local health = math.Clamp(LocalPlayer():Health(), 0, 100)
smooth = math.Approach(smooth, health, 50*FrameTime())
local w, h = 300, 20
local equation = (w-8)*(smooth/100)+8
surface.SetTexture(tex2)
surface.SetDrawColor(255,255,255,255)
surface.DrawTexturedRect(6, ScrH()/2 + 339,equation,25)
end)
[/lua]
Thanks, I will try that and post back later.
[editline]3rd April 2011[/editline]
Ain't working.
[url]http://www.wegame.com/watch/crazeh/[/url]
Its working for me with draw rounded box instead of draw-texture so I have no idea why its not working for you
Yeah, maybe it's some seaky way to do it with texturing. But I don't realy know.
[editline]3rd April 2011[/editline]
Maybe I just mucked it up somehow. Current code:
[lua]
local smooth = 0
local client = LocalPlayer( )
if !client:Alive( ) then return end
if( client:GetActiveWeapon( ) == NULL or client:GetActiveWeapon( ) == "Camera" ) then return end
local health = math.Clamp(LocalPlayer():Health(), 0, 100)
smooth = math.Approach(smooth, health, 50*FrameTime())
local tex1 = surface.GetTextureID("gui/zombie/bars/healthbargreen")
local tex2 = surface.GetTextureID("gui/zombie/bars/healthbaryellow")
local tex3 = surface.GetTextureID("gui/zombie/bars/healthbarred")
local health1 = surface.GetTextureID("gui/zombie/cross/healthgreen")
local health2 = surface.GetTextureID("gui/zombie/cross/healthyellow")
local health3 = surface.GetTextureID("gui/zombie/cross/healthred")
local main = surface.GetTextureID("gui/zombie/main/main")
local heal = surface.GetTextureID("gui/zombie/icons/heal")
surface.SetTexture(main)
surface.SetDrawColor(255,255,255,255)
surface.DrawTexturedRect(4, ScrH()/2 + 310,200,56)
local w, h = 300, 20
local equation = (w-8)*(smooth/100)+8
if client:Health() > 60 then
surface.SetTexture(tex1)
surface.SetDrawColor(255,255,255,255)
surface.DrawTexturedRect(6, ScrH()/2 + 339,equation,25)
surface.SetTexture(health1)
surface.SetDrawColor(255,255,255,255)
surface.DrawTexturedRect(8, ScrH()/2 + 313,23,23)
elseif client:Health() > 30 then
surface.SetTexture(tex2)
surface.SetDrawColor(255,255,255,255)
surface.DrawTexturedRect(6, ScrH()/2 + 339,equation ,25)
surface.SetTexture(health2)
surface.SetDrawColor(255,255,255,255)
surface.DrawTexturedRect(8, ScrH()/2 + 313,23,23)
elseif client:Health() < 30 then
surface.SetTexture(tex3)
surface.SetDrawColor(255,255,255,255)
surface.DrawTexturedRect(6, ScrH()/2 + 339,equation,25)
surface.SetTexture(health3)
surface.SetDrawColor(255,255,255,255)
surface.DrawTexturedRect(8, ScrH()/2 + 313,23,23)
surface.SetTexture(heal)
surface.SetDrawColor(255,255,255,255)
surface.DrawTexturedRect(98, ScrH()/2 + 320,13,13)
end
if client:Health() > 60 then
draw.SimpleText(client:Health(), "Trebuchet24", 40, ScrH()/2 + 313, Color(0,150,0,255) )
elseif client:Health() > 30 then
draw.SimpleText(client:Health(), "Trebuchet24", 40, ScrH()/2 + 313, Color( 200,200,0,255) )
elseif client:Health() < 30 then
draw.SimpleText(client:Health(), "Trebuchet24", 40, ScrH()/2 + 313, Color( 150,0,0,255) )
end
[/lua]
[editline]3rd April 2011[/editline]
Did Flawless get banned?
Yes, for "backseat moderation" which is apparently when you say "oh by the way, you're in the wrong section."
[editline]3rd April 2011[/editline]
Quote:
[QUOTE=King Flawless;28968208]Firstly wrong section, secondly is this a request or are you actually planning on learning lua?
[highlight](User was banned for this post ("Backseat moderation" - mahalis))[/highlight][/QUOTE]
[editline]3rd April 2011[/editline]
I think Flawless is a bit rude, but he is very helpful and good at lua.
[QUOTE=cis.joshb;28974903]I think Flawless is a bit rude, but he is very helpful and good at lua.[/QUOTE]
When you get to my level of awesome you can be as rude as you like
Flawless is a bit rude, but hell, hes helping me still tho I was rude against him.
Anyone?
Sorry, you need to Log In to post a reply to this thread.