Basic Plugin Guide
The forums have a lot of info and even example projects eg. https://wrobot.eu/forums/topic/213-how-to-create-plugin-developer-only/ Use the info in this guide with a pinch of salt, it can be done a lot of different ways. This guide will attempt to explain how to create a very simple plugin in c#. This plugin will write things to the wrobot log and into the default chatframe in wow.
Base code
The below snippet is what we'll use as a base to start from, you can either put it into a text editor or into an IDE (like visual studio).
using System;
using robotManager.Helpful;
using wManager.Wow.Helpers;
public class Main : wManager.Plugin.IPlugin
{
public void Initialize()
{
// Code here runs when the plugin is enabled and the bot it started.
}
public void Dispose()
{
// Code to run when the bot is stopped
}
public void Settings()
{
// Code to run when someone clicks the plugin settings button
}
}
Adding our own code to the base
So the basecode itself doesn't do anything right now so we want to add something. In this example plugin I'm going to make it list our equipped items in the WRobot log as well as the default chat frame. This will happen when you hit the start button and the plugin loads.
using System;
using robotManager.Helpful;
using wManager.Wow.Helpers;
public class Main : wManager.Plugin.IPlugin
{
public void Initialize()
{
// Code here runs when the plugin is enabled and the bot it started.
// Writing to the WRobot log
Logging.Write("ExamplePlugin: Loaded.");
// Writing to the WRobot log
Logging.Write("ExamplePlugin: Getting equipped items...");
// This is a foreach loop that does something for every WoWItem that
// EquippedItems.GetEquippedItems() returns
foreach(var item in EquippedItems.GetEquippedItems())
{
// Logging the ItemEquipLocation and name to WRobot log
Logging.Write(item.GetItemInfo.ItemEquipLoc + ": " + item.Name);
// Running Lua to write to the default chat frame
Lua.LuaDoString(
String.Format(@"DEFAULT_CHAT_FRAME: AddMessage(""{0}: {1}"")",
item.GetItemInfo.ItemEquipLoc,item.Name));
}
}
public void Dispose()
{
// Code to run when the bot is stopped
}
public void Settings()
{
// Code to run when someone clicks the plugin settings button
Logging.Write("ExamplePlugin: No settings available.")
}
}
What the EquippedItems.GetEquippedItems() method returns can be found in the API docs here: https://marsbars.gitlab.io/unoffical-wrobot-api-docs/api/wManager.Wow.Helpers.EquippedItems.html
Basic plugin with settings
The above plugin will work as is however you may want to add some user defined settings to your plugin. The next few steps should guide you on how to do this.
Base code
Let's start off with the same base code as our previous plugin:
using System;
using robotManager.Helpful;
using wManager.Wow.Helpers;
public class Main : wManager.Plugin.IPlugin
{
public void Initialize()
{
// Code here runs when the plugin is enabled and the bot it started.
}
public void Dispose()
{
// Code to run when the bot is stopped
}
public void Settings()
{
// Code to run when someone clicks the plugin settings button
}
}
Adding the settings
We're going to create a class within our Main class that inherits from robotManager.Helpful.Settings and we're going to add our own settings to it. I added all my comments into the code to explain each bit.
// Note there are some additional *using* bits at the top here.
using System;
using System.ComponentModel;
using System.IO;
using robotManager;
using robotManager.Helpful;
using wManager.Wow.Helpers;
using wManager.Wow.ObjectManager;
public class Main : wManager.Plugin.IPlugin
{
public void Initialize()
{
// Code here runs when the plugin is enabled and the bot it started.
// !IMPORTANT! You want to make sure to load your settings in the
// initialize otherwise it will not use your setttings
ExamplePluginSettings.Load();
// In this example plugin I'm going to make the bot walk forward
// for an amount of time specified in the settings
// The move.forward method has 2 input params.
// The first is teh MoveAction and the second is the amount of
// time the MoveAction is done. That's where our setting is going
// to come in handy. Without our setting it could look like this:
// Move.Forward(Move.MoveAction.PressKey, 1000);
// We however are going to use our ForwardTime setting from below.
Move.Forward(Move.MoveAction.PressKey,
ExamplePluginSettings.CurrentSetting.ForwardTime);
// I added a jump to the end... why not.
Move.JumpOrAscend();
}
public void Dispose()
{
// Code to run when the bot is stopped
}
public void Settings()
{
// Code to run when someone clicks the plugin settings button
// First we need to load any settings if there are any
ExamplePluginSettings.Load();
// Then create the settings form
ExamplePluginSettings.CurrentSetting.ToForm();
// Then save the settings when the settings form is closed
ExamplePluginSettings.CurrentSetting.Save();
}
[Serializable]
public class ExamplePluginSettings : Settings
{
// This creates a setting
// This is a default value 'guide'. If it matches the current
// user setting, it will not be in bold.
[DefaultValue(1000)]
// This is a category, if you create multiple settings and give
// them the same category they will be under the same header
[Category("Time")]
// The name of your setting that the user sees.
[DisplayName("Time to walk foward")]
// The description shown when a user clicks on the settings
// It is shown in the box at the bottom of the window
[Description("The amount of time in ms that the bot will walk forward")]
// The name of setting in the code
public int ForwardTime { get; set; }
private ExamplePluginSettings()
{
// Add each of your settings here to set its default value
ForwardTime = 1000;
// This is the settings window that opens up, in this example
// its 300 pixels wide and 400 pixel high. You set the title
// of the window here too.
ConfigWinForm(
new System.Drawing.Point(300, 400), "ExamplePlugin "
+ Translate.Get("Settings")
);
}
public static ExamplePluginSettings CurrentSetting { get; set; }
// This is the save method. It saves the settings into the settings
// folder with your plugin name, the char name and the char realm
// I recommend just leaving this as it is other than changing
// the ExamplePlugin bits to your own
public bool Save()
{
try
{
return Save(AdviserFilePathAndName("ExamplePlugin",
ObjectManager.Me.Name + "." + Usefuls.RealmName));
}
catch (Exception e)
{
Logging.WriteError("ExamplePluginSettings > Save(): " + e);
return false;
}
}
// Similar to save, leave this as it is except for replacing ExamplePlugin
public static bool Load()
{
try
{
if (File.Exists(AdviserFilePathAndName("ExamplePlugin",
ObjectManager.Me.Name + "." + Usefuls.RealmName)))
{
CurrentSetting = Load<ExamplePluginSettings>(
AdviserFilePathAndName("ExamplePlugin",
ObjectManager.Me.Name+"."+Usefuls.RealmName));
return true;
}
CurrentSetting = new ExamplePluginSettings();
}
catch (Exception e)
{
Logging.WriteError("ExamplePluginSettings > Load(): " + e);
}
return false;
}
}
}
If you save this into a .cs file and put it into your plugins folder you should be able to launch WRobot, go to plugins, select your plugin and then hit settings. It should have one setting in it, "Time to walk foward". Try changing this to something higher than 1000ms (1 second) and launch the bot in WRotation. When it starts it should walk forward for your specified time and then jump.
You can confirm your chars settings have been created by going to the wrobot settings folder and finding the name of your plugin (or if you've just used my code it should be "ExamplePlugin").