Writing a plugin
The following guide will explain how to write a plugin for the server and use the plugin API.
- Visual Studio 2019 (or dotnet in your path)
- Experience with C#/.NET
- Create a new project in Visual Studio and choose "Class Library (.NET Standard)".
- Add the gtaserver.core.dll in the server folder as reference.
- Create a new class e.g. 'Example' and inherit the IPlugin (GTAServer.PluginAPI) interface.
OnEnable method will be called as soon as the plugin is loaded, the plugin can return false here when for example something got wrong while starting. The
GameServer instance is also exposed which contains most of the functions to access the server.
Commands can be executed by the server and the client, they are registed by creating a function with the
Two arguments are passed
args, args contains all arguments passed after the command e.g. '/hello hello there' returns "hello" and "there". The
CommandContext class contains a couple of properties about the context of the command execution e.g. the command sender, server instance, orginal message.
To register all commands in a class use
gameServer.RegisterCommands<ExampleCommands>(); in your
OnEnable where ExampleCommands is your class containing all your commands.
A plugin can register several hooks to get notified when certain events happen, for this you can use the following classes
PacketEvents. Some require you to return a
PluginResponse with the ability to modify the message passed on to other plugins and the server.