First of all, let's put that code in a [code] tag so it's nice to read:
Code:
oUF.Tags.Events['curhp'] = 'UNIT_HEALTH UNIT_MAXHEALTH'
oUF.Tags.Methods['curhp'] = function(unit)
local r,g,b = gradient(UnitHealth(unit)/UnitHealthMax(unit))
return format('|cff%02x%02x%02x %s |cffFFFFFF | |r|cff%02x%02x%02x%d%%|r',
r, g, b, numberize(UnitHealth(unit)),
r, g, b, floor((UnitHealth(unit)/UnitHealthMax(unit))*1000)/10)
end
Now, the part I highlighted in orange is what's causing your error.
UnitHealthMax can return 0, and we all know dividing by 0 causes black holes.
While you're fixing that, you should also use some variables to avoid having to call
UnitHealth and
UnitHealthMax multiple times, since function calls are Very Slow:
Code:
oUF.Tags.Events['curhp'] = 'UNIT_HEALTH UNIT_MAXHEALTH'
oUF.Tags.Methods['curhp'] = function(unit)
local hp, hpMax = UnitHealth(unit), UnitHealthMax(unit)
if hpMax == 0 then return end
local hpPercent = hp / hpMax
local r,g,b = gradient(hpPercent)
return format('|cff%02x%02x%02x %s |cffFFFFFF | |r|cff%02x%02x%02x%d%%|r',
r, g, b, numberize(hp),
r, g, b, floor(hpPercent * 1000) / 10
)
end