WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Class Colored Names on Frames & No Background behind Name on Frames (https://www.wowinterface.com/forums/showthread.php?t=59097)

escodashoota 04-16-22 03:50 PM

Class Colored Names on Frames & No Background behind Name on Frames
 
Hello,

I'm trying to figure out a way I can create addons out of scripts from a addon I installed. When I use the addon however, it breaks other addons of mine which aren't very convenient. So I'd like to simply extract these two scripts from the addon; one gives Class Colours to names on the player & target frames, the other Removes the background behind the players name on the target frame.

Code for Class Coloured Names:
Lua Code:
  1. function RunClassColorsOnHealthBars()
  2. -- Включение цвета классов на полосах здоровья
  3. local UnitIsPlayer, UnitIsConnected, UnitClass, RAID_CLASS_COLORS = UnitIsPlayer, UnitIsConnected, UnitClass,
  4.     RAID_CLASS_COLORS
  5. local _, class, c
  6. local function colour(statusbar, unit)
  7.     if UnitIsPlayer(unit) and UnitIsConnected(unit) and unit == statusbar.unit and UnitClass(unit) then
  8.         _, class = UnitClass(unit)
  9.         c = CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS[class] or RAID_CLASS_COLORS[class]
  10.         statusbar:SetStatusBarColor(c.r, c.g, c.b)
  11.     end
  12. end
  13. hooksecurefunc("UnitFrameHealthBar_Update", colour)
  14. hooksecurefunc("HealthBar_OnValueChanged", function(self)
  15.     colour(self, self.unit)
  16. end)
  17. end


Code for removing bar behind the target frame name:
Lua Code:
  1. function RunBlackNameBackground()
  2. -- Изменяет бэкграунд на фреймах таргета и фокуса
  3. hooksecurefunc("TargetFrame_CheckFaction",
  4. function(self)
  5.     self.nameBackground:SetVertexColor(0.0, 0.0, 0.0, 0.01);
  6. end)
  7. end

Any idea on how I can make these into addons?


SDPhantom 04-17-22 01:11 AM

A quick and easy way is to copy/paste the code into addon.bool.no. You may have to open the .toc file in something like Notepad after you extract everything and make sure the Interface# is correct for your game client.
  • 90200 for Retail
  • 20504 for BCC
  • 11402 for Classic Era/SoM

escodashoota 04-17-22 04:38 AM

Quote:

Originally Posted by SDPhantom (Post 340520)
A quick and easy way is to copy/paste the code into addon.bool.no. You may have to open the .toc file in something like Notepad after you extract everything and make sure the Interface# is correct for your game client.
  • 90200 for Retail
  • 20504 for BCC
  • 11402 for Classic Era/SoM

i used this website and made sure the interface # was correct, but it wasn't working after logging in.

SDPhantom 04-21-22 01:38 PM

You need to either remove the function enclosures or call them. I suggest removing them since the functions hooked already exist on load.
Lua Code:
  1. -- Включение цвета классов на полосах здоровья
  2. hooksecurefunc("HealthBar_OnValueChanged",function(self)
  3.     local unit=self.unit;
  4.     if UnitIsPlayer(unit) and UnitIsConnected(unit) then
  5.         local _,class=UnitClass(unit);
  6.         if class then
  7.             self:SetStatusBarColor(ColorMixin.GetRGB(CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS[class] or RAID_CLASS_COLORS[class]));
  8.         end
  9.     end
  10. end);
  11.  
  12. -- Изменяет бэкграунд на фреймах таргета и фокуса
  13. hooksecurefunc("TargetFrame_CheckFaction",function(self)
  14.     self.nameBackground:SetVertexColor(0.0, 0.0, 0.0, 0.01);
  15. end);

PS: I cleaned up the code some. Hooking UnitFrameHealthBar_Update() was unnecessary as it ended up triggering HealthBar_OnValueChanged() anyway. Also while RAID_CLASS_COLORS inherits ColorMixin, CUSTOM_CLASS_COLORS isn't so clearly defined as it's not a Blizzard variable. This is why :GetRGB() is called from ColorMixin instead of the color tables. Note '.' was used instead of ':' so the color table could be given to the function as a reference instead of it trying to take ColorMixin as self.

Vremon 05-09-22 01:10 AM

Quote:

Originally Posted by SDPhantom (Post 340537)
You need to either remove the function enclosures or call them. I suggest removing them since the functions hooked already exist on load.
Lua Code:
  1. -- Включение цвета классов на полосах здоровья
  2. hooksecurefunc("HealthBar_OnValueChanged",function(self)
  3.     local unit=self.unit;
  4.     if UnitIsPlayer(unit) and UnitIsConnected(unit) then
  5.         local _,class=UnitClass(unit);
  6.         if class then
  7.             self:SetStatusBarColor(ColorMixin.GetRGB(CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS[class] or RAID_CLASS_COLORS[class]));
  8.         end
  9.     end
  10. end);
  11.  
  12. -- Изменяет бэкграунд на фреймах таргета и фокуса
  13. hooksecurefunc("TargetFrame_CheckFaction",function(self)
  14.     self.nameBackground:SetVertexColor(0.0, 0.0, 0.0, 0.01);
  15. end);

PS: I cleaned up the code some. Hooking UnitFrameHealthBar_Update() was unnecessary as it ended up triggering HealthBar_OnValueChanged() anyway. Also while RAID_CLASS_COLORS inherits ColorMixin, CUSTOM_CLASS_COLORS isn't so clearly defined as it's not a Blizzard variable. This is why :GetRGB() is called from ColorMixin instead of the color tables. Note '.' was used instead of ':' so the color table could be given to the function as a reference instead of it trying to take ColorMixin as self.

hello i try iy aswell the script with healthbar change but its look like the bar at some point its change bacj to green or sometime its appear green not class color and after changes the color ,for target and focus frames does that any othet way to fix this?

SDPhantom 05-09-22 01:03 PM

Strange, it works fine for me.


All times are GMT -6. The time now is 05:27 PM.

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