Creating project
Unturned Plugin Development #2
MCrow • 5 months ago
MCrow • 5 months ago
In this guide, we will create our first Unturned plugin using the project templates we installed in the previous guide. We will create a simple plugin that will log a message to the console when the server starts. Then we will compile the plugin, install it on the server, and test it.
Open Visual Studio and press on Create a new project
. Search for Unturned
and select Unturned Plugin
.
Enter the name of the project, for example, Kits
, ChatManager
or AdminTools
. For the purpose of this guide we will name our project Example
.
Naming rules to follow:
AviKits
, ZaupShop
and RFVault
.You can leave project location and solution name as default. Don't check the Place solution and project in the same directory
checkbox. Press Create
.
In the next window as Author enter your name or nickname. It is required and can't contain spaces, because it is used in the project namespace. It helps to identify the author of plugin in error logs. Press Create
.
In the Solution Explorer, you will see the project structure. Open ExamplePlpugin.cs
and ExampleConfiguration.cs
files in the Example
project.
ExamplePlugin.cs
file contains the main class of the plugin. It is derived from RocketPlugin
class and contains the Load
and Unload
methods. These methods are called when the plugin is loaded and unloaded.
The other file you will see is ExampleConfiguration.cs
. This file contains the configuration of the plugin. We will use it in the next guides to store plugin settings.
In the Load
method of the ExamplePlugin
class, add the following line of code:
Logger.Log("Hello, Unturned!");
The Logger
class is a static class that is used to log messages to the console and Rocket.log file. It is part of the RocketMod library.
Press Ctrl + Shift + B
to compile the plugin. If there are no errors, you will see Build succeeded
in the output window.
Alternatively you can press Build
→ Build Solution
in the menu.
Right click on the Example
project and press Open Folder in File Explorer
. Navigate to bin
→ Debug
→ net48
folder. Copy the Example.dll
file to the Rocket
→ Plugins
folder on your Unturned server.
Start your Unturned server. In the console, you should see the message Hello, Unturned!
. This means the plugin was loaded successfully.
Congratulations! You have created your first Unturned plugin. In the next guide, we will learn how to handle events and commands in the plugin.