Quantcast WoWInterface - View Single Post - Help with an Addon Nameplate
View Single Post
11-01-19, 11:03 AM   #4
Ayacoz
A Murloc Raider
Join Date: Nov 2019
Posts: 4
It worked at some way, i liked it, but if there's an option to add the percent like mine, i'll be glad, i tried so hard here and realized that i suck at it, can you take a look ?

**frame.health.text:SetText(UnitHealth(frame.unit).. "-" .. healthPercentage .. "%") -- Update health numbers + percentages (player.)

Thanks !

Originally Posted by SDPhantom View Post
Here's what I do on mine. It hooks NameplateDriverFrame:OnNamePlateCreated() when it creates nameplates and CompactUnitFrame_UpdateHealth() to update. I also store a mapping between the unitframe and the text to prevent collisions with other addons or future additions from Blizzard.
Lua Code:
  1. local NamePlateHealthText={};
  2. hooksecurefunc(NamePlateDriverFrame,"OnNamePlateCreated",function(self,base)--  Hook Nameplate creation
  3.     local unitframe=base.UnitFrame;
  4.  
  5.     local health=unitframe.healthBar:CreateFontString(nil,"OVERLAY");
  6.     health:SetFont("Fonts\\ArialN.ttf",10,"THICKOUTLINE");--    Fonts are easier to read when made from scratch rather than resizing an inherited one
  7.     health:SetPoint("LEFT");
  8.     health:SetTextColor(0,1,0);
  9.  
  10.     NamePlateHealthText[unitframe]=health;
  11. end);
  12.  
  13. hooksecurefunc("CompactUnitFrame_UpdateHealth",function(self)-- This is a shared function with other UnitFrames
  14.     if NamePlateHealthText[self] then NamePlateHealthText[self]:SetText(UnitHealth(self.displayedUnit)); end
  15. end);
  Reply With Quote