[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  How would I match this trigger in the dialog?

How would I match this trigger in the dialog?

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Rivius   (99 posts)  [Biography] bio
Date Sun 12 Sep 2010 04:42 PM (UTC)
Message
Ryboi slices across your head with a solar eclipse shofa, spilling stinging
blood into your eyes.

Obviously the name Ryboi and the weapon he's using are going to be variable. The problem is, this is multiline, and the weapon name can be several words long in some cases.
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #1 on Sun 12 Sep 2010 04:51 PM (UTC)

Amended on Sun 12 Sep 2010 04:53 PM (UTC) by Twisol

Message
Ick. I just love those... If possible, disable line wrapping on the server. It will help immensely if we can get that line in whole instead of split. We can always set up client-side wrapping.

If you can do this, you can treat this as a single line and make it a lot easier to do. Otherwise, you'll need to do something like this (and it's not guaranteed (and I haven't tested it)):
\ARyboi[\n ]slices[\n ]across[\n ]your[\n ]head[\n ]with[\n ]a[\n ]solar[\n ]eclipse[\n ]shofa,[\n ]spilling[\n ]stinging[\n ]blood[\n ]into[\n ]your[\n ]eyes\.\Z

Blech, right?

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #2 on Sun 12 Sep 2010 05:36 PM (UTC)

Amended on Sun 12 Sep 2010 05:37 PM (UTC) by Worstje

Message
Funny how things can be different among games.

The wordwrap I have experience with works a bit differently... it leaves the spaces in place, but adds a \n at some moments, meaning you might need a ' \n?' instead of your '[\n ]' version.
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Sun 12 Sep 2010 09:49 PM (UTC)

Amended on Sun 12 Sep 2010 09:52 PM (UTC) by Nick Gammon

Message
Rivius said:


Ryboi slices across your head with a solar eclipse shofa, spilling stinging
blood into your eyes.


Obviously the name Ryboi and the weapon he's using are going to be variable. The problem is, this is multiline, and the weapon name can be several words long in some cases.


How much of this is fixed? That is, is "slices" always there, or "into your eyes"? I am thinking of a more general solution, but to do that we need some sort of anchoring text.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Sun 12 Sep 2010 10:19 PM (UTC)

Amended on Sun 12 Sep 2010 10:23 PM (UTC) by Nick Gammon

Message
Here is a more general solution...

First we want a multi-line trigger that has enough in it to match this line and hopefully exclude things that are completely irrevelant.


<triggers>
  <trigger
   enabled="y"
   lines_to_match="5"
   match="(?s)^[A-Z][A-Za-z]+ (slices|chops|hits|slashes) [^.]+\.\Z"
   multi_line="y"
   regexp="y"
   script="attack_trigger"
   sequence="110"
  >
  </trigger>
</triggers>


In this case I have tested for:


  • (?s) means "dot matches all" which means newlines can be part of a regular expression. Normally newlines terminate a regular expression.

  • First thing on line starts with a capital letter (A-Z) followed by at least one lower-case letter followed by a space. That hopefully gives matches on names (like Ryboi) but not stuff like prompts.

  • The words "(slices|chops|hits|slashes)" to try to identify this as one of your combat messages. You would put words here that would appear (the | means "or").

  • Any character other than a period. Excluding periods rules out double matches. Otherwise this would match twice:

    
    Ryboi slices across your head with a solar eclipse shofa, spilling stinging
    blood into your eyes.
    You go north.
    


  • A trailing period as the last character.


This gives a reasonable chance that the trigger will match multiple lines which are in the general category of what you want.

Now in the trigger script (in the script file, for convenience, because of the imbedded newlines and other reasons) we have this as the trigger function:


local attack_re = rex.new ("^(?<who>[A-Za-z]+) (?<attack>slices|chops|hits|slashes) across (?<where>.*) with (?<what>.*), spilling .*\.$")

function attack_trigger (name, line, wildcards)

  -- change newlines and multiple spaces into a single space
  local matching_text = string.gsub (wildcards [0], "%s+", " ")
  
  -- test full regular expression
  local s, e, t = attack_re:match (matching_text)

  -- see if match
  if s == nil then
    return
  end -- no match
  
  -- debugging
  print ("line=", matching_text)

  require "tprint"
  tprint (t)

end -- attack_trigger


The string.gsub fixes up the lines to change spaces and newlines to just spaces. This gets rid of the problem of imbedded newlines.

Now we make a more detailed regular expression using rex.new (this has the same syntax as the normal trigger regexps) and can now match as if we got a single line.

In this case I am pulling out who attacked us, with what, what sort of attack, and the effect of the attack.

My debugging output is:


Ryboi chops across your head with a solar eclipse shofa, spilling stinging
blood into your eyes.
line= Ryboi chops across your head with a solar eclipse shofa, spilling stinging blood into your eyes.
1="Ryboi"
2="chops"
3="your head"
4="a solar eclipse shofa"
"who"="Ryboi"
"what"="a solar eclipse shofa"
"where"="your head"
"attack"="chops"



This general technique could be applied to many cases where you need to match multiple lines.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


15,805 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]