WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   Help with an Addon Nameplate (https://www.wowinterface.com/forums/showthread.php?t=57651)

Ayacoz 11-01-19 04:52 AM

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)

SDPhantom 11-01-19 08:29 AM

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);

Ayacoz 11-01-19 08:49 AM

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

Quote:

Originally Posted by SDPhantom (Post 334474)
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);


Ayacoz 11-01-19 11:03 AM

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 !

Quote:

Originally Posted by SDPhantom (Post 334474)
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);


SDPhantom 11-01-19 09:26 PM

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

Ayacoz 11-02-19 06:02 AM

1 Attachment(s)
It worked perfectly!

Thanks you so much =D

Quote:

Originally Posted by SDPhantom (Post 334478)
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



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

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