> For the complete documentation index, see [llms.txt](https://docs.hogwarp.com/hogwarp/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hogwarp.com/hogwarp/scripting/server-side/plugin/creating-a-plugin.md).

# Creating a Plugin

A general tutorial for creating a Hogwarp plugin. Version: 0.8.0 beta 2

## Create a project

{% tabs %}
{% tab title="Visual Studio" %}
In Visual Studio, create a new project, select `Class Library`, then click Next.

<figure><img src="https://1616767776-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSbmAvHgFDKouBnrDAEyc%2Fuploads%2FCHJyNlyYvhX4kZ7rFWNB%2Fimage.png?alt=media&amp;token=d49ed761-6106-4e54-8897-ff653b1f7b2b" alt=""><figcaption></figcaption></figure>

On the next page, give the project the name of your choice and click Next. In this example we use `Tutorial.`

{% hint style="info" %}
When asked to select the Framework, pick `.NET 8.0 (Long Term Support)`. This is very important!
{% endhint %}

<figure><img src="https://1616767776-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSbmAvHgFDKouBnrDAEyc%2Fuploads%2FsVfNHadrnwspEHb9IB7O%2Fimage.png?alt=media&amp;token=24bfc580-493d-4c7f-856f-84b258492935" alt=""><figcaption></figcaption></figure>

Click `Create`.
{% endtab %}

{% tab title="JetBrains Rider" %}
In JetBrains Rider, create new new solution by clicking `New Solution`.

<figure><img src="https://1616767776-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSbmAvHgFDKouBnrDAEyc%2Fuploads%2FQG6IGI0A6gsojWR0Cn3o%2Fimage.png?alt=media&amp;token=7df450f2-8c65-4557-848f-9ec52fd45612" alt=""><figcaption></figcaption></figure>

A window will pop up and you have to select the `Class Library` at the list to the left.

<figure><img src="https://1616767776-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSbmAvHgFDKouBnrDAEyc%2Fuploads%2FskWk8uZSvaJF0SvAelsx%2Fimage.png?alt=media&amp;token=3d571f40-c2db-49ea-a8c2-a1fa74890241" alt=""><figcaption></figcaption></figure>

Then give the project a name and select a solution directory of your choice.

<figure><img src="https://1616767776-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSbmAvHgFDKouBnrDAEyc%2Fuploads%2FhmWmXda5XNT3uidae9Js%2Fimage.png?alt=media&amp;token=13f5d08e-564c-47fe-9cb1-57b24c7ea4e4" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
You can tick on the `Put solution and project in the same directory` if you want.
{% endhint %}

At last please select `net8.0` as your `Target Framework` and press `Create` at the bottom right

<figure><img src="https://1616767776-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSbmAvHgFDKouBnrDAEyc%2Fuploads%2FBePhtvzTEHfYh5m4sjlX%2Fimage.png?alt=media&amp;token=97f83262-13ec-456f-8600-363e55f7abe6" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
Picking net8.0 as your Target Framework is very important. Make sure you have installed the .NET SDK 8.0 from [Microsoft](https://dotnet.microsoft.com/en-us/download/dotnet/8.0)
{% endhint %}

{% endtab %}
{% endtabs %}

## Configure the project

{% tabs %}
{% tab title="Visual Studio" %}
You should now be in Visual Studio with a basic class.

In the solution explorer, expand your project and right click on dependencies, then click `Add Project Reference...`

<figure><img src="https://1616767776-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSbmAvHgFDKouBnrDAEyc%2Fuploads%2FkMYFKMDxbCCdvQNeFVLn%2Fimage.png?alt=media&amp;token=a840d799-4c5b-4698-b9dc-204827115c63" alt=""><figcaption></figcaption></figure>

A window will open, click on `Browse...`

<figure><img src="https://1616767776-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSbmAvHgFDKouBnrDAEyc%2Fuploads%2Fm3JLgilsO4t7L8wF21Uv%2Fimage.png?alt=media&amp;token=2130c6f2-8a76-4adc-9c7c-43a7a054549e" alt=""><figcaption></figcaption></figure>

Go to the HogWarp install location, then in the Server folder and select `HogWarpSdk.dll`.

<figure><img src="https://1616767776-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSbmAvHgFDKouBnrDAEyc%2Fuploads%2FDVTY29qvyadOyRV2UXsc%2Fimage.png?alt=media&amp;token=70805f68-32b6-449c-976c-6d57869c1d68" alt=""><figcaption></figcaption></figure>

Click on `Add`. Then `Ok`.
{% endtab %}

{% tab title="JetBrains Rider" %}
You should now be in JebBrains Rider with a Class1.cs file.

In the solution explorer, expand your project and right click on `Dependencies` , then click `Reference...`

<figure><img src="https://1616767776-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSbmAvHgFDKouBnrDAEyc%2Fuploads%2Fp8WNGspuDd0M0O38wnQm%2Fimage.png?alt=media&amp;token=a4002050-4180-4815-b87d-5cf2f400800c" alt=""><figcaption></figcaption></figure>

A window will open, click on `Add From...`&#x20;

<figure><img src="https://1616767776-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSbmAvHgFDKouBnrDAEyc%2Fuploads%2FPuyFK6mA6nTVJQQtzs1T%2Fimage.png?alt=media&amp;token=c608837a-71af-44ff-a6a1-45b73fcc8ac3" alt=""><figcaption></figcaption></figure>

Go to the HogWarp install location, then in the Server folder and select `HogWarpSdk.dll`.

<figure><img src="https://1616767776-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSbmAvHgFDKouBnrDAEyc%2Fuploads%2FkWAfQKIrVUxarukUxhdU%2Fimage.png?alt=media&amp;token=4410eace-1141-4949-96a9-3a6c9de90948" alt=""><figcaption></figcaption></figure>

Click on `Open` .
{% endtab %}
{% endtabs %}

## Entry

{% tabs %}
{% tab title="Visual Studio" %}
The server mods need to respect a special naming convention to be loaded correctly.

When attempting to load a mod, the server will look for the `ModName.Plugin` class, where `ModName` is the name you chose when creating your project.

Create a `Plugin.cs` file in your solution and fill out the required fields.

{% code title="Plugin.cs" lineNumbers="true" fullWidth="false" %}

```csharp
namespace Tutorial;

public class Plugin : HogWarpSdk.IPlugin
{
    public string Author { get; } = "YourName";
    public string Name { get; } = "Tutorial";
    public Version Version { get; } = new(1, 0, 0, 0);
    
    public Plugin()
    {
        var logger = new HogWarpSdk.Systems.Logger(Name);
        logger.Info("Hello, World!");
    }

    public void PostLoad() { }

    public void Shutdown() { }
}   
```

{% endcode %}

For now, we leave `PostLoad`and `Shutdown` empty, as we don't need them here.

### Output Path Generation

If you choose this folder structure for you project:&#x20;

`Hogwarp->Server->Server->YourPluginName`&#x20;

You can of course alter this path to your likings if you know how to do so.

You can add the following PropertyGroup into your csproj file:

```markup
<PropertyGroup>
    <OutputPath>$(SolutionDir)..\..\Mods\$(AssemblyName)\</OutputPath>
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
```

If you have done this and build your mod it should have generated the folders and files for you.

The files should now be in your `Hogwarp->Server->Mods` folder.

### Simple Output Path

Now build your mod, you will see a path to a DLL being produced, browse to this location.

You must now copy the DLL so that you get something like `Server/Mods/ModName/ModName.dll.`

For example with the "Tutorial" plugin the path will be `Server/Mods/Tutorial/Tutorial.dll`&#x20;

### Launching

If you now launch the server you should see your plugin gets loaded correctly:

<figure><img src="https://1616767776-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSbmAvHgFDKouBnrDAEyc%2Fuploads%2Fpwxq2oiMXhmaXPYSgkMJ%2Fimage.png?alt=media&amp;token=4317ae64-4f74-41c9-896e-94ca2f1a27c7" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="JetBrains Rider" %}
The server mods need to respect a special naming convention to be loaded correctly.

When attempting to load a mod, the server will look for the `ModName.Plugin` class, where `ModName` is the name you chose when creating your project.

Just rename the Class1.cs to Plugin.cs like this or use shortcut for it.

<figure><img src="https://1616767776-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSbmAvHgFDKouBnrDAEyc%2Fuploads%2Fh1Sbh6NfFiWrVGbmlyvT%2Fimage.png?alt=media&amp;token=72228aad-7196-4a4a-940d-f440a2371165" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1616767776-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSbmAvHgFDKouBnrDAEyc%2Fuploads%2FAmZ1HBAYABFYt8ZBR05G%2Fimage.png?alt=media&amp;token=4313561a-dc6d-4af0-9572-a3a9db1868ea" alt=""><figcaption></figcaption></figure>

We added a constructor and a logger message to check if everything works fine.

{% code title="Plugin.cs" lineNumbers="true" %}

```csharp
namespace Tutorial;

public class Plugin : HogWarpSdk.IPlugin
{
    public string Author { get; } = "YourName";
    public string Name { get; } = "Tutorial";
    public Version Version { get; } = new(1, 0, 0, 0);
    
    public Plugin()
    {
        var logger = new HogWarpSdk.Systems.Logger(Name);
        logger.Info("Hello, World!");
    }

    public void PostLoad() { }

    public void Shutdown() { }
}
```

{% endcode %}

### Output Path Generation

If you choose this folder structure for you project:&#x20;

`Hogwarp->Server->Server->YourPluginName`&#x20;

You can of course alter this path to your likings if you know how to do so.

You can add the following PropertyGroup into your csproj file:

```markup
<PropertyGroup>
    <OutputPath>$(SolutionDir)..\..\Mods\$(AssemblyName)\</OutputPath>
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
```

You can open it like this:

<figure><img src="https://1616767776-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSbmAvHgFDKouBnrDAEyc%2Fuploads%2Fozd04596p2X7GtWQ4b7R%2Fimage.png?alt=media&amp;token=bb3146b0-ebd4-488b-9b0f-47026017877b" alt=""><figcaption></figcaption></figure>

And add those two options:

<figure><img src="https://1616767776-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSbmAvHgFDKouBnrDAEyc%2Fuploads%2FsqlZGjTOl5oD6cM3VeF4%2Fimage.png?alt=media&amp;token=7a655019-6f96-4d26-b4e8-85b1f6657659" alt=""><figcaption></figcaption></figure>

If you have done this and build your mod it should have generated the folders and files for you.

<figure><img src="https://1616767776-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSbmAvHgFDKouBnrDAEyc%2Fuploads%2FwaqdsBSB6L8rQ41PPiae%2Fimage.png?alt=media&amp;token=e24abb82-9a13-489e-9b93-4be9a8c5bdc8" alt=""><figcaption></figcaption></figure>

The files should now be in your `Hogwarp->Server->Mods` folder.

### Simple Output Path

Now build your mod, you will see a path to a DLL being produced, browse to this location.

You must now copy the DLL so that you get something like `Server/Mods/ModName/ModName.dll.`

For example with the "Tutorial" plugin the path will be `Server/Mods/Tutorial/Tutorial.dll`

### Launching

If you now launch the server you should see your plugin gets loaded correctly:

<figure><img src="https://1616767776-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSbmAvHgFDKouBnrDAEyc%2Fuploads%2FfB9sF1L4gf197kr1zQez%2Fimage.png?alt=media&amp;token=539cc63f-de02-4258-a837-6329e132a886" alt=""><figcaption></figcaption></figure>
{% endtab %}
{% endtabs %}
