View Single Post
11-07-08, 06:27 AM   #221
Slakah
A Molten Giant
 
Slakah's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 863
Originally Posted by saulhudson View Post
Hi guys

How can I colour the health text value by there health status.

So for say 2890 hp or 30% make the text red. Not the bar colour but the text itself.

I currently basically do this atm.

bar.value:SetText("|cff33EE44"..numberize(cur) .."|r.".. d.."%")

Which is Lyns code giving something like this 5000.50%.

Any help greatlt appreciated.
Stick this at the top of your layout somewhere.

Code:
local function ColourGradient(perc) -- for colouring in
	if perc <= 0.5 then
		return 255, perc*510, 0
	else
		return 510 - perc*510, 255, 0
	end
end
and then replace
Code:
bar.value:SetText("|cff33EE44"..numberize(cur) .."|r.".. d.."%")
with
Code:
bar.value:SetText(string.format("|cff%02x%02x%02x%s|r.%s%%", ColourGradient(min/max), numberize(cur), d)
Hope this helps.