Here I will implement a simple in-game wolfbot with ScriptCraft in under a hundred lines of code. In the beginning our bot will only support a few commands–mostly serving as a glorified “donkey”. In later posts we will add more functionality. You can find the code for our bot in the wolfbot Github repo.
First off, my intent in this post is not to create the next best pet/bot plugin, especially since there are already some good pet plugins out there. The purpose of this post is for us to learn how to create a bot in ScriptCraft.
We will also be using the brand new ScriptCraft plugin feature which was included in the newest release. The plugin feature is a neat addition since it gives us data persistence and also the ability to safely package various features so that non-op players can indirectly use ScriptCraft goodies.
There are three main parts to a ScriptCraft plugin:
The plugin’s definition section is where the meat of the plugin resides. Here we define various methods to implement the features we want to support in our plugin. We can also place helper methods here for accessing our plugin’s data storage.
ScriptCraft makes it absurdly easy to persist data with your plugins. To save data we need only add a key to our plugins store and assign it an object. Behind the scenes ScriptCraft will serialize the data into JSON when needed and save it for us to be accessed later.
A Simple Plugin
Below, check out each of the three sections in action in this plugin which can get and set a string:
If you would like to read more about ScriptCraft plugins, then I recommend reading Walter Higgins original post introducing them.
Wolfbot Specs & Demo
Before we get started coding our wolfbot, let’s look at the list of various actions I would like the bot to support:
- summon – Summons the bot.
- dismiss – Dismisses the bot.
- come – Causes the bot to target you and follow.
- stay – Causes the bot to sit and stay put.
- pack – Causes the bot to show you its inventory and allow you to take and place items with it.
You can see these commands in action below:
To implement the actions we described above we will create a method for each action in the plugin definition section. Most everything inside these methods are Bukkit API calls. You can see the definition section below. Reference the Bukkit API docs to find out more about the API calls I make.
All there is left to do now is create our storage and associate plugin commands with our plugin’s functionality so that players who are not ops can also have bots. Checkout the code for the complete plugin in the Github repo.
Is there a topic you would like to see covered here? I want to hear your input. Send me an email with any suggestions for future posts. If you liked this post, then you might also like Visualizing Towers Of Hanoi In Minecraft.