Quantcast
Reverse string - WoWInterface
Thread Tools Display Modes
12-25-21, 03:36 PM   #1
abel8909
A Murloc Raider
Join Date: Jan 2021
Posts: 4
Reverse string

hi everyone and happy christmas eve, i'm new to this lua, could someone help me how to reverse string example
FACTION_STANDING_INCREASED = "%s %d"
for
FACTION_STANDING_INCREASED = "%d %s"

I found this code but it doesn't work

ChatFrame_AddMessageEventFilter("CHAT_MSG_COMBAT_FACTION_CHANGE", function(frame, event, message, ...)
local which, faction, amount = strmatch(message, "^[%+%-] (%+) (%d+) rep$")
if which and faction and amount then
return false, (format("%s%d %s rep", which, amount, faction)), ...
end
end)
  Reply With Quote
12-25-21, 03:44 PM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,092
Specific to the WoW API, string.format() lets you specify which args go where by modifying the format specifier. By default, they are left-to-right in order. This would flip the order by specifying the second argument goes in the first slot and vice versa. Blizzard did this specifically to support localization.
Code:
FACTION_STANDING_INCREASED = "%2$d %1$s"
Note: The letters define the data type, changing these to be different than what the arguments are can cause type mismatch errors.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 12-25-21 at 03:48 PM.
  Reply With Quote
12-25-21, 07:50 PM   #3
abel8909
A Murloc Raider
Join Date: Jan 2021
Posts: 4
Originally Posted by SDPhantom View Post
Specific to the WoW API, string.format() lets you specify which args go where by modifying the format specifier. By default, they are left-to-right in order. This would flip the order by specifying the second argument goes in the first slot and vice versa. Blizzard did this specifically to support localization.
Code:
FACTION_STANDING_INCREASED = "%2$d %1$s"
Note: The letters define the data type, changing these to be different than what the arguments are can cause type mismatch errors.
if it works, thank you very much, and another question if it does not bother you :P
how can I filter chat texts (from battleground) to replace them example

Babe claims the stables! If left unchallenged, the Alliance will control it in 1 minute!

for

Babe claims the stables!

this is the event
  Reply With Quote
12-25-21, 09:12 PM   #4
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 616
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.     return nil,msg,...
  4. end)
  Reply With Quote
12-26-21, 05:25 PM   #5
abel8909
A Murloc Raider
Join Date: Jan 2021
Posts: 4
Originally Posted by Kanegasi View Post
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.     return nil,msg,...
  4. end)
Thank you very much for answering, if it works and excuse my ignorance, how can I make a list to filter several messages? I did something like that but it doesn't work

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!"," control it in 1 minute!")
  3.     msg=msg:gsub("The Horde Flag was picked up by ","The Horde Flag was captured by ")
  4.     return nil,msg,...
  5. end)
  Reply With Quote
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: 616
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
12-26-21, 08:25 PM   #7
abel8909
A Murloc Raider
Join Date: Jan 2021
Posts: 4
oh i see, thank you very much
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Reverse string

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