Quantcast LUA for HP % on Nameplates? - WoWInterface
Thread Tools Display Modes
05-25-18, 12:10 AM   #1
Xancepants
A Deviate Faerie Dragon
Join Date: Oct 2014
Posts: 15
LUA for HP % on Nameplates?

Hello all!
I've come across this bit of code that puts the % of HP in the center of Nameplates. However, now it starts throwing major errors when you try to type anything in chat and it seems to cause an infinite taint. I was wondering if anybody might know of a way to fix this bit of code so that it works with todays version of WoW? Or possibly even come up with a new way to achieve this? Any help is appreciated, and thank you in advance!


Here is the Lua:

Lua Code:
  1. CreateFrame('frame'):SetScript('OnUpdate', function(self, elapsed)
  2.   for index = 1, select('#', WorldFrame:GetChildren()) do
  3.         local f = select(index, WorldFrame:GetChildren())
  4.         if f:GetName() and f:GetName():find('NamePlate%d') then
  5.           f.h = select(1, select(1, f:GetChildren()):GetChildren())
  6.           if f.h then
  7.          if not f.h.v then
  8.            f.h.v = f.h:CreateFontString(nil, "ARTWORK")  
  9.            f.h.v:SetPoint("CENTER", 5, 0)
  10.            f.h.v:SetFont(STANDARD_TEXT_FONT, 9, 'OUTLINE')
  11.          else
  12.            local _, maxh = f.h:GetMinMaxValues()
  13.            local val = f.h:GetValue()
  14.            f.h.v:SetText(string.format(math.floor((val/maxh)*100)).." %")
  15.          end
  16.           end
  17.         end
  18.   end
  19. end)



Here is the Error that Bug Sack is logging:

2269x Custom Settings\Custom Settings.lua:88: Attempt to access forbidden object from code tainted by an AddOn
[C]: in function `GetName'
Custom Settings\Custom Settings.lua:88: in function <Custom Settings\Custom Settings.lua:85>

Locals:
(*temporary) = <unnamed> {
0 = <userdata>
}
  Reply With Quote
05-25-18, 12:58 AM   #2
thomasjohnshannon
A Cyclonian
 
thomasjohnshannon's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 44
That code is pre legion nameplates it won't work anymore.
__________________
Thomas aka Urnn
  Reply With Quote
05-25-18, 06:57 AM   #3
Xancepants
A Deviate Faerie Dragon
Join Date: Oct 2014
Posts: 15
Yea I figured as much... However the code does still work (technically). The HP% still appears on the nameplates, but whenever you try to type anything in chat, it starts having a meltdown and throwing errors infinitely.

I was hoping someone out there could come up with a new bit of code that does the same thing, but will work with new Legion Nameplates? If I find a solution before then, I'll be sure to post it up here!
  Reply With Quote
05-25-18, 07:19 AM   #4
Ammako
A Cobalt Mageweaver
 
Ammako's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 208
http://www.wowinterface.com/forums/s...ad.php?t=56125

Also I should have told you earlier, but this kind of stuff should be going in General Authoring Discussion or Lua/XML Help.

This is the hack I use for this if you would ever be interested:

lua Code:
  1. hooksecurefunc("CompactUnitFrame_UpdateHealth", function(frame)
  2.     if frame.optionTable.colorNameBySelection and not frame:IsForbidden() then
  3.         local healthPercentage = ceil((UnitHealth(frame.displayedUnit) / UnitHealthMax(frame.displayedUnit) * 100))
  4.  
  5.         if not frame.health then
  6.             frame.health = CreateFrame("Frame", nil, frame)
  7.             frame.health:SetSize(170,16)
  8.             frame.health.text = frame.health.text or frame.health:CreateFontString(nil, "OVERLAY")
  9.             frame.health.text:SetAllPoints(true)
  10.             frame.health:SetFrameStrata("HIGH")
  11.             frame.health:SetPoint("CENTER", frame.healthBar)
  12.             frame.health.text:SetVertexColor(1, 1, 1)
  13.         end
  14.  
  15.         if InterfaceOptionsNamesPanelUnitNameplatesMakeLarger:GetValue() == "1" then
  16.             frame.health.text:SetFont("FONTS\\FRIZQT__.TTF", 11, "OUTLINE")
  17.         else
  18.             frame.health.text:SetFont("FONTS\\FRIZQT__.TTF", 8, "OUTLINE")
  19.         end
  20.  
  21.         frame.health.text:Show()
  22.         frame.health.text:SetText(healthPercentage .. "%")
  23.     end
  24. end)
__________________
█████████████
█████████████
█████████████
█████████████

Last edited by Ammako : 05-25-18 at 08:03 AM.
  Reply With Quote
05-25-18, 06:17 PM   #5
Xancepants
A Deviate Faerie Dragon
Join Date: Oct 2014
Posts: 15
Once again, you are awesome Thank you Ammako! And I will be sure to post Lua questions in the correct area on the forums, thank you for the heads up!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » LUA for HP % on Nameplates?

Thread Tools
Display Modes

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