WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   PlayerHitIndicator and class color. Help (https://www.wowinterface.com/forums/showthread.php?t=55880)

RammounZ 11-26-17 05:02 AM

PlayerHitIndicator and class color. Help
 
1 Attachment(s)
Hi!:)

It's possible to change the size of PlayerHitIndicator(incoming healing and damage on player frame) and a little move to the left?
Attachment 9022

And second question, i have code that change color my nickname on my player frame(you can see that my nickname is blue, like color of the class)

Code:

local function getPlayerColors()
    local c = RAID_CLASS_COLORS[select(2,UnitClass("player"))]
    return c.r, c.g, c.b
end

PlayerName:SetTextColor(getPlayerColors())

so, i want change class color of the nickname on target and focus. Something like that
Code:

TargetFrameTextureFrameName:SetTextColor(getPlayerColors())
FocusFrameTextureFrameName:SetTextColor(getPlayerColors())

But, I dont know how to make the getPlayerColors() function return the color of the class, not just the color of the player. How to do it ?

jeffy162 11-26-17 08:22 AM

I'm not an expert in Lua coding (by any means), but, the answer (basically) is in the second line of your example. RAID_CLASS_COLORS should give you your clue.

Sorry if that's wrong, but it seemed obvious to me. :o

RammounZ 11-26-17 08:53 AM

Thanks for reply. Yes, one dude suggest me this code, but he doesnt work

Code:

local function getPlayerColors(unit)
    local c = RAID_CLASS_COLORS[select(2,UnitClass(unit))]
    return c.r, c.g, c.b
end

PlayerName:SetTextColor(getPlayerColors("player"))
TargetFrameTextureFrameName:SetTextColor(getPlayerColors("target"))
FocusFrameTextureFrameName:SetTextColor(getPlayerColors("focus"))


Kakjens 11-26-17 10:40 AM

Quote:

Originally Posted by RammounZ (Post 325932)
he doesnt work

Was it meant as "it doesn't work"?
I believe you might want to call
Code:

TargetFrameTextureFrameName:SetTextColor(getPlayerColors("target"))
FocusFrameTextureFrameName:SetTextColor(getPlayerColors("focus"))

accordingly when target or focus changed instead of during login.

Tim 11-26-17 11:23 AM

Pretty sure the PlayerHitIndicator text is drawn on sort of like Blizzard's combat text so, the only ways to change it are by changing fonts or disabling it completely.

As for the name color stuff....

Code:

local function getPlayerColors(unit)

  if not UnitExists(unit) then return end

  local color
  local class = select(2, UnitClass(unit))

  if UnitIsPlayer(unit) then
      color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
  else
      color = FACTION_BAR_COLORS[UnitReaction(unit, "player")]
  end

  return color.r, color.g, color.b

end

local UpdateColor = CreateFrame("Frame")
UpdateColor:RegisterEvent("PLAYER_ENTERING_WORLD")
UpdateColor:RegisterEvent("PLAYER_TARGET_CHANGED")
UpdateColor:RegisterEvent("PLAYER_FOCUS_CHANGED")
UpdateColor:RegisterEvent("UNIT_FACTION")
UpdateColor:SetScript("OnEvent", function(_, event)

  _G["PlayerName"]:SetTextColor(getPlayerColors("player"))
  _G["TargetFrameTextureFrameName"]:SetTextColor(getPlayerColors("target"))
  _G["FocusFrameTextureFrameName"]:SetTextColor(getPlayerColors("focus"))

end)


RammounZ 11-26-17 12:05 PM

Quote:

Originally Posted by Tim (Post 325934)
Code:

local function getPlayerColors(unit)

  if not UnitExists(unit) then return end

  local color
  local class = select(2, UnitClass(unit))

  if UnitIsPlayer(unit) then
      color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
  else
      color = FACTION_BAR_COLORS[UnitReaction(unit, "player")]
  end

  return color.r, color.g, color.b

end

local UpdateColor = CreateFrame("Frame")
UpdateColor:RegisterEvent("PLAYER_ENTERING_WORLD")
UpdateColor:RegisterEvent("PLAYER_TARGET_CHANGED")
UpdateColor:RegisterEvent("PLAYER_FOCUS_CHANGED")
UpdateColor:RegisterEvent("UNIT_FACTION")
UpdateColor:SetScript("OnEvent", function(_, event)

  _G["PlayerName"]:SetTextColor(getPlayerColors("player"))
  _G["TargetFrameTextureFrameName"]:SetTextColor(getPlayerColors("target"))
  _G["FocusFrameTextureFrameName"]:SetTextColor(getPlayerColors("focus"))

end)


This code working very well, ty Tim very much for help!!!

And about PlayerHitIndicator, you are right. I use other fonts, that's why PlayerHitIndicator is so big. And since they can not be reduced, I decided to hide them. If someone need a code:

Code:

PlayerHitIndicator:SetText(nil)
PlayerHitIndicator.SetText = function() end


Kakjens 11-26-17 05:09 PM

With a use of variable "event" is possible to avoid unnecessary getPlayerColors(unit) calls.
What's the reason for UpdateColor:RegisterEvent("UNIT_FACTION")?
For me it feels that
Lua Code:
  1. PlayerHitIndicator:SetText(nil)
  2. PlayerHitIndicator.SetText = function() end
is a wrong way to hide text due to tainting.

Kanegasi 11-26-17 09:23 PM

Quote:

Originally Posted by Kakjens (Post 325940)
For me it feels that
Lua Code:
  1. PlayerHitIndicator:SetText(nil)
  2. PlayerHitIndicator.SetText = function() end
is a wrong way to hide text due to tainting.

Correct. Altering any of Blizzard's functions is a good way to taint. Not all UI code is secure, but taints happen in weird ways.

A better way to hide the PlayerHitIndicator text:

Lua Code:
  1. PlayerFrame:UnregisterEvent('UNIT_COMBAT')

My addon NoCombatText can also hide the text, but it also allows you to configure what you want to show, for both Player and Pet. An addon of the same name here, No Combat Text, just hides the text by clearing the anchor points of the HitIndicator frames. The names are coincidental, as explained in my comment on that addon's page.

Tim 11-27-17 04:42 AM

Quote:

Originally Posted by Kakjens (Post 325940)
What's the reason for UpdateColor:RegisterEvent("UNIT_FACTION")?

It's just for the npc's where they're not always friendly/neutral/hostile towards you.


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

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