• HUD Health Bar Issue
    15 replies, posted
So Ive recently been working on my first HUD, and its pretty much complete except for the health bar. [IMG]http://i.imgur.com/ZvbPfFR.jpg[/IMG] Its working fine until you go past 100 hp where the bar will just keep expanding right across the screen. [IMG]http://i.imgur.com/DwB24F4.jpg[/IMG] Please help
[QUOTE=KeZzY*;51653363]So Ive recently been working on my first HUD, and its pretty much complete except for the health bar. [IMG]http://i.imgur.com/ZvbPfFR.jpg[/IMG] Its working fine until you go past 100 hp where the bar will just keep expanding right across the screen. [IMG]http://i.imgur.com/DwB24F4.jpg[/IMG] Please help[/QUOTE] Use math.Clamp() on the progress bar's rendering, but don't do it on the text. Clamp it between 0 and 100. Do the same thing for the armor if it's happening to the armor bar too. [CODE]math.Clamp( input, 0, 100 )[/CODE]
Ill show you my code [editline]11th January 2017[/editline] [QUOTE=brianm109;51653394]Use math.Clamp() on the progress bar's rendering, but don't do it on the text. Clamp it between 0 and 100. Do the same thing for the armor if it's happening to the armor bar too. [CODE]math.Clamp( input, 0, 100 )[/CODE][/QUOTE] Where abouts do i put it in this - So this is my healthbar's code, where abouts do i put it? local health = client:Health() draw.RoundedBox(0, 58, ScrH() -92, 300 + 4, 14 + 4, Color(40,40,40)) draw.RoundedBox(0, 60, ScrH() -90, health * 3, 14, Color(255,77,77)) draw.SimpleText(health.."%", "Kenz", 70 + 146 , ScrH() -85, Color (255, 255, 255), 1, 1)
[QUOTE=KeZzY*;51653447]So this is my healthbar's code, where abouts do i put it? local health = client:Health() draw.RoundedBox(0, 58, ScrH() -92, 300 + 4, 14 + 4, Color(40,40,40)) draw.RoundedBox(0, 60, ScrH() -90, health * 3, 14, Color(255,77,77)) draw.SimpleText(health.."%", "Kenz", 70 + 146 , ScrH() -85, Color (255, 255, 255), 1, 1)[/QUOTE] Next time, please put the code in code tags to make it easier for people to read. Anyway, replace [CODE]draw.RoundedBox(0, 60, ScrH() -90, health * 3, 14, Color(255,77,77))[/CODE] with [CODE]draw.RoundedBox(0, 60, ScrH() -90, math.Clamp(health * 3, 0, 100), 14, Color(255,77,77))[/CODE] [editline]10th January 2017[/editline] That is untested. So, if it errors, please post the error. And, try it yourself on the armor bar as well if it does the same thing.
[QUOTE=brianm109;51653489]Next time, please put the code in code tags to make it easier for people to read. Anyway, replace [CODE]draw.RoundedBox(0, 60, ScrH() -90, health * 3, 14, Color(255,77,77))[/CODE] with [CODE]draw.RoundedBox(0, 60, ScrH() -90, math.Clamp(health * 3, 0, 100), 14, Color(255,77,77))[/CODE] [editline]10th January 2017[/editline] That is untested. So, if it errors, please post the error. And, try it yourself on the armor bar as well if it does the same thing.[/QUOTE] So its made the health bar like this, and it just stays that size now [IMG]http://i.imgur.com/aMsatvz.jpg[/IMG]
[QUOTE=KeZzY*;51653529]So its made the health bar like this, and it just stays that size now [IMG]http://i.imgur.com/aMsatvz.jpg[/IMG][/QUOTE] Oh, I'm so sorry lol. Change the 100 to 300 in the math.Clamp() because I forgot to take into account the * 3 in your code.
[QUOTE=brianm109;51653537]Oh, I'm so sorry lol. Change the 100 to 300 in the math.Clamp() because I forgot to take into account the * 3 in your code.[/QUOTE] Cheers man it worked, one last thing quickly, as the Garrysmod.org, hp and armour bars font are custom. Do I just put their true text file into materials > fonts folder?
[QUOTE=KeZzY*;51653558]Cheers man it worked, one last thing quickly, as the Garrysmod.org, hp and armour bars font are custom. Do I just put their true text file into materials > fonts folder?[/QUOTE] Actually, no. They go in resource/fonts. [editline]10th January 2017[/editline] And, make sure to resource.AddFile() the font too.
yea i think i have got it, cheers man [editline]11th January 2017[/editline] [QUOTE=brianm109;51653577]Actually, no. They go in resource/fonts. [editline]10th January 2017[/editline] And, make sure to resource.AddFile() the font too.[/QUOTE] So does resource.AddFile() just go in a lua file called resource.lua in the lua > autorun > server folder?
[QUOTE=KeZzY*;51653599]yea i think i have got it, cheers man [editline]11th January 2017[/editline] So does resource.AddFile() just go in a lua file called resource.lua in the lua > autorun > server folder?[/QUOTE] It doesn't necessary have to. It can be put it in any script that is ran. But, that is one way.
Jeez just realised, money is working. Current code is [CODE] draw.SimpleText("Wallet : $", "Wallet", 278, ScrH() -47, Color(255, 255, 255),TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) draw.SimpleText(PlayerMoney, "Wallet", 310, ScrH() -55, Color(255, 255, 255), 0, 0) [/CODE] Just comes up with Nil
[QUOTE=KeZzY*;51653744]Jeez just realised, money is working. Current code is [CODE] draw.SimpleText("Wallet : $", "Wallet", 278, ScrH() -47, Color(255, 255, 255),TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) draw.SimpleText(PlayerMoney, "Wallet", 310, ScrH() -55, Color(255, 255, 255), 0, 0) [/CODE] Just comes up with Nil[/QUOTE] That's because your PlayerMoney variable isn't right. Can you show us the line where you define PlayerMoney?
[QUOTE=KeZzY*;51653744]Jeez just realised, money is working. Current code is [CODE] draw.SimpleText("Wallet : $", "Wallet", 278, ScrH() -47, Color(255, 255, 255),TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) draw.SimpleText(PlayerMoney, "Wallet", 310, ScrH() -55, Color(255, 255, 255), 0, 0) [/CODE] Just comes up with Nil[/QUOTE] Make sure you are using Player:getDarkRPVar("money") to retrieve money.
Try using [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/GetMaxHealth]Entity:GetMaxHealth[/url] if you want the bar to accurately represent the fraction of the player's health
[QUOTE=MPan1;51657878]Try using [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/GetMaxHealth]Entity:GetMaxHealth[/url] if you want the bar to accurately represent the fraction of the player's health[/QUOTE] Normally, health bars are just capped to display up to 100, so doing so would probably confuse players UNLESS the server purposely has it set like that.
I used this code for my HUD [code]table.insert( text, {"Wallet: $"..string.Comma((localplayer:getDarkRPVar("money"))), "icon16/money.png"} );[/code] [code] draw.SimpleText("Wallet: $"..string.Comma((localplayer:getDarkRPVar("money")))", "Wallet", 278, ScrH() -47, Color(255, 255, 255),TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) draw.SimpleText(PlayerMoney, "Wallet", 310, ScrH() -55, Color(255, 255, 255), 0, 0)[/code] Maybe this should work
Sorry, you need to Log In to post a reply to this thread.