Let me explain it in more detail.
Lets say the message received from the event monitor is
msg = "The ostrich tells you its wish:#-*!**"
Code: Select all
if msg and string.match(msg, RoMScript("TEXT(\"SC_2012THANKS_NPC_121493_SYSTEM_14\")")) then -- "The ostrich tells you its wish:"
What this line does is say,
if there is a msg and the message contains "The ostrich tells you its wish:" then. msg does contain that so it continues. You can test this out by typing this on the commandline.
Code: Select all
if string.match( "The ostrich tells you its wish:#-*!**", "The ostrich tells you its wish:") then print("true") end
At this point the value of msg hasn't changed .
Code: Select all
local wish = string.match(msg,"['#!%*%-]+")
What this does is extract the block of text from 'msg' that includes the characters !, #, ', ` and *, which is "#-*!**". This is what 'wish' now holds. You can test this by typing
Code: Select all
print(string.match("The ostrich tells you its wish:#-*!**", "['#!%*%-]+"))
This will output
#-*!**. I'll fix the code above.
Next
Code: Select all
for cmd in string.gmatch(wish) do
Oops another mistake. It should be
Code: Select all
for cmd in string.gmatch(wish,"..") do
What this does is go though 'wish' and return every 2 characters in a loop. You can test this by doing
Code: Select all
for cmd in string.gmatch("#-*!**","..") do print(cmd) end
This will output
#-
*!
**
And lastly it uses those 2 characters to execute the command using the 'respondto' function.
Hope that made thing clearer.