[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Passing command through idle-timer alias
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Passing command through idle-timer alias

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Dragonatorul   (2 posts)  [Biography] bio
Date Fri 08 Jan 2016 09:13 PM (UTC)
Message
Hello,

I'm trying to set up a way to be notified if I've been idle for 15, 20, and 25 minutes.

The way I thought of is to set up an alias that captures every command I send to the world and passes it through to the world, while at the same time creating 3 timers which set off a function that plays a "ding". However, I'm having trouble with the passing the command through to the world.

If I setup an alias to capture

^(.*?)$


and set up the body of the alias with the function:

Send(%1)


If I set it to send this to the world and type the command look it sends this to the world:

Send(look)


If I set it to send to Script it sends this to the world:

nil


I'm stumped because it seems to capture it properly when sending to the world, but not when sending to the script, then passing back to the world.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Fri 08 Jan 2016 09:48 PM (UTC)

Amended on Sat 09 Jan 2016 02:36 AM (UTC) by Nick Gammon

Message
You could make a small plugin that uses the OnPluginCommand callback to find when you actually typed a command.

Something like the one below:


Template:saveplugin=IdleWarning To save and install the IdleWarning plugin do this:
  1. Copy between the lines below (to the Clipboard)
  2. Open a text editor (such as Notepad) and paste the plugin into it
  3. Save to disk on your PC, preferably in your plugins directory, as IdleWarning.xml
  4. Go to the MUSHclient File menu -> Plugins
  5. Click "Add"
  6. Choose the file IdleWarning.xml (which you just saved in step 3) as a plugin
  7. Click "Close"




<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>

<muclient>
<plugin
   name="IdleWarning"
   author="Nick Gammon"
   id="9c9c760caf80e43893bb7b70"
   language="Lua"
   purpose="Warns when you are idle"
   date_written="2016-01-09 08:22:56"
   requires="4.90"
   version="1.0"
   >
</plugin>

<!--  Timers  -->

<timers>
  <timer 
    name="timer1" 
    enabled="y"
    minute="15"  
    send_to="1"
    script="OnIdleTimeout"
  >
  </timer>
  
  <timer 
    name="timer2" 
    enabled="y"
    minute="20"  
    send_to="1"
    script="OnIdleTimeout"
  >
  </timer>
  
  <timer 
    name="timer3" 
    enabled="y"
    minute="25"  
    send_to="1"
    script="OnIdleTimeout"
  >
  </timer>
      
</timers>

<!--  Script  -->


<script>
<![CDATA[

playedDing = {}  -- empty table
lastCommand = os.time ()

function OnPluginCommand ()
  ResetTimers ()   -- all timers start again
  playedDing = {}  -- reset table of played dings
  lastCommand = os.time ()
  return true -- process this command
end -- OnPluginCommand

function OnIdleTimeout (name)
  
  -- don't play it twice
  if playedDing [name] then
    return
  end -- if
  
  playedDing [name] = true
  PlaySound (0, "ding.wav")
  minutes = (os.time () - lastCommand) / 60
  ColourNote ("yellow", "", string.format ("WARNING: You have been idle for %i minutes now.", minutes))
end -- OnIdleTimeout

]]>
</script>

</muclient>


Note that the sound file should be in the "sounds" directory under the MUSHclient install folder.

The only file type supported is a .wav file, as follows:

* 16-bit
* 22.05 KHz
* PCM (ie. uncompressed)
* Mono or Stereo

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Sat 09 Jan 2016 04:52 AM (UTC)

Amended on Sat 09 Jan 2016 04:53 AM (UTC) by Nick Gammon

Message
Quote:

... and set up the body of the alias with the function:

Send(%1)


Related to your question:

Template:faq=32 Please read the MUSHclient FAQ - point 32.


It would have worked better as:


Send("%1")

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Dragonatorul   (2 posts)  [Biography] bio
Date Reply #3 on Sat 09 Jan 2016 04:19 PM (UTC)
Message
Nick Gammon said:

You could make a small plugin that uses the OnPluginCommand callback to find when you actually typed a command.

Something like the one below:



Did you just write the plugin I was trying to write myself? You are AWESOME! Thank you!

Also thanks for clearing that lua value quote up for me. I have very little experience in Lua, having mostly worked with Java so far, but am learning as I go thanks to your client.

I'd also like to say you did an awesome job with the MUSHclient and thank you for making it available.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Sun 10 Jan 2016 06:33 AM (UTC)
Message
Quote:

Did you just write the plugin I was trying to write myself?


Yes I did. I thought other people might find it useful too. :)

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] 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.


2,575 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]