Thread: Reverse string
View Single Post
12-26-21, 07:30 PM   #6
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
The gsub function accepts three arguments: the string, what to look for, and what to substitute.

msg=gsub(msg,find,replace)

or

msg=msg:gsub(find,replace)

This means that replace being an empty string, "", you are deleting what the function finds.

Lua Code:
  1. ChatFrame_AddMessageEventFilter("CHAT_MSG_BG_SYSTEM_ALLIANCE",function(_,_,msg,...)
  2.     msg=msg:gsub(" If left unchallenged, the Alliance will control it in 1 minute!","")
  3.     msg=msg:gsub(" control it in 1 minute!","")
  4.     return nil,msg,...
  5. end)

The above code only filters the blue text. To alter the red text, you need to filter the Horde event.

Lua Code:
  1. ChatFrame_AddMessageEventFilter("CHAT_MSG_BG_SYSTEM_HORDE",function(_,_,msg,...)
  2.     msg=msg:gsub("The Horde Flag was picked up by ","")
  3.     msg=msg:gsub("The Horde Flag was captured by ","")
  4.     return nil,msg,...
  5. end)

If I got the colors wrong, I apologize. The messages above may all be blue, it's been a long time since I played battlegrounds.

Edit:

Now that I think about it, you don't have to worry about the different events if you just filter all of them at once.

Lua Code:
  1. local filterfunc=function(_,_,msg,...)
  2.     msg=msg:gsub(" If left unchallenged, the Alliance will control it in 1 minute!","")
  3.     msg=msg:gsub(" control it in 1 minute!","")
  4.     msg=msg:gsub("The Horde Flag was picked up by ","")
  5.     msg=msg:gsub("The Horde Flag was captured by ","")
  6.     return nil,msg,...
  7. end
  8.  
  9. ChatFrame_AddMessageEventFilter("CHAT_MSG_BG_SYSTEM_ALLIANCE",filterfunc)
  10. ChatFrame_AddMessageEventFilter("CHAT_MSG_BG_SYSTEM_HORDE",filterfunc)
  11. ChatFrame_AddMessageEventFilter("CHAT_MSG_BG_SYSTEM_NEUTRAL",filterfunc)

This takes one filter function and applies it to all three BG announcement events.

Last edited by Kanegasi : 12-26-21 at 10:15 PM.
  Reply With Quote