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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  A trigger that attacks when they see another character attack.

A trigger that attacks when they see another character attack.

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


Posted by MythicalPlatypus   (3 posts)  [Biography] bio
Date Mon 28 May 2018 02:01 PM (UTC)

Amended on Mon 28 May 2018 02:03 PM (UTC) by MythicalPlatypus

Message
Im trying to work on a trigger that will input

"attack <name of creature"

whenever it sees

"Jinx just attacked the <imp|huge rat|any creature>"

My problem is that sometimes it is attacked "the imp" sometimes "the huge rat" "the female hobgoblin" "the lizard man", Etc... aswell as "the cyclops" (which works fine)

I can't quite figure out how to have it only select "rat", "lizard".

as I said it works with one worded creatures (aka Cyclops)

<triggers>
  <trigger
   enabled="y"
   group="auto attacks"
   keep_evaluating="y"
   match="^Jinx just attacked (?:the )?(.*?) with a (.*?)$"
   regexp="y"
   sequence="100"
  >
  <send>a %1
a %1
c dobuza %1</send>
  </trigger>
</triggers>

Thankyou for any input
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Mon 28 May 2018 09:10 PM (UTC)

Amended on Mon 28 May 2018 09:13 PM (UTC) by Nick Gammon

Message
The easiest thing in this case is to post-process the matching name to grab the last word, like this:


<triggers>
  <trigger
   enabled="y"
   group="auto attacks"
   keep_evaluating="y"
   match="^Jinx just attacked (?:the )?(.*?) with a (.*?)$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>

who = string.match ("%1", "%%S+$")

Send ("a " .. who)
Send ("a " .. who)
Send ("c dobuza " .. who)

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



The string.match there finds one or more characters which are not a space, at the end of the string. This will effectively be the last (or only) word.

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


The "send_to" being 12 means "send to script" (this will work if you follow the instructions above to paste it back into the client).

You need %% in the string.match, like I showed, to "escape" the meaning of a % in the send field. If you used a script file it would be done slightly differently, eg:


function attach_trigger (name, line, wildcards)
  who = string.match (wildcards [1], "%S+$")

  Send ("a " .. who)
  Send ("a " .. who)
  Send ("c dobuza " .. who)
end -- attach_trigger

- Nick Gammon

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

Posted by MythicalPlatypus   (3 posts)  [Biography] bio
Date Reply #2 on Mon 28 May 2018 11:02 PM (UTC)
Message
Hey thank-you so much for your help! It was very informative, Only one thing I have to ask is what does %S+$ do? I know "+" is one or more of the previous characters (be+d, Beeed etc..) and $ is end of string. But unsure as to what %S does? is it just code for not space? Because I would have assumed would would have been (! +$). Thank-you again.

Also do you mind if I ask more scripting questions in here or are new topics better?
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Tue 29 May 2018 07:00 AM (UTC)
Message
The page for string.find (which encompasses the syntax for string.match) explains it:

http://www.gammon.com.au/scripts/doc.php?lua=string.find

%S is indeed code for "not space". %s is the code for space.

So, %S+ is one or more of anything but a space.

The Lua pattern matching is a little different to regular expressions used in triggers.

Quote:

Also do you mind if I ask more scripting questions in here or are new topics better?


New topics are better, they are more easily searchable by other people.

- 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.


10,355 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]