Thread Tools Display Modes
11-01-19, 04:52 AM   #1
Ayacoz
A Murloc Raider
Join Date: Nov 2019
Posts: 5
Help with an Addon Nameplate

Here is the deal.

I Like the blizzard nameplate by default, but i would like to see the values of hp and % and the Unitnameplate

i find an simple project, that i cant remember the owner's name but its not me.

This "addon" does what i want, BUT, it shows also at the Blizzard Raid Frame, and i dont want it, can someone help me on not showing it at Raid Frame.

here's the code

hooksecurefunc("CompactUnitFrame_UpdateHealth", function(frame)

if not frame:IsForbidden() then
local healthPercentage = ceil((UnitHealth(frame.displayedUnit) / UnitHealthMax(frame.displayedUnit) * 100)) -- Calculating a percentage value for health.

if not frame.health then
frame.health = CreateFrame("Frame", nil, frame) -- Setting up health display frames.
frame.health:SetSize(170,16)
frame.health.text = frame.health.text or frame.health:CreateFontString(nil, "OVERLAY")
frame.health.text:SetAllPoints(true)
frame.health:SetFrameStrata("HIGH")
frame.health:SetPoint("CENTER", frame.healthBar)
frame.health.text:SetVertexColor(1, 1, 1)
end

if InterfaceOptionsNamesPanelUnitNameplatesMakeLarger:GetValue() == "1" then -- If 'Larger Nameplates' option is enabled.
frame.health.text:SetFont("FONTS\\FRIZQT__.TTF", 11, "OUTLINE")
else
frame.health.text:SetFont("FONTS\\FRIZQT__.TTF", 8, "OUTLINE")
end


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

end
end)
  Reply With Quote
11-01-19, 08:29 AM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
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);
__________________
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)

Last edited by SDPhantom : 11-01-19 at 08:51 AM.
  Reply With Quote
11-01-19, 08:49 AM   #3
Ayacoz
A Murloc Raider
Join Date: Nov 2019
Posts: 5
Thanks mate

i'll run some tests to see if its what i want, but it seems to be.

I'll tell you the results

Originally Posted by SDPhantom View Post
Here's what I do on mine. It hooks NameplateDriverFrame:OnNamePlateCreated() when it creates nameplates and CompactUnitFrame_UpdateHealth(). 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
11-01-19, 11:03 AM   #4
Ayacoz
A Murloc Raider
Join Date: Nov 2019
Posts: 5
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
11-01-19, 09:26 PM   #5
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
You can expand line 14 to be something like this.
Lua Code:
  1. if NamePlateHealthText[self] then
  2.     local cur,max=UnitHealth(self.displayedUnit),UnitHealthMax(self.displayedUnit);
  3.     NamePlateHealthText[self]:SetFormattedText("%d - %.0f%%",cur,100*cur/max);
  4. 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
11-02-19, 06:02 AM   #6
Ayacoz
A Murloc Raider
Join Date: Nov 2019
Posts: 5
It worked perfectly!

Thanks you so much =D

Originally Posted by SDPhantom View Post
You can expand line 14 to be something like this.
Lua Code:
  1. if NamePlateHealthText[self] then
  2.     local cur,max=UnitHealth(self.displayedUnit),UnitHealthMax(self.displayedUnit);
  3.     NamePlateHealthText[self]:SetFormattedText("%d - %.0f%%",cur,100*cur/max);
  4. end
Attached Thumbnails
Click image for larger version

Name:	WoWScrnShot_110219_090014.jpg
Views:	323
Size:	61.5 KB
ID:	9344  
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Help with an Addon Nameplate

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