Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ General
➜ 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 page
Posted by
| MythicalPlatypus
(3 posts) 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 | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) 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.
 |
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 | Top |
|
Posted by
| MythicalPlatypus
(3 posts) 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? | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) 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 | 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.
12,006 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top