Command Delay

Posted by Drakonik on Sun 09 Dec 2007 01:30 AM — 4 posts, 22,524 views.

#0
The MUD I play just implemented a 2 command buffer, with a .5 second delay between commands. What I want to do is to put a .6 second delay between ALL commands. That means aliases, macros, triggers, and even commands which I queue up using the command stacking.

Is this even possible?
Australia Forum Administrator #1
Yes I think you could do this. I am not at my PC right now, but the general technique would be to:

  • Make a plugin that implements the function OnPluginSend to capture all attempts to send data to the MUD. See:

    http://www.gammon.com.au/scripts/doc.php?general=plugin_callbacks
  • Instead of allowing it to be sent, it would store it into a queue (for later sending), and return 'false' so the text is not sent right now.
  • Make a timer that fires every 0.6 seconds. This timer pulls out the first item from the queue mentioned above (if any), and sends it.
  • The plugin would need some sort of internal flag, so it knows when the timer fires to allow the text to be actually sent, rather than re-appended to the queue.
Amended on Sun 09 Dec 2007 04:44 AM by Nick Gammon
#2
You might want to make some kind of check where when you send the command, it checks your queue to see if it has anything in it. If it doesn't, the command is executed immediately and then turns queuing on so that for the next 0.6 seconds, additional commands are queued and if other commands are entered, it keeps queuing commands for 0.6 seconds until you stop entering commands. If you don't do this, I think everytime you enter a simple command like who or look, it'll wait queue the command and won't execute for 0.6 seconds, which might get a tad bit annoying.
Australia Forum Administrator #3
Yes I agree, although that could be fiddly to implement. Just checking the queue is empty and sending immediately won't work, as you might have sent something 0.1 seconds earlier.

Quote:

... everytime you enter a simple command like who or look, it'll wait queue the command and won't execute for 0.6 seconds ...


Not quite. It will execute in a maximum of 0.6 seconds. If the timer fires every 0.6 seconds, then it might be about to fire anyway (like 0.001 seconds later). The way I suggested you would wait a maximum of 0.6 seconds for individual commands, and therefore the average wait would be 0.3 seconds.