Page 1 of 1

PitBull4 : LUA Text Health color

PostPosted: Thu Apr 14, 2011 11:52 pm
by Ezharon
I'd like to change my health text color according to my health level. Does anybody know how to do this with LUA Text?

Re: PitBull4 : LUA Text Health color

PostPosted: Thu Apr 28, 2011 7:46 pm
by Raeli
Code: Select all
local cur,max = HP(unit), MaxHP(unit)
local diff = max-cur
local pct = cur/max
local color = 0
if pct == 1.0 or pct == 0.0 then
    color = 0xFFFFFF
elseif ( pct <= 0.50 ) then
    color = 0xFF0030 + floor(pct*255)*512
else
    color = 0x10FF30 + floor((1-pct)*235)*(131072)
end
return "|cff%x%s%%", color, Percent(cur,max)


White if 100% or 0%. Green to Red as health percent goes down.

Re: PitBull4 : LUA Text Health color

PostPosted: Fri Apr 29, 2011 3:55 am
by RedAces
hey,

There's a function built-in in Pitbull for this: HPColor(cur, max)!

simple colored percentage:
Code: Select all
local cur, max = HP(unit), MaxHP(unit)
local r,g,b = HPColor(cur, max)
return "|cff%02x%02x%02x%s%%|r",r,g,b,Percent(cur,max)


Bye, RedAces.

Re: PitBull4 : LUA Text Health color

PostPosted: Fri Apr 29, 2011 3:37 pm
by Ezharon
Thanks 8)