View Single Post
09-18-09, 12:57 AM   #1189
NeverD1e
A Murloc Raider
Join Date: Aug 2008
Posts: 5
Originally Posted by NeverD1e View Post
Hello everyone, I'm bad know Lua.
Help bring the code with this:

local function truncate(value)
if(value >= 1e6) then
return gsub(format('%.2fm', value / 1e6), '%.?0+([km])$', '%1')
elseif(value >= 1e5) then
return gsub(format('%.1fk', value / 1e3), '%.?0+([km])$', '%1')
else
return value
end
end

Such:

1603022>1,603k
725622>725,6k
11813>11,8k
9156>9,1k
937>937


And with this:

oUF.TagEvents['[customstatus]'] = 'UNIT_HEALTH'
oUF.Tags['[customstatus]'] = function(unit)
return not UnitIsConnected(unit) and PLAYER_OFFLINE or UnitIsGhost(unit) and 'Ghost' or UnitIsDead(unit) and DEAD
end

oUF.TagEvents['[customhp]'] = 'UNIT_HEALTH UNIT_MAXHEALTH'
oUF.Tags['[customhp]'] = function(unit)
local status = oUF.Tags['[customstatus]'](unit)
local min, max = UnitHealth(unit), UnitHealthMax(unit)

local r,g,b = ColourGradient(min/max)

return status and status or
(unit ~= 'player' and unit ~= 'target' and min-max ~= 0) and format('|cff%02x%02x%02x%s|r', r, g, b, truncate(min-max)) or
(unit == 'target' and min - max == 0) and format('|cff%02x%02x%02x%s|r', r, g, b, truncate(max)) or
(min - max == 0) and format('%s', '') or
(unit == 'target' or unit == 'player') and format('|cff00FF00%s|r . |cff%02x%02x%02x%s|r %d%%', truncate(max), r, g, b, truncate(min), floor(min/max*100)) or
(min~=max) and format('%s |cff0090ff/|r %s', truncate(min), truncate(max)) or max
end


Such:

If player or target then
If min~=max then
show max
If max<100% then
show min | max

If targettarget or pet or focus then

If min~=max then
show max
If max<100% then
show min

If party or raid then

If min~=max then
show max
If max<100% then
show -(min-max)

I suffer for a long time, help me please.
This realy worked?

local function truncate(value)
if(value >= 1e7) then
return gsub(format('%.1fm', value / 1e6), '%.?0([km])$', '%1')
elseif(value >= 1e6) then
return gsub(format('%.2fm', value / 1e6), '%.?0+([km])$', '%1')
elseif(value >= 1e5) then
return format('%.0fk', value / 1e3)
elseif (value >= 1e3) or (value <= -1e3) then
return gsub(format('%.1fk', value / 1e3), '%.?0([km])$', '%1')
else
return value
end
end


And:

oUF.TagEvents['[customstatus]'] = 'UNIT_HEALTH'
oUF.Tags['[customstatus]'] = function(unit)
return not UnitIsConnected(unit) and 'Off' or UnitIsGhost(unit) and 'Ghost' or UnitIsDead(unit) and 'Dead'
end

oUF.TagEvents['[customhp]'] = 'UNIT_HEALTH UNIT_MAXHEALTH'
oUF.Tags['[customhp]'] = function(unit)
local status = oUF.Tags['[customstatus]'](unit)
local min, max = UnitHealth(unit), UnitHealthMax(unit)

local r,g,b = ColourGradient(min/max)

return status and status or
(unit ~= 'player' and unit ~= 'target' and min-max ~= 0) and format('|cff%02x%02x%02x%s|r', r, g, b, truncate(min-max)) or
(unit ~= 'player' and unit ~= 'target' and min-max == 0) and format('|cff%02x%02x%02x%s|r', r, g, b, truncate(max)) or
(unit == 'target' and unit == 'player' and min-max ~=0) and format('|cff%02x%02x%02x%s|r | |cff%02x%02x%02x%s|r', truncate(min), r, g, b, truncate(max)) or
(unit == 'target' and unit == 'player' and min-max ==0) and format('|cff%02x%02x%02x%s|r', r, g, b, truncate(max))
end