View Single Post
10-27-20, 07:04 AM   #18
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,323
This is similar to what I did with my personal nameplate addon. I modified it to duplicate the layout of your existing code. If you're running this on Classic, change the first hook from AcquireUnitFrame to OnNamePlateCreated.
Lua Code:
  1. local TextObjects={};
  2.  
  3. hooksecurefunc(NamePlateDriverFrame,"AcquireUnitFrame",function(self,base)
  4.     if base:IsForbidden() then return; end
  5.  
  6.     local uf=base.UnitFrame; if TextObjects[uf] then return; end
  7.     local healthtext=uf.healthBar:CreateFontString(nil,"OVERLAY",FontName);--"NumberFontNormalSmall");
  8.     healthtext:SetPoint("RIGHT",0,0);
  9.     healthtext:SetFont(STANDARD_TEXT_FONT,12,"OUTLINE");
  10.  
  11.     TextObjects[uf]=healthtext;
  12. end);
  13.  
  14. hooksecurefunc("CompactUnitFrame_UpdateHealth",function(self)
  15.     local healthtext=TextObjects[self]; if not healthtext then return; end
  16.     if UnitIsUnit(frame.displayedUnit,"player") or not UnitIsFriend("player",frame.displayedUnit) then
  17.         healthtext:SetFormattedText("%.0f%%",100*UnitHealth(self.displayedUnit)/UnitHealthMax(self.displayedUnit));
  18.     else healthtext:SetText(nil); end
  19. end);
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote