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

Gammon Software Solutions forum

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

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Plugins
. . -> [Subject]  My first plugin... (Reboot Timer)
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

My first plugin... (Reboot Timer)

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by Shadowfyr   USA  (1,776 posts)  [Biography] bio
Date Thu 08 Aug 2002 06:17 AM (UTC)  quote  ]

Amended on Thu 08 Aug 2002 06:24 PM (UTC) by Shadowfyr

Message
This was designed to work with the 'uptime' command on Ages of Despair. Changing it for another muds command would require changing the trigger and a few wildcards in the setting script, but shouldn't be too hard.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE muclient >
<muclient>
<plugin name="Reboot_Timer"
  author="Kagehi"
  language="vbscript"
  purpose="Displays time until reboot in the status line."
  save_state="n"
  requires="3.23"
  version="1.0"
  id="d8008e74585e7435a82d1b12"
  >
<description trim="y">
<![CDATA[

Designed for the Ages of Despair mud.

This plugin reads the time until reboot from the 'uptime'
command and sets a counter in the clients status line,
indicating the time left once each minute.

Typing 'uptime' will set/reset it.

]]>
</description>
</plugin>

<!--
========================================
Startup Sub
========================================
-->
<script>
<![CDATA[
sub OnPluginConnect
   world.send "uptime"
end sub
]]>
</script>

<!--
========================================
Trigger SetReb
========================================
-->

<triggers>
  <trigger
   enabled="y"
   keep_evaluating="y"
   match="*The next reboot is * on * (in *)."
   name="SetReb"
   script="SetReb"
   sequence="3"
  >
  </trigger>
</triggers>
<script>
<![CDATA[
sub SetReb (TrigName, Output, Wildcards)
  dim sTest, sGrab, sOut
  dim sMatch
  sTest = wildcards(4) '"1d 1h 14m 33s"
  int b
  int tim
  int count
  tim = 0
  sMatch = split(sTest," ",-1,1)
  'world.note ubound(sMatch)
  for count = 0 to ubound(sMatch)
    sGrab = sMatch(count)
    b = len(sGrab)
    'world.note sGrab & ", " & count
    select case right(sGrab,1)
      case "d"
        tim = tim + 1440
      case "h"
        tim = tim + CInt(left(sGrab, b-1)) * 60
      case "m"
        tim = tim + CInt(left(sGrab, b-1))
      case "s"
        b = CInt(left(sGrab, b-1))
        if b > 30 then
          tim = tim + 1
        end if
    end select
  next
  world.setvariable "TTRB", CStr(tim)
  world.addtimer "RebootTimer", 0, 1, 0, "", 1, "RepReboot"
  world.enabletimer "RebootTimer", 1
  sOut = Rttt(tim)
  world.note "Reboot timer set."
  world.setstatus "Reboot is in " & sOut
end sub
]]>
</script>

<!--
========================================
Timer RebootTimer
========================================
-->

<timers>
  <timer name="RebootTimer" script="RepReboot" enabled="y" minute="1" active_closed="y" >
  </timer>
</timers>
<script>
<![CDATA[
sub RepReboot (TimerName)
  dim sRet, sOut, sTest
  int tim
  sRet = world.getvariable ("TTRB")
  tim = CInt(sRet)
  tim = tim - 1
  if tim < 1 then
    world.enabletimer "RebootTimer", 0
	 world.setstatus "Reboot!"
  else
    sOut = Rttt(tim)
    world.setstatus "Reboot is in " & sOut
    world.setvariable "TTRB", CStr(tim)
  end if
end sub

function Rttt(tim)
  dim sRet, sOut
  int temp
  int temp2
  temp = tim
  if temp > 1440 then
    sOut = " 1d "
    temp = temp - 1440
  end if
  if temp >= 60 then
    temp2 = Int(temp/60)
    temp = temp - (temp2 * 60)
    sOut = sOut & CStr(temp2) & "h "
  end if
  sOut = sOut & temp & "m."
  Rttt = sOut
end function
]]>
</script>


NOTE: The above script should now be complete, the following questions and comments have been left in place for thread completeness.

Just one thing... It is generally a good idea if one of the first commands sent to the mud after all they login is the 'uptime' command. You can do this in the main world by adding it in the connection settings, however... How do you have a plugin automatically execute the command automatically the same way?

main {
__if (Schrodinger_Cat is Alive or version >= "XP"){
____if version = "Vista" then Performance /= Number_of_Cores;
____call Functional_Code();}
__else
____call Crash_Windows();}
[Go to top] top

Posted by Magnum   Canada  (580 posts)  [Biography] bio
Date Reply #1 on Thu 08 Aug 2002 08:22 AM (UTC)  quote  ]
Message
Put commands in the mainline of the plugin, and they will execute when the plugin is loaded. Look at the sample script to see other routines like OnConnect where you could put them.

I wanted to offer some advice about the thread title you chose. It might be more helpful if you put the title of the plugin in the title, so that the thread can easily be found in the future. (Searching forums). Up to you of course... You don't have to listen to my little nit-picking. :)

Get my plugins here: http://www.magnumsworld.com/muds/

Constantly proving I don't know what I am doing...
Magnum.
[Go to top] top

Posted by Nick Gammon   Australia  (19,468 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Thu 08 Aug 2002 10:10 AM (UTC)  quote  ]
Message
Check out the sample plugin - the routine to be called when the mud connects is OnPluginConnect. There are a batch of those with hard-coded names.


sub OnPluginConnect
   world.note "Plugin " & world.getpluginname & " - world connected."
 end sub

- Nick Gammon

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

Posted by Shadowfyr   USA  (1,776 posts)  [Biography] bio
Date Reply #3 on Thu 08 Aug 2002 06:06 PM (UTC)  quote  ]
Message
Good advice on both counts.. I figured there had to be some sort of connect routine for the plugins, just not where to find them listed. While it is useful to have those routines listed in the sample plugin, it is not the first place I went looking. ;)

Oh... And not sure why, but seems 3.24 is picky about having a space between some things in the <plugin> block. One of your sample scripts won't load, because it insists there is no world ID in it. I had mine do the same thing. Turned out changing it from id = "d8008e... to id="d8008e was all I needed to get it loaded. This seems a bit nitpicky to me. :P

I will amend the original post to include the needed startup routine.

main {
__if (Schrodinger_Cat is Alive or version >= "XP"){
____if version = "Vista" then Performance /= Number_of_Cores;
____call Functional_Code();}
__else
____call Crash_Windows();}
[Go to top] top

Posted by Nick Gammon   Australia  (19,468 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Fri 09 Aug 2002 01:11 AM (UTC)  quote  ]

Amended on Fri 09 Aug 2002 01:13 AM (UTC) by Nick Gammon

Message
Quote:

And not sure why, but seems 3.24 is picky about having a space between some things in the <plugin> block. One of your sample scripts won't load, because it insists there is no world ID in it.


The sample plugin "sample_plugin.xml" has a deliberately bad plugin ID (with XXXs) so you aren't tempted to reuse that exact ID - thus, it won't load. If you want to see it in action, just make your own plugin ID (world.note world.getuniqueid), and paste that into the sample, and load it.


However I cannot reproduce the problem with the extra spaces. It isn't supposed to be picky. For instance, this loads OK:

id = "b5bd261daf097933034a2585"

- Nick Gammon

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

Posted by Nick Gammon   Australia  (19,468 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Fri 09 Aug 2002 01:14 AM (UTC)  quote  ]

Amended on Fri 09 Aug 2002 02:03 AM (UTC) by Nick Gammon

Message
Quote:

While it is useful to have those routines listed in the sample plugin, it is not the first place I went looking. ;)


Frankly, the documentation is not really finished (started?).

However I thought that one big example was worth 1000 words, so the documentation is currently "by example".

Also, the new Plugin Wizard will generate plugins for you quite easily, which will be helpful.

- 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,556 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [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.

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Web site powered by FutureQuest.Net]