Timer plugin

Posted by Nick Gammon on Wed 03 Mar 2004 08:40 PM — 1 posts, 7,842 views.

Australia Forum Administrator #0
The plugin below calculates elapsed time from when you connected and shows it in the status bar. It can be reset by typing "timerreset" so you can use it for timing any event (eg. you have 10 minutes to find your corpse).



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE muclient>
<!-- Saved on Thursday, March 04, 2004, 7:32 AM -->
<!-- MuClient version 3.42 -->

<!-- Plugin "Timer" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Timer"
   author="Nick Gammon"
   id="cc98cbe576474a19d1715a02"
   language="VBscript"
   purpose="Shows elapsed time in status bar"
   date_written="2004-03-04 07:29:18"
   requires="3.30"
   version="1.0"
   >
<description trim="y">
<![CDATA[
This plugin displays time connected in the status bar. 
It can be reset to zero when you like.

The time is shown as hours and minutes (eg. 4h 22m) - if you are connected for 
more than a day then it will show more than 24 hours. 
You could amend it slightly to change that if you wanted.

Commands
--------

timerreset  - reset timer to zero
Timer:help  - show this help
]]>
</description>

</plugin>


<!--  Aliases  -->

<aliases>
  <alias
   script="TimerToZero"
   match="resettimer"
   enabled="y"
   send_to="2"
   sequence="100"
  >
  <send>Timer reset.</send>
  </alias>
</aliases>

<!--  Timers  -->

<timers>
  <timer name="StatusBarTimer" script="ElapsedTimer" enabled="y" second="30" >

  </timer>
</timers>

<!--  Script  -->


<script>
<![CDATA[
'
'  Timer showing when we last connected
'

dim tConnected

tConnected = Now

'
' This world has been connected (to the MUD)
'
sub OnPluginConnect
  tConnected = Now
  Call ElapsedTimer ("StatusBarTimer")
end sub

'
' Plugin has been installed
'
sub OnPluginInstall
  Call OnPluginConnect
end sub

'
'  Called by alias to zero timer
'
Sub TimerToZero (sName, sLine, wildcards)
  Call OnPluginConnect
End Sub

'
'  Called when timer fires
'
Sub ElapsedTimer (sName)

dim Minutes, Hours

'
'  Calculate how long in minutes
'
  Minutes = DateDiff ("n", tConnected, Now)

'
'  Convert to hours and minutes
'
  Hours = Int (Minutes / 60)	
  Minutes = Minutes - (Hours * 60)

'
'  Update status bar
'
  SetStatus "Timer: " & Hours & "h " & Minutes & "m"
End Sub

'
' Plugin is being removed (closed)
'
sub OnPluginClose
  SetStatus "Ready"
end sub

]]>
</script>


<!--  Plugin help  -->

<aliases>
  <alias
   script="OnHelp"
   match="Timer:help"
   enabled="y"
  >
  </alias>
</aliases>

<script>
<![CDATA[
Sub OnHelp (sName, sLine, wildcards)
  world.Note world.GetPluginInfo (world.GetPluginID, 3)
End Sub
]]>
</script> 

</muclient>