SampSharp

Starting Development Edit this page on GitHub

Introduction

This page will focus on setting up your first game mode and giving you some direction on where to go from there. Before continuing, please make sure you've set up your server as described on the Setup page.

Creating a Project

  1. Click on File > New > Project (Shortcut: Ctrl + Shift + N).
  2. Select Visual C# from the list on the left.
  3. Select .NET Core from the expanded sub-list and choose Console App (.NET Core) from the list in the center.
  4. Type the name and Location of your new Solution.
  5. Click OK to save.

Referencing the Framework

To be able to interact with the server, you need to add the framework to your project's references.

  1. In the Solution explorer, right click on References under your project.
  2. Click on Manage NuGet Packages....
  3. Under Online select the SampSharp repository.
  4. Click on Framework for SA-MP# and click on Install.

Defining the Entry Point

You can now create the entry point of your gamemode. In you project, create a class named GameMode and let it inherit from BaseMode.

Here is a simple GameMode class:

using SampSharp.GameMode; // Contains BaseMode class
using SampSharp.GameMode.Controllers; // Contains ControllerCollection class

public class GameMode : BaseMode
{
    #region Overrides of BaseMode

    protected override void OnInitialized(EventArgs e)
    {
        Console.WriteLine("\n----------------------------------");
        Console.WriteLine(" Blank Gamemode by your name here");
        Console.WriteLine("----------------------------------\n");

        /*
         * TODO: Do your initialisation and loading of data here.
         */
        base.OnInitialized(e);
    }

    protected override void LoadControllers(ControllerCollection controllers)
    {
        base.LoadControllers(controllers);

        /*
         * TODO: Load or unload controllers here.
         */
    }

    #endregion
}

Starting the Game Mode

In the newly created project, you will have a class named Program. In that class, in the Main method, you will have to create a GameModeBuilder, which will run your gamemode (Refer to GameMode Builder for details on what a GameMode Builder is, how it works and different configuration options).

A sample of a standard Main class:

private static void Main(string[] args)
{
    new GameModeBuilder()
        .Use<GameMode>()
        .Run();
}