Originally Posted by hikokun
I'm looking for a custom lua code to show curhp/maxhp followed by perchp with two decimals for Stuf Unit Frames. The current code I'm using which only shows perchp with two decimals -
Code:
function(unit, cache, textframe)
if UnitExists(unit) then
local perchp = 100 * UnitHealth(unit)/UnitHealthMax(unit)
return "%.2f%%",perchp
else
local perchp = 100 * UnitHealth("player")/UnitHealthMax("player")
return "%.2f%%",perchp
end
end
I'd like a code for both of the following setups if possible
300000/500000 | 60.00%
60.00% | 300000/500000
Thanks for any help!
|
I think i fount a solution, try to replace your function with this one:
Lua Code:
function(unit, cache, textframe)
if UnitExists(unit) then
local curhp = UnitHealth(unit)
local maxhp = UnitHealthMax(unit)
local perchp = 100 * curhp/maxhp
local stamp = curhp.." / "..maxhp.." | ".."%.2f%%"
return stamp,perchp
else
local curhp = UnitHealth("player")
local maxhp = UnitHealthMax("player")
local perchp = 100 * curhp/maxhp
local stamp = curhp.." / "..maxhp.." | ".."%.2f%%"
return stamp,perchp
end
end
Or cleaner:
Lua Code:
function(unit, cache, textframe)
local curhp, maxhp
if UnitExists(unit) then
curhp = UnitHealth(unit)
maxhp = UnitHealthMax(unit)
else
curhp = UnitHealth("player")
maxhp = UnitHealthMax("player")
end
local perchp = 100 * curhp/maxhp
local stamp = curhp.." / "..maxhp.." | ".."%.2f%%"
return stamp,perchp
end