• Colour changing health bar And Ammo bar not fully Working
    8 replies, posted
Hiya i have just starting lua coding about 3 weeks ago and i have been working on a simple hud for some time now and i have been trying to make it change the colour of the health bar when the player takes damage but i cant get it to work however with the ammo bar i got it to work a little but the blue bar does not go all the way. Picture of the hud [URL="https://gyazo.com/0be6ea46760b014282db1c5d1e682ea0"]https://gyazo.com/0be6ea46760b014282db1c5d1e682ea0[/URL] [CODE]hook.Add( "HUDPaint", "DrawMyHud", function() client = client or LocalPlayer( ); if( !client:Alive( ) ) then return; end local ply = LocalPlayer() if !ply:Alive() then return end if(ply:GetActiveWeapon() == NULL or ply:GetActiveWeapon() == "Camera") then return end local health = LocalPlayer():Health() local weapon = LocalPlayer():GetActiveWeapon():Clip1() local weapon2 = LocalPlayer():GetAmmoCount(LocalPlayer():GetActiveWeapon():GetPrimaryAmmoType()) local armor = LocalPlayer():Armor() --Health draw.RoundedBox(0,8,ScrH() - 100,300 + 4 ,30 + 4,Color(40,40,40)) draw.RoundedBox(0,10,ScrH() - 98,health * 3,30,Color(255,120,120)) draw.SimpleText(health.."%","font",10 + 150,ScrH() - 84,Color(255,255,255),1,1) draw.RoundedBox(5,3,ScrH() - 105,312 + 2.5,95,Color(30 ,30 ,30 ,190)) --Armor draw.RoundedBox(0,8,ScrH() - 50,300 + 4 ,30 + 4,Color(40,40,40)) draw.RoundedBox(0,10,ScrH() - 49,armor * 3,30,Color(0,120,240)) draw.SimpleText(armor.."%","font",10 + 150,ScrH() - 35,Color(255,255,255),1,1) -- Ammo surface.SetDrawColor(40,40,40,255) surface.DrawRect(1020,ScrH() - 35,280,20) surface.SetDrawColor(0,51,255,255) surface.DrawRect(1022,ScrH() - 33,weapon * 6.15,16) surface.SetTextColor(255,255,255,255) surface.SetTextPos(80 + 1010,ScrH() - 36) surface.SetFont("font") surface.DrawText("Ammo: "..weapon.."/"..weapon2) end) -- Hide Original Hud -- function hidehud(name) for k, v in pairs({"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo"}) do if name == v then return false end end end hook.Add("HUDShouldDraw", "HideOurHud:D", hidehud)[/CODE] Thanks you for reading this!
do [CODE]var1 = Color(10,255,10,255)[/CODE] and replace your health bars current color with that variable make an if statement that changes the color of your health bar if the player takes damage then set [CODE]var1 = Color(255,10,10,255)[/CODE]
[QUOTE=Thane;50611081]do [CODE]var1 = Color(10,255,10,255)[/CODE] and replace your health bars current color with that variable make an if statement that changes the color of your health bar if the player takes damage then set [CODE]var1 = Color(255,10,10,255)[/CODE][/QUOTE] Sorry thane but i dont really know were to put the variable or what the if statement should look like.
[QUOTE=Detxer99235;50611189]Sorry thane but i dont really know were to put the variable or what the if statement should look like.[/QUOTE] doesn't matter where you put the variable just put it under your other variables. although I don't know what to put directly after the if statement I know what it should look like. Maybe someone else on here can help. the if statement should be [CODE]if something then var1 = Color(255,10,10,255) end[/CODE]
But what do i put in the draw.RoundedBox(0,10,ScrH() - 98,health * 3,30,Color(255,10,10,255))
[QUOTE=Detxer99235;50611340]But what do i put in the draw.RoundedBox(0,10,ScrH() - 98,health * 3,30,Color(255,10,10,255))[/QUOTE] Just change it to this [CODE]draw.RoundedBox(0,10,ScrH() - 98,health * 3,30,var1)[/CODE]
[QUOTE=Thane;50611345]Just change it to this [CODE]draw.RoundedBox(0,10,ScrH() - 98,health * 3,30,var1)[/CODE][/QUOTE] [CODE]if LocalPlayer():Health() == LocalPlayer():Health(60) then var1 = Color(255,10,10,255) else var1 = Color(0,255,0,255) end --Health draw.RoundedBox(0,8,ScrH() - 100,300 + 4 ,30 + 4,Color(40,40,40)) draw.RoundedBox(0,10,ScrH() - 98,health * 3,30,var1) draw.SimpleText(health.."%","font",10 + 150,ScrH() - 84,Color(255,255,255),1,1) draw.RoundedBox(5,3,ScrH() - 105,312 + 2.5,95,Color(30 ,30 ,30 ,190)) [/CODE] No is does not work still i want it to go green to red if the health is below 20
[QUOTE=Detxer99235;50611380][CODE]if LocalPlayer():Health() == LocalPlayer():Health(60) then var1 = Color(255,10,10,255) else var1 = Color(0,255,0,255) end --Health draw.RoundedBox(0,8,ScrH() - 100,300 + 4 ,30 + 4,Color(40,40,40)) draw.RoundedBox(0,10,ScrH() - 98,health * 3,30,var1) draw.SimpleText(health.."%","font",10 + 150,ScrH() - 84,Color(255,255,255),1,1) draw.RoundedBox(5,3,ScrH() - 105,312 + 2.5,95,Color(30 ,30 ,30 ,190)) [/CODE] No is does not work still i want it to go green to red if the health is below 20[/QUOTE] [CODE]if health < 20 then var1 = Color(255,10,10,255) else var1 = Color(0,255,0,255) end[/CODE]
Yesss, Thanks you sooo much!! one day i will repay the favor
Sorry, you need to Log In to post a reply to this thread.