Skip to content

Scripting overview

Varion resources могут запускать server logic на C#, JavaScript и Go. Client-side JavaScript resources описаны в Client API.

Server runtimes

Runtimeresource.tomlLoader
C#type = "csharp".NET host через Varion.SDK.RuntimeHost
JavaScripttype = "js"Node host; запускается автоматически для type = "js" с заданным main
Gotype = "go"c-shared DLL host
Native C++modules/Native module loader with include/varion_module_sdk.h

Полный справочник серверного JS API — Server JavaScript API.

Resource lifecycle

  1. Сервер читает enabled resource names.
  2. Dependencies сортируются.
  3. Runtime loaders сканируют resources своего type.
  4. Loaded resources получают start/stop/tick и gameplay events через 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 и typed runtime events
RPCClient-to-server handlers и server-to-client responses
MetadataLocal data, synced metadata и stream-synced metadata
World visualsBlips, markers, text labels, checkpoints и colshapes
VoiceVoice channels и 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');

// Первый аргумент onClient — proxy Player, а не числовой 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

Страница основана на src/core/CServer.cpp, src/scripting/CScriptRuntime.h, src/scripting/CJsScriptRuntime.h, src/scripting/CGoScriptRuntime.h, sdk/Varion.SDK/varion.cs и sdk/server-js-host/varion-server-shim.cjs.

Varion Multiplayer Platform