Posted by
| Nick Gammon
Australia (23,120 posts) Bio
Forum Administrator |
Message
| The problem was with how you were capturing the matched line.
Using "local line = GetLineInfo(GetLinesInBufferCount(), 1)" was unnecessarily complex and also only returned the last line.
I changed it to:
... in your first trigger, and in the second one, because there would be embedded linefeeds:
The amended triggers are:
<triggers>
<trigger
enabled="y"
ignore_case="y"
match="^\(Party\): You say, "Target Order: (.*)"$"
regexp="y"
send_to="12"
sequence="100"
>
<send>-- Declare target_list globally
target_list = {}
local line = "%0"
Note("Captured line: " .. line)
-- Match and clean up the target order
local targets_line = string.match(line, 'Target Order:%s*(.+)')
if targets_line then
Note("Matched targets line: " .. targets_line)
-- Process each target in the line
for target in string.gmatch(targets_line, "([^,]+)") do
target = target:gsub("^%s+", ""):gsub("%s+$", ""):gsub("[^%w%s]", "") -- Trim and clean target
Note("Found target: '" .. target .. "'")
table.insert(target_list, target)
end
-- Check if the target list was populated
if #target_list > 0 then
for i, target in ipairs(target_list) do
Note("Target " .. i .. ": " .. target)
end
else
Note("Target list is empty.")
end
else
Note("No match found for target order.")
end</send>
</trigger>
<trigger
enabled="y"
group="Multi Line"
ignore_case="y"
lines_to_match="2"
match="^You see the following people here:\n(.+)$"
multi_line="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>
-- Capture the line listing people in the room
local line = [=[%0]=]
Note("Captured line: " .. line)
-- Match and extract the people in the room
local names_line = string.match(line, "You see the following people here:%s*(.*)")
if names_line then
Note("Matched names line: " .. names_line)
-- Iterate through the target_list and check if any target is in names_line
for _, target in ipairs(target_list) do
-- Use pattern matching to check if the target name exists in the names_line
if string.find(names_line, "%f[%a]" .. target .. "%f[%A]") then
Send("PT Target: " .. target)
Note("Target found and command sent: " .. target)
break -- Stop after the first match
end
end
else
Note("No names found in the line.")
end</send>
</trigger>
</triggers>
|
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.
|
Then using your test data it seems to work OK:
(Party): You say, "Target Order: Mike, Stevie, Tesha, Gabi, Dega, Indica, Rose, Rosette, Rosiette, Akri."
Captured line: (Party): You say, "Target Order: Mike, Stevie, Tesha, Gabi, Dega, Indica, Rose, Rosette, Rosiette, Akri."
Matched targets line: Mike, Stevie, Tesha, Gabi, Dega, Indica, Rose, Rosette, Rosiette, Akri."
Found target: 'Mike'
Found target: 'Stevie'
Found target: 'Tesha'
Found target: 'Gabi'
Found target: 'Dega'
Found target: 'Indica'
Found target: 'Rose'
Found target: 'Rosette'
Found target: 'Rosiette'
Found target: 'Akri'
Target 1: Mike
Target 2: Stevie
Target 3: Tesha
Target 4: Gabi
Target 5: Dega
Target 6: Indica
Target 7: Rose
Target 8: Rosette
Target 9: Rosiette
Target 10: Akri
You see the following people here:
Stevie, Gabi, Mike, Rosiette, Akri
Captured line: You see the following people here:
Stevie, Gabi, Mike, Rosiette, Akri
Matched names line: Stevie, Gabi, Mike, Rosiette, Akri
Target found and command sent: Mike
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|