Thread Tools Display Modes
02-26-18, 02:00 AM   #1
rbkz
A Kobold Labourer
Join Date: Feb 2018
Posts: 1
Exclamation 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

Last edited by rbkz : 02-26-18 at 04:47 AM.
  Reply With Quote
02-26-18, 09:20 AM   #2
Ammako
A Frostmaul Preserver
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 256
What if you hooked PlayerFrame OnShow?

(Also pls dont use dark red text.)

Also:
http://www.wowinterface.com/download...ameFrames.html
  Reply With Quote
02-26-18, 01:13 PM   #3
Tim
A Rage Talon Dragon Guard
 
Tim's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 309
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.
__________________
AddOns: Tim @ WoWInterface
Battle Tag: Mysterio#11164
Current PC Setup: PCPartPicker List
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » I need help with lua code

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off