# Creating a Plugin

## Create a project

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

<figure><img src="/files/t28TpUhI80NPLgU66BkO" 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="/files/hIh5t5MrCgkrRKkvhP59" 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="/files/zVzUKSstTpUTnyM9YnNz" 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="/files/iHsAwof2u2SzPpHbm6BP" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/GiL2Mjz8GOMyamHZySp7" 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="/files/jHg7Tkcu6Owf9XEb0inb" 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="/files/oqabR5mUAE5AK9Et1hqT" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/xQ0aCchei6R0Mrxevg1B" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/6fwvYyNNe2G25MCEVi9L" 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="/files/JzAzLhBsN2duaz0K1xWx" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/FzIIzhZwSawTLmymEp6d" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/FAfL7R34Zsh8mFknWZoO" 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="/files/ABp3T56lfq8ftTf54Mub" 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="/files/u65LVjCYmODqeqym6BxA" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/h9Mz3hwBdR3c8PfMhxoj" 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="/files/adwQ7zLeci4SpBGW59IV" alt=""><figcaption></figcaption></figure>

And add those two options:

<figure><img src="/files/AkjsyUgpCExaI5DyFLdj" 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="/files/4giR43avOT0UUKRlYcli" 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="/files/lqvS2aR8ogo7uJhR6IvC" alt=""><figcaption></figcaption></figure>
{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hogwarp.com/hogwarp/scripting/server-side/plugin/creating-a-plugin.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
