Skip to content

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

Runtimeresource.tomlLoader
C#type = "csharp".NET host through Varion.SDK.RuntimeHost
JavaScripttype = "js"Node host; started automatically for type = "js" with a main
Gotype = "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

  1. The server reads enabled resource names.
  2. Dependencies are sorted.
  3. Runtime loaders scan resources of their supported type.
  4. Loaded resources receive start/stop/tick and gameplay events through the script event bus.

Common Concepts

ConceptServer API surface
PlayersIPlayer, JS varion.Player, Go host player IDs
EntitiesVehicles, peds, objects, virtual entities
EventsLocal events, client events and typed runtime events
RPCClient-to-server handlers and server-to-client responses
MetadataLocal data, synced metadata and stream-synced metadata
World visualsBlips, markers, text labels, checkpoints and colshapes
VoiceVoice 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.

Varion Multiplayer Platform