
Your first resource
Build a small airport spawn. When a player joins, the client and server exchange a greeting. Pressing F6 requests the player’s profile from the server.
Create the folders
Start in the directory containing netmp-server.exe. You need the .NET 10 SDK and the bundled NetMP.ServerApi.dll under scripting/.
- server.toml
- scripting
- NetMP.ServerApi.dll
- scripts/HelloC# source
- Hello.csproj
- Main.cs
- resources/hello
- resource.toml
- clientsent to players
- index.js
- serverbuild output
- Hello.dll
- Hello.deps.json
Register the resource
resource.toml names both entry points relative to the resource directory. Add hello to the existing resources array in server.toml. Place that entry before the first TOML table.
type = "csharp"
main = "server/Hello.dll"
client-type = "js"
client-main = "client/index.js"
resources = ["hello"]
Spawn the player
The public main class manages the lifecycle. netMP registers handlers in the IScript class when it loads the DLL. Set the player model before the first spawn. Later spawns reuse the last model you set.
namespace Hello;
using Net.Server;
using System.Threading.Tasks;
public sealed class Main : IResource { }
public sealed class Events : IScript
{
[ScriptEvent(ScriptEventType.PlayerConnect)]
public static void Connect(IPlayer player)
{
player.Model = (uint)PedModel.FreeModeMale01;
player.Spawn(new Position(-1037.8f, -2738f, 20.2f),
new Rotation(0f, 0f, 330f));
}
[ClientEvent("hello:ready")]
public static async Task Ready(IPlayer player)
{
var version = await player.CallRpc<int>("hello:version");
player.Emit("hello:welcome", player.Name, version);
}
[ClientRpc("hello:profile")]
public static object Profile(IPlayer player) =>
new { name = player.Name, health = player.Health };
}
hello:ready is an event. The server receives the sender as IPlayer and asks that client for its script version. CallRpc<int> waits for the reply. Emit then sends the greeting to the same player.
Connect the client
Register the handlers first, then tell the server that the client is ready. Pressing F6 sends a second RPC in the opposite direction. It returns an object containing the player’s name and health. You can read both in the F8 console.
import * as net from 'net-client';
net.onRpc('hello:version', () => 1);
net.onServer('hello:welcome', (name, version) => {
net.log('Hello ' + name + ' | client v' + version);
});
net.on('keydown', async key => {
if (key !== net.KeyCode.F6) return;
try {
const profile = await net.emitRpc('hello:profile');
net.log('Profile ' + profile.name + ' | HP ' + profile.health);
} catch (error) {
net.logError(error.message);
}
});
net.emitServer('hello:ready');
Build and test
Save the project next to Main.cs. The reference path points to the server API in your release. From the directory containing the server executable, build directly into resources/hello/server so the DLL and its .deps.json land together.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
</PropertyGroup>
<ItemGroup>
<Reference Include="NetMP.ServerApi">
<HintPath>../../scripting/NetMP.ServerApi.dll</HintPath>
<Private>false</Private>
</Reference>
</ItemGroup>
</Project>
dotnet build .\scripts\Hello\Hello.csproj -c Release -o .\resources\hello\server
.\netmp-server.exe
Start the server. In the launcher, connect to 127.0.0.1:6390 and open F8. The greeting ends with client v1. Press F6 to print your profile with your name and health.
To test without GTA, open a second PowerShell window in the release directory and start the bot. Key code 117 presses F6. The script output appears in the bot window.
.\netmp-bot.exe 127.0.0.1 6390 Tester js 117
After editing the C# code, build again and enter reload hello in the server console. The running server distributes saved changes under resources/hello/client automatically.
Troubleshoot
The player does not spawn
Open server.log and check for the resource startup and PlayerConnect registration. The class must implement IScript and the handler must take exactly one IPlayer.
The DLL does not load
Compare main in resource.toml with the actual DLL filename. Put the .deps.json and any required libraries beside the resource assembly.
An RPC fails
Check the name and direction. emitRpc expects a C# ClientRpc handler, and CallRpc expects a JavaScript onRpc handler. Calls time out after ten seconds. A C# handler error reaches the JavaScript catch block as error.message.
A resource ends during an RPC
Pending calls for that resource report “Resource gestoppt”. On disconnect the JavaScript caller receives “Verbindung getrennt”. Use finally to release any pending state in your UI.