Thanks Phanx, will do.
Edit: Okay, gonna take me a while to figure this out ... Any time I try to adjust AddMessage function it crashes wow, so I guess I am doing something wrong somewhere rofl.
Edit2: Good News is it now color codes the Names and shows the Toon Name and Server based on toggle setting to do so. Bad News is that it currently crashes if you log in / reload and you don't have any realID friends online or seems to go into an infinite loop and crashes if your realID friend logs off. Phanx or anyone else, is there anything you can see in this code that may cause that as I can't seem to see anything that I am not covering myself for so that it simply returns an unformatted message string.
Removed the toast test since the crashing/hanging etc as it isn't really need in this instance so will see if that might be the cause of the issue but just in case it isn't the cause, here is the code in its entirety and a download version if you prefer.
Lua Code:
local addonName, addonData = ...
local showToonName = true
local showRealmName = showToonName and true
local debugMessages = true
local bnNameFormat = "%s"
local playerBNFormat = "|HBNplayer:%s|h" .. bnNameFormat .. "%s|h"
local playerBNPattern = "|HBNplayer:(.-)|h%[(|Kf(%d+).-)%](.*)|h"
local function RGB_TO_HEX(rgb)
return string.format("%02x%02x%02x", rgb.r*255, rgb.g*255, rgb.b*255)
end
local function ColorToonName(chatFrame,message,...)
local bnData, bnName, bnID, bnExtra = string.match(message, playerBNPattern)
if bnData then
local toonInfo = { BNGetToonInfo(bnID) }
local link = string.format(playerBNFormat, bnData, bnName, bnExtra or "")
if toonInfo[3] ~= "WoW" or toonInfo[3] == nil then
message = string.gsub(message, playerBNPattern, link)
else
local toonName = toonInfo[2]
local realmName = toonInfo[4]
local class = toonInfo[8]
local color = RAID_CLASS_COLORS[class]
local classToken = addonData.ClassNames[class]
if not color then
color = RAID_CLASS_COLORS[classToken]
end
local colorHex = RGB_TO_HEX(color)
if showToonName then
if showRealmName then
coloredSender = string.format("|cff%s %s (%s-%s)|r",colorHex,bnName,toonName,realmName)
else
coloredSender = string.format("|cff%s %s (%s)|r",colorHex,bnName,toonName)
end
else
coloredSender = string.format("|cff%s %s|r",colorHex,bnName)
end
link = string.format(playerBNFormat, bnData, coloredSender, bnExtra or "")
message = string.gsub(message, playerBNPattern, link)
end
end
return message
end
local function AddMessage(chatFrame, message, ...)
if type(message) == "string" then
local bnData, bnName, bnID, bnExtra = strmatch(message, playerBNPattern)
if bnData then
message = ColorToonName(chatFrame,message,...)
end
end
addonData[chatFrame].AddMessage(chatFrame,message, ...)
end
addonData.XRICEvents = CreateFrame("Frame")
addonData.XRICEvents:RegisterEvent("ADDON_LOADED")
addonData.XRICEvents:SetScript("OnEvent",function(self,event,...)
local args = { ... }
if event == "ADDON_LOADED" and args[1] == addonName then
addonData.ClassNames = {}
for k, v in pairs(LOCALIZED_CLASS_NAMES_MALE) do
addonData.ClassNames[v] = k
end
for k, v in pairs(LOCALIZED_CLASS_NAMES_FEMALE) do
addonData.ClassNames[v] = k
end
for i = 1, NUM_CHAT_WINDOWS do
local chatFrame = _G["ChatFrame" .. i]
addonData[chatFrame] = addonData[chatFrame] or {}
if ( not addonData[chatFrame].AddMessage ) then
addonData[chatFrame].AddMessage = chatFrame.AddMessage
chatFrame.AddMessage = AddMessage
end
end
end
end)