C# Plugin Development
1. Requirements :
- Microsoft Visual Studio (2013 is used in this guide)
- Fougerite DLL
- Extra DLL's : UnityEngine and Assembly-csharp (from a rust legacy server, located in the "Managed" folder)
First, we'll need to create a new project of type "Class Library".
Next we will add reference to all the libraries we mentioned before. At the right part of Visual Studio, right click on "References" and click "Add Reference..."
In Visual Studio, you must use .Net Framework 3.5! You can do this by rightclicking on FougeriteTest, then Properties, and setting the target framework to 3.5!
First of all, we'll add a reference to Fougerite on the class by writing "using Fougerite;" to use its types.
In Initialize we will add the code that we want to run when the plugin gets loaded. This is the perfect place to get any file (iniparsers, streamwriters, etc...) and to add your Hooks to Rust.
Hooks are used to execute something on an event. For example, when a player gets killed, or when a player places a structure, when a player writes a command on chat, etc...
3. Example :
The first example will be with the OnCommand hook.This hook gets called everytime someone writes something in chat with a "/" as the first character. For example : "/help" or "/starterkit"
We will add our method "HandleCommand" to the OnCommand hooks on Initialize, and we will delete it on DeInitialize. Notice the difference between them.
Notice that Initialize is += and DeInitialize is -=
On our HandleCommand method, we will take 3 parameters. First one will be the Player that sends the command, second one will be the command string, third one will be an array of strings which stands for whatever comes after the command.
For example : "/spawn battlekit sniper". "spawn" is the command and "battlekit" is the first string on the array and sniper is the second string on the array.
On this example, we check if the command is "test". If so, we send a message to the player.
Here we'll cover the basic and most used hooks.
They are quite a lot, and there are more but are almost never used.Warning : Note that I write Handle + Whatever on all delegates, but this is not necessary. You can call your delegates as you want. However, this is easier to read and understand.
OnBlueprintUse : Called when a Player tries to learn a blueprint. This event will be called both when the Player hasn't learned yet the blueprint and when the Player has already learned the blueprint.
Takes 2 parameters : Fougerite.Player and BPUseEvent
BPUseEvent contains all the information about the event. ItemName (string) property refers to the name of the blueprint item and the Cancel (bool) property cancels the learning of the blueprint when set to true.
The last property is the DataBlock, which contains advanced information about the event which we'll not be using anytime soon.
In this example, we check if the item learned is Explosive Charge. If so, we message the player and cancel the event.
Takes 2 parameters : Fougerite.Player and ChatString
ChatString is basically a string with the NewText property. This property will set the content of the entire string in case you give some value to it.
In this example, we check if the message contains the word "noob". If so, we make the message empty, so that way it isn't printed in the chat, and we message the player.
Notice that the ChatString it's the string message with double quotes at the start and the end.
1st : Server.GetServer().Broadcast(chatString)
2nd : Original message
STILL WORKING ON IT
Last edited by a moderator: