Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, 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.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ General
➜ Actions on Idle
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Traz
(31 posts) Bio
|
| Date
| Tue 27 Mar 2018 02:15 AM (UTC) |
| Message
| I was looking to see if it was possible to do some actions after idling for a set period of time. I looked around and found the plugin that was made for marking yourself as AFK, but I would like to do something different.
An example is after about 2 minutes of idle time, I'd like to execute my sleep alias.
Also, the plugin used OnPluginCommand which could tell when something was typed. I'd like something that can also check if triggers are going off so it doesn't decide to idle while I'm doing something automated.
Any help would be appreciated. | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Tue 27 Mar 2018 02:23 AM (UTC) |
| Message
| First check out plugin callbacks. In particular OnPluginSent. That lets you know that something has been sent to the MUD (by you or by some script).
What you could do is have a 2-minute timer. When that timer fires you can do your “idle” stuff like sleeping. However to prevent it firing while you are doing stuff, in the plugin callback OnPluginSent you call ResetTimer which resets the timer so it goes back to timing 2 minutes again.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Traz
(31 posts) Bio
|
| Date
| Reply #2 on Tue 27 Mar 2018 03:33 AM (UTC) Amended on Tue 27 Mar 2018 03:49 AM (UTC) by Traz
|
| Message
| Ok, so I tried this, but the timer kept counting down, not caring that something was going on.
<timers>
<timer name="IdleSense" minute="5" second="0.00" offset_second="0.00" send_to="12"
group="NecroM" >
<send>
function OnPluginSent (sText)
ResetTimer ("IdleSense")
end
Execute ("sleep")
</send>
</timer>
</timers>
Edit: Just as a side note, the timer is off currently because I couldn't get it to work, so that is not the reason it doesn't work.
Edit2: I think you might have misunderstood and thought I was making a plugin. I was just referring to the AFK plugin. I can see why what I did won't work but I don't know how to make it work. | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #3 on Tue 27 Mar 2018 05:54 AM (UTC) Amended on Tue 27 Mar 2018 07:46 AM (UTC) by Nick Gammon
|
| Message
| You can't shove the OnPluginSent function into something that a timer calls and hope for it to work. (Well, you can hope, but it won't!).
Writing a plugin is quite easy, there is a plugin wizard for that.
Here is a simple plugin that does what you want:
 |
To save and install the Do_Something_When_Idle plugin do this:
- Copy between the lines below (to the Clipboard)
- Open a text editor (such as Notepad) and paste the plugin into it
- Save to disk on your PC, preferably in your plugins directory, as Do_Something_When_Idle.xml
- Go to the MUSHclient File menu -> Plugins
- Click "Add"
- Choose the file Do_Something_When_Idle.xml (which you just saved in step 3) as a plugin
- Click "Close"
|
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<muclient>
<plugin
name="Do_Something_When_Idle"
author="Nick Gammon"
id="3dd3eb0ecf9eb5b183c98fec"
language="Lua"
purpose="Send a sleep command if you are idle"
date_written="2018-03-27 15:34:55"
requires="4.90"
version="1.0"
>
<description trim="y">
<![CDATA[
Sends "sleep" if you are idle for 5 minutes.
]]>
</description>
</plugin>
<!-- Timers -->
<timers>
<timer name="IdleSense"
enabled="y"
minute="5"
second="0.00"
send_to="12"
group="NecroM" >
<send>
if not timerFired then
Execute ("sleep")
timerFired = true
end -- if not already done it
</send>
</timer>
</timers>
<!-- Script -->
<script>
<![CDATA[
function OnPluginSent (sText)
ResetTimer ("IdleSense")
timerFired = false
end
]]>
</script>
</muclient>
Testing showed an interesting problem. The timer would keep firing every 5 minutes, attempting to put you to sleep again. So what this does is remember when you send the "sleep" command so you don't do it again. This "remembering" is cleared when you send something new.
This has to be done after sending "sleep" otherwise that counts as doing something new. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Traz
(31 posts) Bio
|
| Date
| Reply #4 on Tue 27 Mar 2018 06:09 AM (UTC) |
| Message
| | The problem is, I want to be able to turn it off and potentially use this same concept in different scenarios. Can you turn off/on a plugin with an alias? | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #5 on Tue 27 Mar 2018 06:17 AM (UTC) Amended on Tue 27 Mar 2018 06:27 AM (UTC) by Nick Gammon
|
| Message
| You can certainly disable plugins with an alias.
What you could do is make a "sleep" alias which catches your attempt to sleep and do it conditionally. Or, if you don't want to lose the sleep command, make the plugin send Execute something random like "ebf9035ff8421255fc1c68d8" and then make an alias to match that. You can then do something in that alias like:
if I_want_to_sleep then
Send "sleep"
end -- if
|
- 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.
21,478 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top