Delay Trigger until Action

Posted by Traz on Tue 16 Jan 2018 09:24 PM — 5 posts, 20,622 views.

#0

<triggers>
  <trigger
   enabled="y"
   group="Fried"
   match="* opens his mouth and fires a powerful blast at * that causes * to fall in pain!"
   send_to="12"
   sequence="100"
  >
  <send>if lastTriggerTime == nil or os.time () - lastTriggerTime &gt;= 5 then
  Send ("--")
  Send ("assist caldar")
--insert delay here--
  Send ("shoge")
  Send ("rune")
  Send ("shoge")
  Send ("shoge")
  lastTriggerTime = os.time ()
end</send>
  </trigger>
</triggers>


I'm trying to delay the above trigger to delay the four Sends after "assist caldar".

If possible, I would like to delay it until the mud sees the output "* flies down and lands on the ground." otherwise a 2 second delay would be enough.
Amended on Tue 16 Jan 2018 11:33 PM by Nick Gammon
Australia Forum Administrator #1
See "Pausing a script until input arrives from the MUD":

http://www.gammon.com.au/forum/?id=4957
Australia Forum Administrator #2
Basically it would look like this:


<triggers>
  <trigger
   enabled="y"
   group="Fried"
   match="* opens his mouth and fires a powerful blast at * that causes * to fall in pain!"
   send_to="12"
   sequence="100"
  >
  <send>

require "wait"

wait.make (function ()
  if lastTriggerTime == nil or os.time () - lastTriggerTime &gt;= 5 then
    Send ("--")
    Send ("assist caldar")
    wait.regexp ("^.* flies down and lands on the ground\.$", 3)  -- wait for message or 3 second timeout
    Send ("shoge")
    Send ("rune")
    Send ("shoge")
    Send ("shoge")
    lastTriggerTime = os.time ()
  end
end)  -- end of wait.make

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


Template:pasting
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.
Amended on Tue 16 Jan 2018 11:32 PM by Nick Gammon
#3
Not sure what I'm not understanding but I keep getting some pretty lengthy compile errors. This is what I came up with.

<triggers>
  <trigger
   group="FriedTest"
   match="* opens his mouth and fires a powerful blast at * that causes * to fall in pain!"
   send_to="12"
   sequence="100"
  >
  <send>require "wait"
if lastTriggerTime == nil or os.time () - lastTriggerTime &gt;= 5 then
  Send ("--")
  Send ("assist caldar")
    wait.make (function ()
      Send ("shoge")
      Send ("rune")
      Send ("shoge")
      Send ("shoge")
        wait.regexp ("* flies down and lands on the ground.")
    end)
  lastTriggerTime = os.time ()
end</send>
  </trigger>
</triggers>


edit: Just saw the reply above. Was testing it before I refreshed the page and saw that.

For clarification sake, what is the purpose of the symbols in the regexp?
Amended on Tue 16 Jan 2018 11:52 PM by Traz
Australia Forum Administrator #4
See the documentation about regular expressions: http://www.gammon.com.au/regexp

Basically:


^  <-- asserts (matches) start of line

.* <-- matches zero or more of any character

 flies down and lands on the ground  <-- matches itself literally

\.  <-- matches a period

$    <-- asserts (matches) end of line