Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, 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.
 Entire forum ➜ MUSHclient ➜ General ➜ Trigger to process time values from MUD output and execute delayed commands

Trigger to process time values from MUD output and execute delayed commands

You need to log onto the forum to reply or create new threads.

  Refresh page


Posted by Alobar   (3 posts)  Bio
Date Sun 25 Aug 2024 08:20 AM (UTC)
Message
Hello everyone,
My issue is, I want to create a trigger so that can catch the number within the sentence. It does not have to be sentence though. For example, Nick says, "Let's do this after 14 seconds" or Nick says, "11"
I did this:
<triggers>
<trigger
enabled="y"
match="Nick says, &quot;(*)&quot;"
send_to="12"
sequence="100"
>
<send>DoAfterSpecial (tonumber(%1), "kick troll"</send>
</trigger>
</triggers>
So script is not giving any error but not working too. What am i doing wrong?
Top

Posted by Nick Gammon   Australia  (23,057 posts)  Bio   Forum Administrator
Date Reply #1 on Sun 25 Aug 2024 09:45 AM (UTC)

Amended on Sun 25 Aug 2024 09:46 AM (UTC) by Nick Gammon

Message
To pluck a number out of a string like that you need a regular expression, like this:


<triggers>
  <trigger
   enabled="y"
   match="^Nick says\, &quot;[^\d]*(\d+).*&quot;$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>DoAfter (tonumber(%1), "kick troll")</send>
  </trigger>
</triggers>


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


That is matching on any number of characters that are not digits, capturing one or more digits, and then any number of characters after the digits.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Alobar   (3 posts)  Bio
Date Reply #2 on Sun 25 Aug 2024 10:02 AM (UTC)
Message
Thank you. How i couldn't thinkt regexp. I am kinda new at scripting. So, last question maybe, think that a command produces multiple lines of output. What i can do to interract (catch) the first line of output after sending specific command?
Top

Posted by Nick Gammon   Australia  (23,057 posts)  Bio   Forum Administrator
Date Reply #3 on Sun 25 Aug 2024 08:28 PM (UTC)
Message
One approach would be turn turn on a flag in an alias. For example you type "foo" and make an alias that matches "foo" and sets a flag to true (in a script). Then it sends "foo" to the MUD.

Then make a trigger that matches anything (*), and in a script it tests if the flag is set, and if so takes some action, and then clears that flag.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Alobar   (3 posts)  Bio
Date Reply #4 on Mon 26 Aug 2024 08:49 AM (UTC)
Message
"No, I mean, OK, that approach would work, but the thing is, the output will never stay the same. For example, when you type 'scan,' you will see different mobs. I want to catch the first line of the scan results. OK, I know I am asking a lot, but I need something too. I couldn't find the answer properly. So, I need to define a variable from an output message to use it in different triggers. For example, if Nick says, 'This is a book,' I want to get the 'book' part (or it could be something else like 'This is a tablet') and define it as a variable. Then I want to use this variable in a trigger. Another example: 'It's time to drop the objects on the ground that were mentioned to you!' Here, I would want to drop the variable (like 'book' or 'tablet'). How can I do this?"
Top

Posted by Nick Gammon   Australia  (23,057 posts)  Bio   Forum Administrator
Date Reply #5 on Mon 26 Aug 2024 08:56 PM (UTC)

Amended on Mon 26 Aug 2024 08:57 PM (UTC) by Nick Gammon

Message
Well, how about this?


<aliases>
  <alias
   match="scan*"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>

EnableTrigger ("scan_output", true)  -- catch scan output
SetVariable ("scan_result", "")  -- no result yet
Send ("%0")   -- send the command to the MUD

</send>
  </alias>
</aliases>


<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   match="It's time to drop the objects on the ground that were mentioned to you!"
   sequence="100"
  >
  <send>drop @last_scan</send>
  </trigger>


  <trigger
   match="This is a *"
   name="scan_output"
   send_to="12"
   sequence="100"
  >
  <send>

SetVariable ("last_scan", "%1")  -- save what was scanned
EnableTrigger ("scan_output", false)  -- disable ourself
Note ("Scan revealed: %0")

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



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


When you type "scan" or "scan something" it enables the trigger to capture the scan results. Then the trigger that matches "This is a *" will save the thing that was found into a variable.

Then when you see the message "It's time to drop the objects on the ground that were mentioned to you!" another trigger sends the contents of "last_scan" variable to the MUD.

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


627 views.

You need to log onto the forum to reply or create new threads.

  Refresh page

Go to topic:           Search the forum


[Go to top] top

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