09-06-24, 09:14 AM | #1 |
Help with updating addon code
I've been digging around these forums for an addon that removes all instances "-RealmName" attached to player names in the chat frame, and while there were a couple of codes I found to do that, none of them seem to work in the current version of the game. My theory is that Blizzard updated their code for the chat frame, so until the addon code is updated, or a new addon is written, there is no way to hide the player realm names in the chat at the moment
That being said, I did stumble upon a code from 2015 that does a part of the job right to this day! I'll take the liberty to post it here, since it was written by an addon author on these forums for a user that had the same question as I do now: Code:
local a,g = getmetatable(DEFAULT_CHAT_FRAME).__index.AddMessage,gsub getmetatable(DEFAULT_CHAT_FRAME).__index.AddMessage = function(s,t,...) if s == ChatFrame2 then return a(s,t,...) end -- combat log return a(s,g(t,"|Hplayer:(.-)|h(.-)|h",function(a,b) return "|Hplayer:"..a.."|h"..g(b,"-([^%]:]+)(.*)","%2|r").."|h" end),...) end ChatFrame_AddMessageEventFilter('CHAT_MSG_SYSTEM', function(self, event, msg, ...) return false, (msg:gsub('([^\1-\64\91-\96\123-191]+)%-%u%l%a+', '%1')), ... end) ChatFrame_AddMessageEventFilter('CHAT_MSG_LOOT', function(self, event, msg, ...) return false, (msg:gsub('([^\1-\64\91-\96\123-191]+)%-%u%l%a+', '%1')), ... end) ChatFrame_AddMessageEventFilter('CHAT_MSG_CURRENCY', function(self, event, msg, ...) return false, (msg:gsub('([^\1-\64\91-\96\123-191]+)%-%u%l%a+', '%1')), ... end) ChatFrame_AddMessageEventFilter('CHAT_MSG_COMBAT_HONOR_GAIN', function(self, event, msg, ...) return false, (msg:gsub('([^\1-\64\91-\96\123-191]+)%-%u%l%a+', '%1')), ... end) ChatFrame_AddMessageEventFilter('CHAT_MSG_COMBAT_XP_GAIN', function(self, event, msg, ...) return false, (msg:gsub('([^\1-\64\91-\96\123-191]+)%-%u%l%a+', '%1')), ... end) ChatFrame_AddMessageEventFilter('CHAT_MSG_BG_SYSTEM_NEUTRAL', function(self, event, msg, ...) return false, (msg:gsub('([^\1-\64\91-\96\123-191]+)%-%u%l%a+', '%1')), ... end) ChatFrame_AddMessageEventFilter('CHAT_MSG_BG_SYSTEM_ALLIANCE', function(self, event, msg, ...) return false, (msg:gsub('([^\1-\64\91-\96\123-191]+)%-%u%l%a+', '%1')), ... end) ChatFrame_AddMessageEventFilter('CHAT_MSG_BG_SYSTEM_HORDE', function(self, event, msg, ...) return false, (msg:gsub('([^\1-\64\91-\96\123-191]+)%-%u%l%a+', '%1')), ... end) ChatFrame_AddMessageEventFilter('CHAT_MSG_ACHIEVEMENT', function(self, event, msg, ...) return false, (msg:gsub('([^\1-\64\91-\96\123-191]+)%-%u%l%a+', '%1')), ... end) ChatFrame_AddMessageEventFilter('CHAT_MSG_YELL', function(self, event, msg, ...) return false, (msg:gsub('([^\1-\64\91-\96\123-191]+)%-%u%l%a+', '%1')), ... end) ChatFrame_AddMessageEventFilter('CHAT_MSG_SAY', function(self, event, msg, ...) return false, (msg:gsub('([^\1-\64\91-\96\123-191]+)%-%u%l%a+', '%1')), ... end) ChatFrame_AddMessageEventFilter('CHAT_MSG_TEXT_EMOTE', function(self, event, msg, ...) return false, (msg:gsub('([^\1-\64\91-\96\123-191]+)%-%u%l%a+', '%1')), ... end) ChatFrame_AddMessageEventFilter('CHAT_MSG_EMOTE', function(self, event, msg, ...) return false, (msg:gsub('([^\1-\64\91-\96\123-191]+)%-%u%l%a+', '%1')), ... end) hooksecurefunc('ChatEdit_UpdateHeader', function(editBox) local header = _G[editBox:GetName() .. 'Header'] if editBox:GetAttribute('chatType') == 'WHISPER' and header then _G[editBox:GetName() .. 'HeaderSuffix']:Hide() header:SetWidth(0) header:SetFormattedText(CHAT_WHISPER_SEND, (strsplit('-', editBox:GetAttribute('tellTarget')))) editBox:SetTextInsets(15 + (header:GetRight() or 0) - (header:GetLeft() or 0), 13, 0, 0) end end) My question is, since I have 0 knowledge of lua code, could somebody more experienced take a look at the addon and maybe reformulate it to remove all instances of -RealmName from all player messages and interactions in the chat frame? I wanted to reach out to the person that made the code, but they haven't been online in years, hence I'm writing this here in hope that somebody can help Last edited by dankanst : 09-06-24 at 09:18 AM. |
|
09-06-24, 12:19 PM | #2 |
I already sent this to you in a PM. But maybe other folks may wanna use it as well....
Code:
-- Function to remove realm names from player names in chat messages local function RemoveRealmFromChatMessage(message) -- Replace any realm name pattern, i.e., "Player-Realm" with "Player" return message:gsub("([%a]+)%-(%a+)", "%1") end -- Hook into each chat frame to override the AddMessage function local function HookChatFrames() for i = 1, NUM_CHAT_WINDOWS do local chatFrame = _G["ChatFrame"..i] if chatFrame and chatFrame.AddMessage then -- Store the original AddMessage function local originalAddMessage = chatFrame.AddMessage -- Override the AddMessage function chatFrame.AddMessage = function(self, text, ...) -- Remove realm names from the message text = RemoveRealmFromChatMessage(text) -- Call the original AddMessage function with the modified text return originalAddMessage(self, text, ...) end end end end -- Call the function to hook chat frames when the addon is loaded HookChatFrames() |
|
09-07-24, 12:19 PM | #3 |
It's not good practice to replace Blizzard's functions. This may lead to UI taints, even replacing something as innocent as adding a chat line. For example, messing with ChatFrame1 can sometimes cause taints involving Edit Mode.
You can hook CircularBuffer:PushFront(), which is what ScrollingMessageFrame:AddMessage() calls, and edit the line in the chat window directly. I use this method in my personal addon for chat line manipulation. FCF_SetWindowName() happens to be the first function guaranteed to be called when creating any chat window, during UI startup or making any additional window, that includes the frame in the first argument. Hooking FCF_SetWindowName() to then hook any frame that passes through it ensures all chat frames are caught. I also ignore the Combat Log; doing anything to each line in that frame tanks fps, but you can try by removing the commented line. Also, while %a may match character names, %a will not match all realm names. In chat context, such as player links and shift clicking, spaces are removed but dashes and apostrophes may still be there. One realm even has numbers in it. The ascii numbers in the original code was to ensure any possible character that can't be used in a character's name is not matched. I'm not going to reinvent the wheel there if the original author found a problem with %a. Lua Code:
__________________
|
|
WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Help with updating addon code |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|