Let's try something a bit simpler first, see if we can narrow down the error. I can't login to WoW these days, so dry coding can be a pain.
Code:
local color
local pType, pToken, altR, altG, altB = UnitPowerType(unit)
local pCur, pMax = Power(unit), MaxPower(unit)
if (pMax > 0) then
if PitBull4.PowerColors[pToken] then
color = PitBull4.PowerColors[pToken]
else
if (altR == nil) then
color = PitBull4.PowerColors["MANA"]
else
color = {[1] = altR, [2] = altG, [3] = altB}
end
end
return "|cff%02x%02x%02x%s", color[1]*255, color[2]*255, color[3]*255, Short(pCur, true)
end
The only events you should need are:
UNIT_POWER
UNIT_DISPLAYPOWER