WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   LUA for HP % on Nameplates? (https://www.wowinterface.com/forums/showthread.php?t=56239)

Xancepants 05-25-18 12:10 AM

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>
}

thomasjohnshannon 05-25-18 12:58 AM

That code is pre legion nameplates it won't work anymore.

Xancepants 05-25-18 06:57 AM

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!

Ammako 05-25-18 07:19 AM

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)

Xancepants 05-25-18 06:17 PM

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!


All times are GMT -6. The time now is 11:51 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI