Want an alias to repeat a number of commands at a certain time

Posted by Xandler on Mon 05 Jul 2021 04:59 PM — 4 posts, 17,422 views.

#0
Trying to build something out so my character will do X amount of things at a certain time (ie eat 30 pieces of bread at midnight).

I have adapted the alias found here:

https://www.gammon.com.au/forum/?id=8473

to something similar (just changed the initial repeat symbol)


<aliases>
  <alias
   name="itemrepeat"
   match="^@\s*(\d+) (.*?)$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>-- check at least 1 repeat
if %1 &lt; 1 then
  ColourNote ("white", "red", "Too few repeats specified (%1)")
  return
end -- if

-- check not more than 1000 repeats
if %1 &gt; 1000 then
  ColourNote ("white", "red", "Too many repeats specified (%1)")
  return
end -- if

-- execute (send to command processor) the command
for i = 1, %1 do
  Execute "%2"
end -- for loop</send>
  </alias>
</aliases>


Is there a way to adapt this into doing a set amount of things at a certain time like I stated initially? I figure it would be some sort of timer that's set to At this time instead of every interval, but that's as far as I've gotten. I have no idea how to produce the result I want. Any help would be fantastic!
Australia Forum Administrator #1
Timers can fire at a certain time, so this example shows how a script executes every day at 9:30 AM. You could change that to 23:59, if you wanted it to fire close to midnight.


<timers>
  <timer enabled="y" 
         hour="9" 
         minute="30" 
         second="0.00"
         send_to="12"
         at_time="y" 
   >
  <send>
  
  print ("Timer fired at 9:30 AM")

  </send>
  </timer>
</timers>



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


My example sends to "Script" but you could send to "Execute" if you want to do thing like aliases which are set up elsewhere.




If you want to make an alias to do this (rather than just making the timer) you can use the addxml module documented here: http://www.gammon.com.au/forum/?id=7123

So now your alias can add a timer (like below) and the thing to send, and the time to send it could be passed into the code below rather than being hard-coded.


require "addxml"
addxml.timer {  name = "mytimer",
                hour = 9,
                minute = 35,

                -- the thing to send
                send = [[

                print ("hi there!")

                ]],
                enabled = true,
                at_time = true,
                send_to = sendto.script,
              }
#2
I understand what you're saying (I don't think it's quite what I'm looking for), long story short, I want the alias to do say @30 eat bread at a certain time (which would process eat bread 30 times), is there a way to adapt that alias into a timed interval so it fires at a certain time of day?
Australia Forum Administrator #3
Well, you do what I said in reply #1, and make it send to "execute" and in that do your other alias to do something 30 times.