WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   I need help with lua code (https://www.wowinterface.com/forums/showthread.php?t=56071)

rbkz 02-26-18 02:00 AM

I need help with lua code
 
Hello there,

I need help with a lua script, I would like to add color into PlayerFrame aswell same as TargetFrame and FocusFrame.

In the code below it already have class color in health bar and color behind name of target and focus, not player frame.
(red marked text is the code I tried to implement without any success)


local frame = CreateFrame("FRAME")
frame:RegisterEvent("GROUP_ROSTER_UPDATE")
frame:RegisterEvent("PLAYER_TARGET_CHANGED")
frame:RegisterEvent("PLAYER_FOCUS_CHANGED")
frame:RegisterEvent("PLAYER_FRAME_CHANGED")<- Not sure about this one, tried many different texts.
frame:RegisterEvent("UNIT_FACTION")

local function eventHandler(self, event, ...)
if UnitIsPlayer("target") then
c = RAID_CLASS_COLORS[select(2, UnitClass("target"))]
TargetFrameNameBackground:SetVertexColor(c.r, c.g, c.b)
end
if UnitIsPlayer("focus") then
c = RAID_CLASS_COLORS[select(2, UnitClass("focus"))]
FocusFrameNameBackground:SetVertexColor(c.r, c.g, c.b)
end
if UnitIsPlayer("player") then
c = RAID_CLASS_COLORS[select(2, UnitClass("player"))]
PlayerFrameNameBackground:SetVertexColor(c.r, c.g, c.b)

end
end

frame:SetScript("OnEvent", eventHandler)

for _, BarTextures in pairs({TargetFrameNameBackground, FocusFrameNameBackground, PlayerFrameNameBackground}) do
BarTextures:SetTexture("Interface\\TargetingFrame\\UI-StatusBar")
end

Ammako 02-26-18 09:20 AM

What if you hooked PlayerFrame OnShow?

(Also pls dont use dark red text.)

Also:
http://www.wowinterface.com/download...ameFrames.html

Tim 02-26-18 01:13 PM

Here's the same overall code I posted in this thread but, with some modifications for you....

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["PlayerFrameNameBackground"]:SetVertexColor(getPlayerColors("player"))
  _G["TargetFrameNameBackground"]:SetVertexColor(getPlayerColors("target"))
  _G["FocusFrameNameBackground"]:SetVertexColor(getPlayerColors("focus"))

end)

for _, BarTextures in pairs({TargetFrameNameBackground, FocusFrameNameBackground, PlayerFrameNameBackground}) do
  BarTextures:SetTexture("Interface\\TargetingFrame\\UI-StatusBar")
end


btw, PLAYER_FRAME_CHANGED will not work as it's not a valid event. -> https://wow.gamepedia.com/Events

I can't test this right now but, it should work.


All times are GMT -6. The time now is 02:28 AM.

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