GameModeBuilder Edit this page on GitHub


The GameModeBuilder can be used to configure how your game mode is launched. Generally, you'll be using the GameModeBuilder from the entry-point of your assembly.

public static class Program
    public static void Main()
        new GameModeBuilder()

Game Mode Instance

In order for your game mode to properly function, you need to indicate which class provides the game mode functionality; a class which implements IGameModeProvider. The BaseMode class in the SampSharp.GameMode library implements this interface. Generally you'll want to create a class which inherits from BaseMode and use this class as the game mode provider. By using the Use method you can specify the game mode provider:


// or if you wish to specify the constructor manually:

.Use(new MyGameMode())

SampSharp Logging

SampSharp provides some logging messages to show what is going on within SampSharp itself. By using the UseLogLevel method you can change the minimum level of log messages which are written to the output. By default, the log messages are printed to the standard console output. If you wish to change the output stream, you can use the UseLogStream method. The following log levels are available:

Redirect Console Output

By using RedirectConsoleOutput method of the GameModeBuilder you can forward all data written to the console using the System.Console class to the SA-MP server log. It is however a better practise to use a logging package from NuGet because these provides for better options than SA-MP has to offer, such as log rotation, formatting and writing logs to logging services such as Elastic Search. Some examples of good logging packages are Log4Net, Micosoft.Extensions.Logging and NLog.


C# uses Unicode for storing text while SA-MP uses a "byte oriented" charset. The characters displayed by SA-MP depend on the active localization of the machine of the player. In SA-MP without SampSharp you might have noticed that when someone types something in Russian (using a Cyrillic charset), the text appears as some random symbols on the screen of an English user(using a Latin charset). This is because the bytes representing symbols in the Cyrillic charset represent different symbols in the Latin charset.

In order to let characters sent by players represent the same characters on the server, the characters need to be translated to Unicode. In order to do this, you will need to specify which character set (encoding) the server expects to receive. At the moment, SampSharp only supports one encoding to be active. In order to set the active encoding, you can use UseEncoding method of the GameModeBuilder. There are 3 overloads of the UseEncoding method:

SampSharp also provdes some embedded code pages. You can use one of these code pages using the UseEncodingCodePage method. The following code pages are embedded in SampSharp and are available through this method:

See the code pages Wikipedia article for more information code pages and which code page might best suit your users.