View Single Post
03-12-14, 02:57 PM   #20
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Statusbar Text

the following code was supplied by Phanx but I was wondering if there is a way to make it do the following.


Full Health = 345K
Full Mana = 160K
Not Full Health = 160K/345K
Not Full Mana = 80K/160K

Code Supplied by Phanx:
Lua Code:
  1. local shorts = {
  2.     { 1e10, 1e9, "%.0fb" }, --  10b+ as  12b
  3.     {  1e9, 1e9, "%.1fb" }, --   1b+ as 8.3b
  4.     {  1e7, 1e6, "%.0fm" }, --  10m+ as  14m
  5.     {  1e6, 1e6, "%.1fm" }, --   1m+ as 7.4m
  6.     {  1e5, 1e3, "%.0fk" }, -- 100k+ as 840k
  7.     {  1e3, 1e3, "%.1fk" }, --   1k+ as 2.5k
  8.     {    0,   1,    "%d" }, -- < 1k  as  974
  9. }
  10. for i = 1, #shorts do
  11.     shorts[i][4] = shorts[i][3] .. " (%.0f%%)"
  12. end
  13.  
  14. hooksecurefunc("TextStatusBar_UpdateTextStringWithValues", function(statusBar, fontString, value, valueMin, valueMax)
  15.     if value == 0 then
  16.         return fontString:SetText("")
  17.     end
  18.  
  19.     local style = GetCVar("statusTextDisplay")
  20.     if style == "PERCENT" then
  21.         return fontString:SetFormattedText("%.0f%%", value / valueMax * 100)
  22.     end
  23.     for i = 1, #shorts do
  24.         local t = shorts[i]
  25.         if value >= t[1] then
  26.             if style == "BOTH" then
  27.                 return fontString:SetFormattedText(t[4], value / t[2], value / valueMax * 100)
  28.             else
  29.                 return fontString:SetFormattedText(t[3], value / t[2])             
  30.             end
  31.         end
  32.     end
  33. end)

Thank in advance for any help.
Coke
  Reply With Quote