Health Bar

Hello guys,i’m still making my hud and its fine, but its not very cool as it looks. I’ve got Health, Armor, Ammo indicators ( in procents ), but i thought that with bar it would look very nice. I cant find any tutorial which tells how to make a health bar. Kinda like that, you know. I will be very glad if you help me.

[editline]14th January 2013[/editline]

Why you doesnt reply? Isnt from all that viewers, none of them are lua coders?

Because this is so easy to code it’s sad… Draw a background rect then find the health as a decimal 0-1. Multiply it by the width if the background rect to find the proper size for the foreground.

Sorry If hard to read. I’m on my phone

-snip-

Dont really understand how to turn it out. I’m littlebit newb in Lua. I guess i know what you mean, but codes… Can you just type here a code for :slight_smile: . I will fix it out for my hud, but i really dont know how to do that. There is more tutorials on how to make damn easy HUD, but no tutorials bout bar.

You can get the health from ply:Health() function. Then you just have to fiddle with the values to find the formula that suits you with the bar length and width.

local RedBarWidth = MaxBarWidth * (player:GetHealth() / player:GetMaxHealth())

GetMaxHealth isn’t network iirc.

Oh right. Derp. Well, the concept still holds.


function exampleHUD()

local ply = LocalPlayer()
if ply:Alive() then

local health = ply:Health()
local maxhealth = 100

local healthratio = math.Round(health*10/maxhealth)/10
	
surface.SetDrawColor( 100, 100 , 100, 200 )
surface.DrawOutlinedRect( 153, ScrH()-89, 250, 64 )
surface.SetDrawColor( 200*(1-healthratio), 200*healthratio , 0, 200 )
surface.DrawRect( 154, ScrH()-88, 248*healthratio, 62 )
draw.SimpleText("HP:"..health, "Trebuchet24", 280, ScrH() - 56, Color( 255, 255, 255, 245 ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )

end
end

You have made so many threads about your HUD. Can’t you learn to to anything by yourself?

How to learn something without teacher. I’ve tried to read some books, its not that what i need. I’ve watched tutorials and i understand some parts of lua, still there is no tutorials about whole lua and to learn that, i need somebody to help me out.

Learn this :

I like, others, learned by watching already made code. It all makes logical sense in a while. At first you go back to that script that did the same and watch how he did it, like all the time. But as time passes on you’ll learn to do it by yourself since you can think logically how it should be done.
I have never really read the full lua PIL like others say you should, but I’ve managed anyways. Fuck the “LUA YOUTUBE VIDEO TUTORIAL PART 5” because they suck anyways.

Ofcourse i take some full maded codes and changing, learning bout them and how to do them. Still i tried out some huds like ttt and i cant fuck understand whats inside of it. There is shit load of stuff. So i wanted somebody to make that code for me and i could fix it for my code to learn more about lua. Still i havent got descent answer yet. All the codes which that guys gave me, doesnt works…

[editline]15th January 2013[/editline]

I only asked somebody to type lua code here for HP bar. And everyone tells me to learn lua and stuff. I just asked you to do one thing and you fucked it up on 2 days.

Look my first answer. I post your HP Bar

It’s not so much a mater of learning as this is something that shouldn’t have to be learn’t. Making a bar doesn’t need a tutorial. If you just think about the elements of a bar and the mathematics required to determine their scales it should be incredibly easy.

If you really can’t figure it out by thinking for a while and possibly diagraming it on paper you should go back and review the basics of arithmetic and programming instead of asking people here to teach you everything you should know from elementary school and effectively saying: it’s too hard could you just do it for me and give me some code?

You seriously think that i can learn anything in that fucking Russia. I think that teachers of lua should be coders of lua. And i dont think that simple course of maths can help with that. You gave me some links on lua to learn. I’m trying to understand it, still there is only parts of codes on that tutorials. I should know how to use that code to figure out about it.

. Looks like we just playing not the same game, your lua code doesn’t works :}

Forward this to your government: “Good job.”

Anyway, try this tutorial.
Every line is commented to explain you what it does.

Please click on the triangles on the (left) sidebar next to “Functions” and “Hooks” to get you started on searching for functions. The most used/useful ones are pretty well documented.
The tutorials are under “Lua Scripting.”

Nope, the tutorial you gave me was writen in 2009. In 2009 was Gmod 9. That code have changed and f’d up even in Gmod 10, but now its Gmod 13!!! Also when i select Lua Searching, error pop up. So…

The code is mostly the same, so if you get an issue with the code from the tutorial you can easily look it up. That is if you can search on the wiki…