Register forum user name Search FAQ

Gammon Forum

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.
 Entire forum ➜ MUSHclient ➜ Plugins ➜ Enable/Disable plugin's automatically.

Enable/Disable plugin's automatically.

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


Posted by LupusFatalis   (154 posts)  Bio
Date Thu 23 Apr 2009 07:16 PM (UTC)
Message
Ok, so I've been making a ton of little plugins for learning skills and so forth, to automate the process. MUSHclient doesn't seem to store the last state of the plugin, i.e. enabled/disabled. So what I'd like to do, is make all of my learning plugins disable themselves before I connect to the mud. This way I don't log in and immediately start trying to chop down trees, cast spells, and kill npcs all at once, lol... Any ideas on how to accomplish this?

As an aside, I imagine a response to this will also answer my question as to how to have a plugin disable itself once it completes a given task.

Thanks again folks.
Top

Posted by Worstje   Netherlands  (899 posts)  Bio
Date Reply #1 on Fri 24 Apr 2009 01:50 AM (UTC)
Message
You are probably looking at the wrong 'level' of things for what you want to do. Enabling and disabling plugins is meant for users, not for your script.

What you want to do is to give the relevant triggers, aliases and timers a group attribute, and then use EnableGroup to enable or disable them when you need to.

This could be in the OnPluginConnect() callback, for example:


function OnPluginConnect()
  EnableTrigger("woodcutting", false)  -- disable woodcutting.
end
Top

Posted by Nick Gammon   Australia  (23,121 posts)  Bio   Forum Administrator
Date Reply #2 on Fri 24 Apr 2009 04:41 AM (UTC)

Amended on Fri 24 Apr 2009 04:50 AM (UTC) by Nick Gammon

Message
It doesn't remember the enabled state, but you can add that in, like this:


function OnPluginInstall ()

  -- other installation stuff here
  
  if GetVariable ("enabled") == "false" then
    ColourNote ("yellow", "", "Warning: Plugin " .. GetPluginName ().. " is currently disabled.")
    EnablePlugin (GetPluginID (), false)
    return
  end -- they didn't enable us last time
   

  -- if we didn't return (ie. we are enabled) then show windows etc.

end -- OnPluginInstall



function OnPluginSaveState ()

  -- remember if this plugin is disabled

  SetVariable ("enabled",     tostring (GetPluginInfo (GetPluginID (), 17)))

  -- other save state stuff here

end -- OnPluginSaveState


This saves in the state file whether or not you currently have it enabled, and next time it loads, it disables itself if necessary.

For this to work you need "save_state" to be "y" in the plugin header, like this:


<plugin
   name="Icon_Bar"
   author="Nick Gammon"
   id="ede0920fc1173d5a03140f0e"
   language="Lua"
   purpose="Shows a bar of buttons you can click on to do things"
   date_written="2009-02-26 09:00"
   date_modified="2009-04-02 12:15"
   requires="4.37"
   save_state="y"
   version="4.0"
   >


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,121 posts)  Bio   Forum Administrator
Date Reply #3 on Fri 24 Apr 2009 04:52 AM (UTC)
Message
If you just want a plugin to auto-disable on connect, then just do this:


function OnPluginConnect()
  EnablePlugin (GetPluginID (), false)  -- disable me
end


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by LupusFatalis   (154 posts)  Bio
Date Reply #4 on Fri 24 Apr 2009 05:46 AM (UTC)
Message
Exactly what I needed Nick... I might tinker with the first one, but the second bit is all I want in this case... For anyone who cares--in python it looks like...
def OnPluginConnect():
	world.EnablePlugin (world.GetPluginID, 'false')
Top

Posted by Wissie12   (1 post)  Bio
Date Reply #5 on Thu 02 Jul 2009 07:41 PM (UTC)
Message
I'm completely new to this whole MUSH/plug-in thing and i was just wondering where you would put that code in? On its own or add it to the end of the plug-in you want to disable?

Thanks!
Top

Posted by Nick Gammon   Australia  (23,121 posts)  Bio   Forum Administrator
Date Reply #6 on Thu 02 Jul 2009 10:24 PM (UTC)

Amended on Thu 02 Jul 2009 10:25 PM (UTC) by Nick Gammon

Message
I'll do an example ...

Let's start with a simple, existing plugin that doesn't have the enable/disable code in it:


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

<muclient>
<plugin
   name="Auto_Save"
   author="Nick Gammon"
   id="3ea0bfc4db127153568ff673"
   language="Lua"
   purpose="Saves the world file periodically"
   date_written="2009-02-25 17:50:10"
   requires="4.00"
   version="1.0"
   >
<description trim="y">
<![CDATA[
Saves the world file periodically.
Default is every 5 minutes.
]]>
</description>

</plugin>


<!--  Timers  -->

<timers>
  <timer 
    enabled="y" 
    minute="5" 
    send_to="12"
>
  <send>

if GetInfo (111) then  -- world file changed?
  if Save () == false then
    ColourNote ("green", "", "World file saved.")
  else
    ColourNote ("white", "red", "Couldn't save world file.")
  end -- if
end -- if world file changed

</send>

  </timer>
</timers>

</muclient>



This plugin (I think it ships with MUSHclient) automatically saves the world every 5 minutes.

This particular plugin does not have a <script> section (a lot will have), so we first need to add that in:


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

<muclient>
<plugin
   name="Auto_Save"
   author="Nick Gammon"
   id="3ea0bfc4db127153568ff673"
   language="Lua"
   purpose="Saves the world file periodically"
   date_written="2009-02-25 17:50:10"
   requires="4.00"
   version="1.0"
   >
<description trim="y">
<![CDATA[
Saves the world file periodically.
Default is every 5 minutes.
]]>
</description>

</plugin>


<!--  Timers  -->

<timers>
  <timer 
    enabled="y" 
    minute="5" 
    send_to="12"
>
  <send>

if GetInfo (111) then  -- world file changed?
  if Save () == false then
    ColourNote ("green", "", "World file saved.")
  else
    ColourNote ("white", "red", "Couldn't save world file.")
  end -- if
end -- if world file changed

</send>

  </timer>
</timers>


<!--  Script  -->


<script>
<![CDATA[


]]>
</script>


</muclient>



A lot of plugins will already have a <script> section so in that case you would just find the <script> and </script> tags to find where it is (usually towards the bottom of the plugin).

Note that the <script> section goes before the final </muclient> tag.

Now to change the plugin so it disables itself when you connect (not when it is installed) add the lines from a couple of posts up:


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

<muclient>
<plugin
   name="Auto_Save"
   author="Nick Gammon"
   id="3ea0bfc4db127153568ff673"
   language="Lua"
   purpose="Saves the world file periodically"
   date_written="2009-02-25 17:50:10"
   requires="4.00"
   version="1.0"
   >
<description trim="y">
<![CDATA[
Saves the world file periodically.
Default is every 5 minutes.
]]>
</description>

</plugin>


<!--  Timers  -->

<timers>
  <timer 
    enabled="y" 
    minute="5" 
    send_to="12"
>
  <send>

if GetInfo (111) then  -- world file changed?
  if Save () == false then
    ColourNote ("green", "", "World file saved.")
  else
    ColourNote ("white", "red", "Couldn't save world file.")
  end -- if
end -- if world file changed

</send>

  </timer>
</timers>

<!--  Script  -->


<script>
<![CDATA[


function OnPluginConnect()
  EnablePlugin (GetPluginID (), false)  -- disable me
end


]]>
</script>

</muclient>



The lines for the OnPluginConnect function are added before the </script> tag (in other words, inside the script section.

However to make the plugin "remember its enabled state" we need to do a bit more.



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

<muclient>
<plugin
   name="Auto_Save"
   author="Nick Gammon"
   id="3ea0bfc4db127153568ff673"
   language="Lua"
   purpose="Saves the world file periodically"
   date_written="2009-02-25 17:50:10"
   requires="4.00"
   save_state="y"
   version="1.0"
   >
<description trim="y">
<![CDATA[
Saves the world file periodically.
Default is every 5 minutes.
]]>
</description>

</plugin>


<!--  Timers  -->

<timers>
  <timer 
    enabled="y" 
    minute="5" 
    send_to="12"
>
  <send>

if GetInfo (111) then  -- world file changed?
  if Save () == false then
    ColourNote ("green", "", "World file saved.")
  else
    ColourNote ("white", "red", "Couldn't save world file.")
  end -- if
end -- if world file changed

</send>

  </timer>
</timers>

<!--  Script  -->


<script>
<![CDATA[


function OnPluginInstall ()

  -- other installation stuff here
  
  if GetVariable ("enabled") == "false" then
    ColourNote ("yellow", "", "Warning: Plugin " .. GetPluginName ().. " is currently disabled.")
    EnablePlugin (GetPluginID (), false)
    return
  end -- they didn't enable us last time
   

  -- if we didn't return (ie. we are enabled) then show windows etc.

end -- OnPluginInstall



function OnPluginSaveState ()

  -- remember if this plugin is disabled

  SetVariable ("enabled",     tostring (GetPluginInfo (GetPluginID (), 17)))

  -- other save state stuff here

end -- OnPluginSaveState


]]>
</script>

</muclient>



I have added the "save_state" line to the plugin header (near the top) and two extra functions instead of the one earlier. In OnPluginInstall we get the state from last time, and if it was disabled, we disable ourselves now. In OnPluginSaveState we remember whether we are currently disabled or not.

It is possible those functions themselves already exist (you need to check these things on a case-by-case basis). If so, the relevant lines inside the functions need to be added to the existing OnPluginInstall and OnPluginSaveState functions.

- 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.


23,270 views.

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

Go to topic:           Search the forum


[Go to top] top

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