Hud Changing after past 65

i am trying to make a hud that changes color when it goes under 65 from green to orange but how to do it

far i know how to make a hud that just goes down in 1 color but how to make it whit 2 colors so it changes?

this is the hole code i used:

function hidehud( name )
for k, v in pairs{“CHudHealth”, “CHudBattery”} do
if name == v then return false end
end
end
hook.Add(“HUDShouldDraw”, “hidehud”, hidehud)

function GM:HUDPaint()

self.BaseClass:HUDPaint()

local person = LocalPlayer()
local health = LocalPlayer():Health()

surface.CreateFont("coolvetica", 64,400,false,false,"dunchebag")

if Health < (65) then
surface.SetTextColor( 0, 255, 0, 255 )

elseif Health > (65) then
surface:SetTextColor( 255. 255, 0, 255 )
end

surface.SetTextPos( 34, (ScrH()/2)+(ScrH()/4))
surface.SetFont("dunchebag")
surface.DrawText ( HP: + Health )

end

a litel help shut be good

You need to call pairs, as it is a function.

for k,v in pairs({“CHudHealth”, “CHudBattery”}) do

For the rest I can’t make out what you’re saying.

oh and Lua is case sensitive, so wherever you have Health, it should be the same name as the variable, which is health.

CapsAdmin: !lua for k,v in pairs{“hello”, “world”} do print(v) end
hello
world

It is still a function though, funnily enough (Even though that works)


15:48:56 > print(type(pairs))...
         function

Yeah I was just showing him you don’t always need () around it if you have brackets and so on around it.

So that is not the problem.

But I do agree with dave on the confusion. I don’t know what the hell MrMiniRazor wants.

He’s drawing some text, he wants the text to change colour when the player is injured.

[lua]function hidehud( name )
for k, v in pairs{“CHudHealth”, “CHudBattery”} do
if name == v then return false end
end
end
hook.Add(“HUDShouldDraw”, “hidehud”, hidehud)

surface.CreateFont(“coolvetica”, 64,400,false,false,“dunchebag”)

function GM:HUDPaint()

self.BaseClass:HUDPaint()

local person = LocalPlayer()
local health = LocalPlayer():Health()

surface.SetTextColor(80 , math.max( 0 , LocalPlayer():Health() * 2.5) , 0 , 255)

surface.SetTextPos( 34, (ScrH()/2)+(ScrH()/4))
surface.SetFont("dunchebag")
surface.DrawText ( "HP: "..health )

end[/lua]

You don’t need to make a font every frame.

PLEASE don’t make a font every frame.

Thanks for all the support what shut i have done whit out your guys :smiley:

Go to the wiki probably. Some trial and error also helps.

i was on wiki did not help that mush :frowning: but then i used FacePunch :stuck_out_tongue: