1. #1
    Deleted

    Removing -REALMNAME

    Hello there,

    I'm working on a small addon for personal use to remove the very annoying [Fansoz-Dragonblight] into [Fansoz] (like it was prior to 5.4.2).

    I am, however, getting stuck at figuring out how to ensure it catches "-Realmname".

    Here is my current code in it's enterity:

    Code:
    function huFilter(self, event, msg)
    	local removestring = "-"..GetRealmName()
    	if msg:find(removestring) then
    		return string.gsub(msg, removestring, "")
    	end
    end
    
    ChatFrame_AddMessageEventFilter("CHAT_MSG_CHANNEL", huFilter)
    ChatFrame_AddMessageEventFilter("CHAT_MSG_SAY", huFilter)
    ChatFrame_AddMessageEventFilter("CHAT_MSG_YELL", huFilter)
    ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER", huFilter)
    When writing, for example, -Dragonblight in the /s it does remove the line, the whole thing. Nothing's shown instead of all but the "-Dragonblight" part.

    I'm not very novice in terms of programming, but I'm not used to event based programming and lua/wow api. So, I don't want a complete answer since I really want to learn this stuff too, so a resource or an explanation of what I'm doing wrong is really all I'm asking for.

    Also I am curious to learn more about the msg:find functionality, I was told by a similarily novice as myself it was useful, personal I'm pondering the usefulness of it since the gsub should simply return a nil value if there's no matches found, right?

    Thanks!

    /Fansoz (Best disco eu! )

  2. #2
    Deleted
    The filter function's first return value is evaluated as a boolean true (hide the message) or false (show the message). If additional return values are present, they are used to replace the existing values. Also, I'm assuming you're trying to alter the string being displayed for the sender's name, not the contents of the message?

    If so, this filter should work (important changes highlighted in red):
    Code:
    local function huFilter(self, event, msg, sender, ...)
    	local name, realm = sender:match("^([^%-]+)%-(.+)$")
    	if realm == GetRealmName() then
    		return false, msg, name, ...
    	else
    		return false
    	end
    end
    More details: ChatFrame_AddMessageEventFilter

  3. #3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •