I trudged through the lua code for this about a week ago, so to save you the trouble, here's my code.
I'll tell you this now, this was made for a healer UI. So, i have the code placed into it to show a percent when not moused over, and scale in color as the person reach's different levels of health/mana.
First, the health:
Events that must be on - Unit_Aura, Unit_Health, Unit_Healthmax
Code:
local s = Status(unit)
local cur,max=HP(unit),MaxHP(unit)
local per=Percent(cur,max)
if s then
return s
end
if IsMouseOver() then
return "|cff009900%s|r",HP(unit),MaxHP(unit)
else
if per<10 then
return "|cffff0000%s|r",Percent(HP(unit),MaxHP(unit))
else
if per<25 then
return "|cffff5511%s|r",Percent(HP(unit),MaxHP(unit))
else
if per<50 then
return "|cffffcc33%s|r",Percent(HP(unit),MaxHP(unit))
else
return "|cff009900%s|r",Percent(HP(unit),MaxHP(unit))
end
end
end
end
Now the code for mana:
Events that must be on - Unit_DisplayPower, Unit_Energy, Unit_Focus, Unit_Mana, Unit_Maxenergy, Unit_Maxfocus, Unit_Maxrage, Unit_Maxrunic_power, Unit_Rage, Unit_Runic_Power
Code:
local s = Status(unit)
local cur,max=Power(unit),MaxPower(unit)
local per=Percent(cur,max)
if s then
return s
end
if IsMouseOver() then
return "|cff1188ff%s|r",Power(unit),MaxPower(unit)
else
if per<10 then
return "|cffff0000%s|r",Percent(Power(unit),MaxPower(unit))
else
if per<25 then
return "|cffff5511%s|r",Percent(Power(unit),MaxPower(unit))
else
if per<50 then
return "|cffffcc33%s|r",Percent(Power(unit),MaxPower(unit))
else
return "|cff009900%s|r",Percent(Power(unit),MaxPower(unit))
end
end
end
end
Edit: Noticed you wanted it to switch to name, this is very possible, in fact, here's the code(Note - For health):
Events that must be on - Player_Flags_Changed, Unit_Aura, Unit_Health, Unit_Healthmax, Unit_Name_Update
Code:
local s = Status(unit)
local cur,max=HP(unit),MaxHP(unit)
local per=Percent(cur,max)
if s then
return s
end
if IsMouseOver() then
return "|cff009900%s|r",HP(unit),MaxHP(unit)
else
return '%s %s%s%s',Name(unit),Angle(AFK(unit) or DND(unit))
end
In the odd case you want the above code for mana:
Events that must be on - Player_Flags_Changed, Unit_Aura, Unit_Name_Update, Unit_DisplayPower, Unit_Energy, Unit_Focus, Unit_Mana, Unit_Maxenergy, Unit_Maxfocus, Unit_Maxrage, Unit_Maxrunic_power, Unit_Rage, Unit_Runic_Power
Code:
local s = Status(unit)
local cur,max=Power(unit),MaxPower(unit)
local per=Percent(cur,max)
if s then
return s
end
if IsMouseOver() then
return "|cff009900%s|r",Power(unit),MaxPower(unit)
else
return '%s %s%s%s',Name(unit),Angle(AFK(unit) or DND(unit))
end
A not about colors - These are all set to my own colors. Lua uses hex based colors. To change the color to a color of your choice, refer to "|cff009900%s|r" The number's in bold must be changed to the correct hex value's. They go as such, with 2 numbers for each, Red, Green, Blue. numbers may range from 0-9, and a-f. Letters are higher value then numbers.
A quick search of google gets me http://www.december.com/html/spec/color.html i recommend that sight for all your color value finding needs.