View Single Post
03-12-14, 08:09 AM   #15
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Pet Name Color to White

I've been trying all morning to get the pet eg beast, demon, and elemental to have there names white.


At first I tried UnitIsPet(unit) but it seems that the wow api does not have that in it.

Then I went searching and found UnitCreatureType(unit) then I tried:
Lua Code:
  1. if UnitCreatureType("beast") or UnitCreatureType("demon") or UnitCreatureType("elemental") then
  2.     self.name:SetTextColor(1, 1, 1)
  3. else
  4.     self.name:SetTextColor(color.r, color.g, color.b)
  5. end

But the above code turned every name color white.

So I did more searching and found a post that had a function created for UnitIsPet so I copy/pasted the:
Lua Code:
  1. local function UnitIsPet(unit)
  2.     local guidtype = tonumber(strsub(UnitGUID(unit),5,5),16)%8
  3.     if guidtype==4 then return true end
  4.     return false
  5. end
then I changed the code to:
Lua Code:
  1. if UnitIsPet(unit) then
  2.     self.name:SetTextColor(1, 1, 1)
  3. else
  4.     self.name:SetTextColor(color.r, color.g, color.b)
  5. end

and this changes the Pet name color to White but bugsack gives me this error:
Code:
5x BasicUI-5.4.4\Modules\Unitframes\Unitframes.lua:193: bad argument #1 to "strsub" (string expected, got nil)
<in C code>
BasicUI-5.4.4\Modules\Unitframes\Unitframes.lua:193: in function <BasicUI\Modules\Unitframes\Unitframes.lua:192>
BasicUI-5.4.4\Modules\Unitframes\Unitframes.lua:220: in function <BasicUI\Modules\Unitframes\Unitframes.lua:198>
<in C code>
Blizzard_ArenaUI\Blizzard_ArenaUI.lua:275: in function "ArenaEnemyFrame_UpdatePet"
Blizzard_ArenaUI\Blizzard_ArenaUI.lua:47: in function <Blizzard_ArenaUI\Blizzard_ArenaUI.lua:25>

Locals:
unit = "arenapet1"
(*temporary) = <function> defined =[C]:-1
Im trying more and more to get this lua coding figured out.

Hopefully this is enough info for you.

If not below is the complete Unitframes.lua just in case.

Coke


Unitframes.lua:
Lua Code:
  1. local B, C, DB = unpack(select(2, ...)) -- Import:  B - function; C - config; DB - Database
  2.  
  3. if C["unitframes"].enable ~= true then return end
  4.  
  5.  
  6. -- Special Thanks to the guys over at Arena Junkies for most of these scripts
  7. -- [url]http://www.arenajunkies.com/topic/222642-default-ui-scripts/[/url]
  8.  
  9. local _G = _G
  10.  
  11.  
  12. -- Player Frame
  13. if C["unitframes"].player.enable then
  14.  
  15.     -- Frame Scale
  16.     _G["PlayerFrame"]:SetScale(C["unitframes"].player.scale);  
  17.     PlayerFrameHealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].player.fontSize,"THINOUTLINE");
  18.     PlayerFrameManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].player.fontSize, "THINOUTLINE");
  19.     PlayerFrameAlternateManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].player.fontSize, "THINOUTLINE");
  20.     PetFrameHealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].player.fontSizepet,"THINOUTLINE");
  21.     PetFrameManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].player.fontSizepet, "THINOUTLINE");
  22.  
  23. end
  24.  
  25. -- Target Frame
  26. if C["unitframes"].target.enable then
  27.  
  28.     -- Frame Scale
  29.      _G["TargetFrame"]:SetScale(C["unitframes"].target.scale);
  30.     TargetFrameTextureFrameHealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].target.fontSize, "THINOUTLINE");
  31.     TargetFrameTextureFrameManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].target.fontSize, "THINOUTLINE");
  32.  
  33. end;
  34.  
  35. -- Focus Frame
  36. if C["unitframes"].focus.enable then
  37.  
  38.     -- Frame Scale
  39.      _G["FocusFrame"]:SetScale(C["unitframes"].focus.scale)
  40.     FocusFrameTextureFrameHealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].focus.fontSize,"THINOUTLINE")
  41.     FocusFrameTextureFrameManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].focus.fontSize,"THINOUTLINE")
  42.  
  43. end;
  44.  
  45.  
  46. -- Party Frames --
  47. if C["unitframes"].party.enable then
  48.  
  49.     -- Clear all old settings
  50.     PartyMemberFrame1:ClearAllPoints();
  51.     PartyMemberFrame2:ClearAllPoints();
  52.     PartyMemberFrame3:ClearAllPoints();
  53.     PartyMemberFrame4:ClearAllPoints();
  54.  
  55.     -- Create new locations
  56.     PartyMemberFrame1:SetPoint(C['unitframes'].party.position.relAnchor, UIParent, C['unitframes'].party.position.offSetX, C['unitframes'].party.position.offSetY);
  57.     PartyMemberFrame2:SetPoint("TOPLEFT", PartyMemberFrame1, 0, -75);
  58.     PartyMemberFrame3:SetPoint("TOPLEFT", PartyMemberFrame2, 0, -75);
  59.     PartyMemberFrame4:SetPoint("TOPLEFT", PartyMemberFrame3, 0, -75);
  60.  
  61.     -- Make the new locations stay
  62.     PartyMemberFrame1.SetPoint = function() end;
  63.     PartyMemberFrame2.SetPoint = function() end;
  64.     PartyMemberFrame3.SetPoint = function() end;
  65.     PartyMemberFrame4.SetPoint = function() end;
  66.  
  67.     -- Set the scale of all the frames
  68.     PartyMemberFrame1:SetScale(C["unitframes"].party.scale);
  69.     PartyMemberFrame2:SetScale(C["unitframes"].party.scale);
  70.     PartyMemberFrame3:SetScale(C["unitframes"].party.scale);
  71.     PartyMemberFrame4:SetScale(C["unitframes"].party.scale);
  72.    
  73.     -- Set Font Size
  74.     PartyMemberFrame1HealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].party.fontSize, "THINOUTLINE")
  75.     PartyMemberFrame1ManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].party.fontSize, "THINOUTLINE")
  76.     PartyMemberFrame2HealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].party.fontSize, "THINOUTLINE")
  77.     PartyMemberFrame2ManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].party.fontSize, "THINOUTLINE")
  78.     PartyMemberFrame3HealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].party.fontSize, "THINOUTLINE")
  79.     PartyMemberFrame3ManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].party.fontSize, "THINOUTLINE")
  80.     PartyMemberFrame4HealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].party.fontSize, "THINOUTLINE")
  81.     PartyMemberFrame4ManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].party.fontSize, "THINOUTLINE")
  82. end;
  83.  
  84.  -- Arena Frames
  85. if C["unitframes"].arena.enable then
  86.     LoadAddOn("Blizzard_ArenaUI"); -- You only need to run this once. You can safely delete any copies of this line.
  87.      
  88.     ArenaEnemyFrames:SetScale(C["unitframes"].arena.scale);
  89.    
  90.     ArenaEnemyFrame1HealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].arena.fontSize,"THINOUTLINE");
  91.     ArenaEnemyFrame1ManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].arena.fontSize, "THINOUTLINE");
  92.     ArenaEnemyFrame2HealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].arena.fontSize,"THINOUTLINE");
  93.     ArenaEnemyFrame2ManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].arena.fontSize, "THINOUTLINE");
  94.     ArenaEnemyFrame3HealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].arena.fontSize,"THINOUTLINE");
  95.     ArenaEnemyFrame3ManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].arena.fontSize, "THINOUTLINE");
  96.     ArenaEnemyFrame4HealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].arena.fontSize,"THINOUTLINE");
  97.     ArenaEnemyFrame4ManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].arena.fontSize, "THINOUTLINE");
  98.     ArenaEnemyFrame5HealthBarText:SetFont(C['media'].fontNormal, C["unitframes"].arena.fontSize,"THINOUTLINE");
  99.     ArenaEnemyFrame5ManaBarText:SetFont(C['media'].fontNormal, C["unitframes"].arena.fontSize, "THINOUTLINE");
  100.  
  101.  
  102.     if C["unitframes"].arena.tracker == true then
  103.         trinkets = {};
  104.         local arenaFrame,trinket;
  105.         for i = 1, 5 do
  106.             arenaFrame = "ArenaEnemyFrame"..i;
  107.             trinket = CreateFrame("Cooldown", arenaFrame.."Trinket", ArenaEnemyFrames);
  108.             trinket:SetPoint("TOPRIGHT", arenaFrame, 30, -6);
  109.             trinket:SetSize(24, 24);
  110.             trinket.icon = trinket:CreateTexture(nil, "BACKGROUND");
  111.             trinket.icon:SetAllPoints();
  112.             trinket.icon:SetTexture("Interface\\Icons\\inv_jewelry_trinketpvp_01");
  113.             trinket:Hide();
  114.             trinkets["arena"..i] = trinket;
  115.         end;
  116.         local events = CreateFrame("Frame");
  117.         function events:UNIT_SPELLCAST_SUCCEEDED(unitID, spell, rank, lineID, spellID)
  118.             if not trinkets[unitID] then
  119.                 return;
  120.             end ;      
  121.             if spellID == 59752 or spellID == 42292 then
  122.                 CooldownFrame_SetTimer(trinkets[unitID], GetTime(), 120, 1);
  123.                 SendChatMessage("Trinket used by: "..GetUnitName(unitID, true), "PARTY");
  124.             end;
  125.         end;
  126.         function events:PLAYER_ENTERING_WORLD()
  127.             local _, instanceType = IsInInstance();
  128.             if instanceType == "arena" then
  129.                 self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED");
  130.             elseif self:IsEventRegistered("UNIT_SPELLCAST_SUCCEEDED") then
  131.                 self:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED");
  132.                 for _, trinket in pairs(trinkets) do
  133.                     trinket:SetCooldown(0, 0);
  134.                     trinket:Hide();
  135.                 end;        
  136.             end;
  137.         end;
  138.         events:SetScript("OnEvent", function(self, event, ...) return self[event](self, ...) end);
  139.         events:RegisterEvent("PLAYER_ENTERING_WORLD");
  140.     end;
  141. end;
  142.  
  143.  -- Boss Frames
  144. if C["unitframes"].boss.enable then
  145.     for i = 1,4 do
  146.         local boss = _G["Boss"..i.."TargetFrame"];
  147.         if boss then
  148.             boss:SetScale(C["unitframes"].boss.scale)
  149.             boss:ClearAllPoints();
  150.             boss:SetPoint(C['unitframes'].boss.position.relAnchor, UIParent, C['unitframes'].boss.position.offSetX, C['unitframes'].boss.position.offSetY);
  151.             boss.ClearAllPoints = function() end;
  152.             boss.SetPoint = function() end;    
  153.         end;
  154.     end;
  155. end;
  156.  
  157. -- Font Style thanks to Phanx from WoWinterface.
  158. local shorts = {
  159.     { 1e10, 1e9, "%.0fb" }, --  10b+ as  12b
  160.     {  1e9, 1e9, "%.1fb" }, --   1b+ as 8.3b
  161.     {  1e7, 1e6, "%.0fm" }, --  10m+ as  14m
  162.     {  1e6, 1e6, "%.1fm" }, --   1m+ as 7.4m
  163.     {  1e5, 1e3, "%.0fk" }, -- 100k+ as 840k
  164.     {  1e3, 1e3, "%.1fk" }, --   1k+ as 2.5k
  165.     {    0,   1,    "%d" }, -- < 1k  as  974
  166. }
  167. for i = 1, #shorts do
  168.     shorts[i][4] = shorts[i][3] .. " (%.0f%%)"
  169. end
  170.  
  171. hooksecurefunc("TextStatusBar_UpdateTextStringWithValues", function(statusBar, fontString, value, valueMin, valueMax)
  172.     if value == 0 then
  173.         return fontString:SetText("")
  174.     end
  175.  
  176.     local style = GetCVar("statusTextDisplay")
  177.     if style == "PERCENT" then
  178.         return fontString:SetFormattedText("%.0f%%", value / valueMax * 100)
  179.     end
  180.     for i = 1, #shorts do
  181.         local t = shorts[i]
  182.         if value >= t[1] then
  183.             if style == "BOTH" then
  184.                 return fontString:SetFormattedText(t[4], value / t[2], value / valueMax * 100)
  185.             else
  186.                 return fontString:SetFormattedText(t[3], value / t[2])             
  187.             end
  188.         end
  189.     end
  190. end)
  191.  
  192. local function UnitIsPet(unit)
  193.     local guidtype = tonumber(strsub(UnitGUID(unit),5,5),16)%8
  194.     if guidtype==4 then return true end
  195.     return false
  196. end
  197.  
  198. hooksecurefunc("UnitFrame_Update", function(self)
  199.     if not self.name then return end
  200.     local unit = self.unit -- THIS WAS MISSING
  201.  
  202.     local color
  203.    
  204.     if UnitIsPlayer(unit) then
  205.         local _, class = UnitClass(unit)
  206.         color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
  207.     elseif UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit) then
  208.         color = GRAY_FONT_COLOR
  209.     elseif UnitIsEnemy(unit, "player") then
  210.         color = FACTION_BAR_COLORS[1]      
  211.     else
  212.         local reaction = UnitReaction(unit, "player")
  213.         color = reaction and FACTION_BAR_COLORS[reaction] or FACTION_BAR_COLORS[5]
  214.     end
  215.  
  216.     if not color then
  217.         color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)["priest"]
  218.     end
  219.  
  220.     if UnitIsPet(unit) then
  221.         self.name:SetTextColor(1, 1, 1)
  222.     else
  223.         self.name:SetTextColor(color.r, color.g, color.b)
  224.     end
  225.  
  226. end)
  227.  
  228.  
  229. -- Disable healing/damage spam over player/pet frame:
  230. PlayerHitIndicator:SetText(nil)
  231. PlayerHitIndicator.SetText = function() end
  232. PetHitIndicator:SetText(nil)
  233. PetHitIndicator.SetText = function() end
  Reply With Quote