Trigger with line break

Posted by Valentim on Sat 05 Aug 2023 12:56 AM — 8 posts, 17,721 views.

#0
How to create a trigger when there is a limit of 60 characters and after this limit the line is broken.

Example:
Whole Line >> "An Ugly and Stinking Ogre attacked you with a club and hit your arm."

1º Broken Line >> "An Ugly and Stinking Ogre attacked you with a club and hit y"
2º Broken Line >> "our arm."

Note: line break changes according to the text

Trigger: ^(.*) attacked you with a (.*) and hit your (.*)\.$
Australia Forum Administrator #1
What do you mean by broken line? Does the server do that? It seems odd to break a word in the middle.
#2
word wrap is does by server, possibly due to some bidding on screen size, I don't know how to explain.

I already tried to configure client in output options, but it didn't work... I don't know if I did it right

Is there any way to use wildcard as (.*\n) ?
Amended on Sat 05 Aug 2023 02:16 PM by Valentim
Australia Forum Administrator #3
I'm surprised a MUD would break lines in the middle of words. Did you configure MUSHclient to have short lines? If not, surely their server has an option to have longer lines, many servers have a "config" or similar command to do that.

Normal triggers are evaluated on a linebreak, so you therefore can't put a newline into the trigger.

There is an multi-line trigger option, in which case you could look for newlines in a wildcard like you suggested. However I would try to fix the main problem first before attempting that.
USA Global Moderator #4
Quote:
Is there any way to use wildcard as (.*\n) ?


Given the description of the scenario (splitting in the middle of a word), it sounds like you'd need an optional \n after every single character. Even if that works, it would be very ugly and hard to work with.
Amended on Mon 07 Aug 2023 12:01 AM by Fiendish
Australia Forum Administrator #5
This might work for you:


<triggers>
  <trigger
   enabled="y"
   lines_to_match="2"
   match="(?s)^.* attacked you with.*\."
   multi_line="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>

local line = [===[%0]===]

line = string.gsub (line, "\\n", "")

print ("Combined line:", line)

who, weapon, place = string.match (line, "^(.-) attacked you with a (.-) and hit your (.-)%.$")

if not who then
  print "No match"
  return
end -- if

print ("Who:", who)
print ("With what:", weapon)
print ("Where:", place)

</send>
  </trigger>
</triggers>


Template:pasting
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.


What this is doing is using a two-line multi-line trigger to detect both lines. We have to cut down the regular expression in the trigger to just detect "this sort of" line. The final period in the match text is to make it stop when it hits the period at the end of the sentence. The "(?s)" in the regexp tells it to include newlines in the "dot" match.

Then the Lua code gets rid of the newline (if any) and then does a string.match to re-parse the line and extract out the attacker, weapon and place it hits.

Example output from your test data:


Combined line: An Ugly and Stinking Ogre attacked you with a club and hit your arm.
Who: An Ugly and Stinking Ogre
With what: club
Where: arm


The only trouble with this is would be a single-line attack, because the two-line trigger will wait for both lines. For that case you might want to use your original trigger (that matches a single line) to handle that case, and make that a lower sequence number, so that it stops this second multi-line trigger from trying to evaluate.
Amended on Mon 07 Aug 2023 05:42 AM by Nick Gammon
USA Global Moderator #6
match="(?s)^.* attacked you with.*\."


I was thinking more like


match="(?s)^.* \n?a\n?t\n?t\n?a\n?c\n?k\n?e\n?d\n? \n?y\n?o\n?u\n? \n?w\n?i\n?t\n?h\n?.*\."


:D
Amended on Mon 07 Aug 2023 03:54 PM by Fiendish
Australia Forum Administrator #7
Yeah, well I was kind-of hoping the mob's name wouldn't be so long it would push the rest past a line break. I suppose you could match "anything" and then do the decoding in the trigger.