Scripting Overview
Varion resources can run server logic in C#, JavaScript and Go. Client-side JavaScript resources are described in the client API section.
Server Runtimes
| Runtime | resource.toml | Loader |
|---|---|---|
| C# | type = "csharp" | .NET host through Varion.SDK.RuntimeHost |
| JavaScript | type = "js" | Node host; started automatically for type = "js" with a main |
| Go | type = "go" | c-shared DLL host |
| Native C++ | modules/ | Native module loader with include/varion_module_sdk.h |
The complete server JS API reference is Server JavaScript API.
Resource Lifecycle
- The server reads enabled resource names.
- Dependencies are sorted.
- Runtime loaders scan resources of their supported
type. - Loaded resources receive start/stop/tick and gameplay events through the script event bus.
Common Concepts
| Concept | Server API surface |
|---|---|
| Players | IPlayer, JS varion.Player, Go host player IDs |
| Entities | Vehicles, peds, objects, virtual entities |
| Events | Local events, client events and typed runtime events |
| RPC | Client-to-server handlers and server-to-client responses |
| Metadata | Local data, synced metadata and stream-synced metadata |
| World visuals | Blips, markers, text labels, checkpoints and colshapes |
| Voice | Voice channels and external voice host settings |
Minimal JS Resource
toml
enabled = true
type = "js"
main = "server/main.js"
client-type = "none"javascript
varion.log('server resource loaded');
// The first onClient argument is a Player proxy, not a numeric id.
varion.onClient('chat:message', (player, message) => {
varion.emitAllClients('chat:addMessage', player.name, String(message));
});Minimal C# Resource
csharp
using Varion;
public sealed class Main : Resource
{
public override void OnStart()
{
varion.Log("resource started");
varion.OnPlayerConnect += player => varion.Log($"connect {player.Name}");
}
}Source Backing
This page is derived from src/core/CServer.cpp, src/scripting/CScriptRuntime.h, src/scripting/CJsScriptRuntime.h, src/scripting/CGoScriptRuntime.h, sdk/Varion.SDK/varion.cs and sdk/server-js-host/varion-server-shim.cjs.