Welcome to the first tutorial on how to create plugins for the framework. Before you start make sure you have the basic knowledge about bot creation like sending messages to Everybodyedits or receiving them. Visit Capasha´s site for more information.
First of all we need to set up our project to create plugins. I´ll use Visual Studio C# Express 2010 but it should also work with other IDEs. After you downloaded the current framework-package and created a new ClassLibrary-Project, you´ll find a dll called 'IBotPlugin.dll'. Add a reference to this dll to your project. You´ll also need to reference the PlayerIOClient.dll which can be downloaded with the PlayerIO-Development-Package. After you´ve done this you should remove all other references from your project. If you´re finished with this your last step is to set the property 'Local Copy' of both dlls to false, so they will be packed into your dll.
First the whole barebone you need for a plugin. For now you can just copy and paste it. We´ll go through it later.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using PlayerIOClient; using IBotPlugin; namespace Plugin { public class Barebone : IBotPlugin.IBotPlugin { private IBotHoster _host; private bool enabled; public string GetName() { return "MyPlugin"; } public int GetVersion() { return 1; } public void OnLoad() { } public void SetHoster(IBotHoster hoster) { _host = hoster; } public List<ICommandInfo> GetCommands() { return null; } public void OnEnable() { enabled = true; // Register your message handlers HERE } public void OnDisable() { enabled = false; // Unregister your message handlers HERE } public bool IsEnabled() { return enabled; } public float GetCodeBase() { // Return the version of the framework your plugin is made for. return 1.72f; } } }
Now let´s go through it.
The first part you may notice is this:
public class Barebone : IBotPlugin.IBotPlugin
As you may now a colon shows that a class extends another class (or implements an interface like in our case). You EVER need to extend the IBotPlugin.IBotPlugin-Interface or your plugin won´t be loaded correctly.
The second part are all those functions. You need to implement all of them or the compiler will give you an error. The first function is public string GetName()
. Here you only return your plugins name. Same thing with public int GetVersion()
except you return your plugins version (in this case that´s an 1).
Another quite important function is public void SetHoster(IBotHoster hoster)
.
You have to know this method is called when your plugin is loaded and gets the framework as an instance. So it´s a good idea to keep this value for later.
public List<ICommandInfo> GetCommands()
is currently under development and does NOT work correct currently. So simply return null
.
Next there is the public void OnLoad()
-function. This method is similiar to the Main()-method.
Now there are the function called public void OnEnable()
and public void OnDisable()
. Those are called when your plugin is enabled or disabled by the user. You should register / unregister your message handlers here. You should also save a bool if your plugin was enabled to return in public bool IsEnabled()
.
Last but not least there is the method public float GetCodeBase()
. Simply return the version of the highest framework you tested your plugin successfully with.
That´s it. That´s the fully working barebone you need for a working plugin! Why don´t you compile your code and give it a little test run? If everything works correctly there should show up a message that your plugin (extension) was loaded correctly!
>> Next to Tutorial No. 2
^^ Back to the overview