Thread: Stuf LUA help
View Single Post
10-03-15, 06:24 PM   #3
Nikita S. Doroshenko
A Cyclonian
 
Nikita S. Doroshenko's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2015
Posts: 45
Originally Posted by hikokun View Post
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:
  1. function(unit, cache, textframe)
  2.     if UnitExists(unit) then
  3.         local curhp = UnitHealth(unit)
  4.         local maxhp = UnitHealthMax(unit)
  5.         local perchp = 100 * curhp/maxhp
  6.         local stamp = curhp.." / "..maxhp.." | ".."%.2f%%"
  7.         return stamp,perchp
  8.     else
  9.         local curhp = UnitHealth("player")
  10.         local maxhp = UnitHealthMax("player")
  11.         local perchp = 100 * curhp/maxhp
  12.         local stamp = curhp.." / "..maxhp.." | ".."%.2f%%"
  13.         return stamp,perchp
  14.     end
  15. end

Or cleaner:

Lua Code:
  1. function(unit, cache, textframe)
  2.     local curhp, maxhp
  3.     if UnitExists(unit) then
  4.         curhp = UnitHealth(unit)
  5.         maxhp = UnitHealthMax(unit)
  6.     else
  7.         curhp = UnitHealth("player")
  8.         maxhp = UnitHealthMax("player")
  9.     end
  10.     local perchp = 100 * curhp/maxhp
  11.     local stamp = curhp.." / "..maxhp.." | ".."%.2f%%"
  12.     return stamp,perchp
  13. end

Last edited by Nikita S. Doroshenko : 10-03-15 at 06:28 PM.
  Reply With Quote