Thread Tools Display Modes
07-13-14, 11:58 AM   #1
shoegum
A Defias Bandit
Join Date: Apr 2014
Posts: 3
Player in HP% & Target HP in CurrentHP/HP%

Hello,

I am trying to combine these two functions. I would like the player frame to follow the first function, which has the health displayed as a percent value. I would like the target frame to follow the second function, which has the health displayed as current health + percent value.

How can these be combined so Player Frame receives the "percent function" and Target/Focus Frames receive the "current health + percent function"? If someone coule help right it and rename the new format if (GhettoFramesSaveX.hformat==2) This is because the only way I know how to change format is thru the config menu provided by the author's original work.

The lua code has been pulled from the addon Ghetto Frames.

If Framelist = {"Target", "Focus", "Player"} could be separated so Function A effects "Target/Focus" and Function B effects "Player"

Percent Function Code:
  1. if (GhettoFramesSaveX.hformat==1) then--percent
  2.         FrameList = {"Target", "Focus", "Player"}
  3.          function UpdateHealthValues(...)
  4.         for i = 1, select("#", unpack(FrameList)) do
  5.             local FrameName = (select(i, unpack(FrameList)))
  6.             if (0 < UnitHealth(FrameName)) then
  7.                 local Health = UnitHealth(FrameName)
  8.                 local HealthMax = UnitHealthMax(FrameName)
  9.                 local HealthPercent = (UnitHealth(FrameName)/UnitHealthMax(FrameName))*100
  10.                 _G[FrameName.."FrameHealthBar"].TextString:SetText(format("%.0f",HealthPercent).."%")
  11.            
  12.             end
  13.         end
  14.  end
  15.  
  16.          hooksecurefunc("TextStatusBar_UpdateTextStringWithValues", UpdateHealthValues)
  17.  
  18.  
  19.    end

Current Health + Percent Function Code:
  1. if (GhettoFramesSaveX.hformat==3) then --currenthealth + percent
  2.    FrameList = {"Target", "Focus", "Player"}
  3.          function UpdateHealthValues(...)
  4. for i = 1, select("#", unpack(FrameList)) do
  5. local FrameName = (select(i, unpack(FrameList)))
  6.        if (0 < UnitHealth(FrameName)) then
  7.        if UnitHealth(FrameName) < 1000 then
  8.             local Health = UnitHealth(FrameName)
  9.             local HealthMax = UnitHealthMax(FrameName)
  10.             local HealthPercent = (UnitHealth(FrameName)/UnitHealthMax(FrameName))*100
  11.             _G[FrameName.."FrameHealthBar"].TextString:SetText(Health.." ("..format("%.0f",HealthPercent).."%)")
  12.         elseif (UnitHealth(FrameName) < 1000000) then
  13.             local Health = (UnitHealth(FrameName))/1000
  14.             local HealthMax = (UnitHealthMax(FrameName))/1000
  15.             local HealthPercent = (UnitHealth(FrameName)/UnitHealthMax(FrameName))*100
  16.             _G[FrameName.."FrameHealthBar"].TextString:SetText(format("%.0f",Health).."k ("..format("%.0f",HealthPercent).."%)")
  17.         elseif (1000000<=UnitHealth(FrameName)) then
  18.             local Health = (UnitHealth(FrameName))/1000000
  19.             local HealthMax = (UnitHealthMax(FrameName))/1000000
  20.             local HealthPercent = (UnitHealth(FrameName)/UnitHealthMax(FrameName))*100
  21.             _G[FrameName.."FrameHealthBar"].TextString:SetText(format("%.0f",Health).."m ("..format("%.0f",HealthPercent).."%)")
  22.         end      
  23. end
  24. end
  25. end
  26. hooksecurefunc("TextStatusBar_UpdateTextStringWithValues", UpdateHealthValues)
  27. end

Last edited by shoegum : 07-13-14 at 12:47 PM.
  Reply With Quote
07-13-14, 12:44 PM   #2
shoegum
A Defias Bandit
Join Date: Apr 2014
Posts: 3
Would this work?

Lua Code:
  1. FrameList = {"Player"}
  2.          function UpdateHealthValues(...)
  3.         for i = 1, select("#", unpack(FrameList)) do
  4.             local FrameName = (select(i, unpack(FrameList)))
  5.             if (0 < UnitHealth(FrameName)) then
  6.                 local Health = UnitHealth(FrameName)
  7.                 local HealthMax = UnitHealthMax(FrameName)
  8.                 local HealthPercent = (UnitHealth(FrameName)/UnitHealthMax(FrameName))*100
  9.                 _G[FrameName.."FrameHealthBar"].TextString:SetText(format("%.0f",HealthPercent).."%")
  10.            
  11.             end
  12.         end
  13.  end
  14.         FrameList = {"Target", "Focus"}
  15.     function UpdateHealthValues(...)
  16.         for i = 1, select("#", unpack(FrameList)) do
  17.             local FrameName = (select(i, unpack(FrameList)))
  18.             if (0 < UnitHealth(FrameName)) then
  19.             if UnitHealth(FrameName) < 1000 then
  20.                 local Health = UnitHealth(FrameName)
  21.                 local HealthMax = UnitHealthMax(FrameName)
  22.                 local HealthPercent = (UnitHealth(FrameName)/UnitHealthMax(FrameName))*100
  23.                 _G[FrameName.."FrameHealthBar"].TextString:SetText(Health.." ("..format("%.0f",HealthPercent).."%)")
  24.         elseif (UnitHealth(FrameName) < 1000000) then
  25.             local Health = (UnitHealth(FrameName))/1000
  26.             local HealthMax = (UnitHealthMax(FrameName))/1000
  27.             local HealthPercent = (UnitHealth(FrameName)/UnitHealthMax(FrameName))*100
  28.             _G[FrameName.."FrameHealthBar"].TextString:SetText(format("%.0f",Health).."k ("..format("%.0f",HealthPercent).."%)")
  29.         elseif (1000000<=UnitHealth(FrameName)) then
  30.             local Health = (UnitHealth(FrameName))/1000000
  31.             local HealthMax = (UnitHealthMax(FrameName))/1000000
  32.             local HealthPercent = (UnitHealth(FrameName)/UnitHealthMax(FrameName))*100
  33.             _G[FrameName.."FrameHealthBar"].TextString:SetText(format("%.0f",Health).."m ("..format("%.0f",HealthPercent).."%)")
  34.         end      
  35. end
  36. end
  37. end
  38. hooksecurefunc("TextStatusBar_UpdateTextStringWithValues", UpdateHealthValues)
  39. end

Edit: After setting this to option #2. It works with no errors in bug-sack.

The player health first appeared as Current Health/Total Health; but going into the game menu Esc>Interface>Status Text>Drop Down Menu then set to Percentage the unit frames are showing up exactly how I want. The player frame is shown just as a Percentage while my Target and Focus frames are showing Current Health/Percentage.

If anyone can confirm this I would greatly appreciate it as I have no knowledge of coding and just cut and pasted what I thought was reasonable.

Last edited by shoegum : 07-13-14 at 12:53 PM.
  Reply With Quote
07-13-14, 07:05 PM   #3
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Well, if it works, it works. What do you want confirmed? :P There are definitely ways to make that code better, though, but first; have you tried the "percent + absolute" option in interface options? It would be easier to modify the player frame to use only percentage and let the existing code handle the rest, than the other way around, if that works for you.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
07-13-14, 08:37 PM   #4
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
You could do something like this..
Lua Code:
  1. local caps = {'k', 'm', 'b', 't'}
  2. hooksecurefunc('TextStatusBar_UpdateTextStringWithValues', function(f, text, value, _, maxValue)
  3.     if f == PlayerFrameHealthBar then
  4.         text:SetFormattedText('%.0f%%', value / maxValue * 100)
  5.     elseif f == TargetFrameHealthBar or f == FocusFrameHealthBar then
  6.         local breaks = min(#caps, floor((strlen(value) - 1) / 3))
  7.         text:SetFormattedText('%.0f%s (%.0f%%)', value / 1000 ^ breaks, breaks > 0 and caps[breaks] or '', value / maxValue * 100)
  8.     end
  9. end)

Last edited by semlar : 07-13-14 at 08:43 PM.
  Reply With Quote
07-15-14, 06:18 PM   #5
shoegum
A Defias Bandit
Join Date: Apr 2014
Posts: 3
Hey great ideas. Thank you so very much.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Player in HP% & Target HP in CurrentHP/HP%


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off