Scripting API Reference

Nexus scripts are C# classes that extend the ScriptAPI base class. Each script is compiled at runtime by the controller using Roslyn and distributed to all connected servers. Scripts allow you to hook into various Nexus events to customize behavior without modifying the plugin itself.

For general script setup instructions (adding scripts, prefabs, refreshing), see the Script Setup page.

Example scripts are available on the Nexus GitHub.

Creating a Script link

Every Nexus script must inherit from ScriptAPI. Override only the methods you need:

public class MyCustomScript : ScriptAPI
{
    public override bool InboundGate(MyCubeGrid BiggestGrid, List<MyCubeGrid> AllGrids, GateAPI Gate, List<long> allPlayers, ref Vector3D gridSpawnPos, ref byte targetServer)
    {
        // Your custom gate logic here
        return true; // Return false to deny the transfer
    }
}

Save your script as a .cs or .txt file in the controller’s Scripts directory and refresh.

Script Events link

The following table lists all available script events. The Script Type column shows how the event is categorized in the controller’s script list.

Event Method Script Type Description
DiscordLink DiscordLink Called on the !d link command
InboundGate InboundGate Called after a grid enters a gate and spawns on the destination server
OutboundGate OutboundGate Called on the origin server when a grid exits through a gate
OutboundSpawnpad OutboundSpawnpad Called on the origin server when a spawn pad is activated
NexusButtonAction NexusButtonAction Called when a player presses a scripted NPC button
InboundSpawnPad_Pre InboundSpawnPad_Pre Called on the destination server before the spawn pad processes
InboundSpawnPad_Post InboundSpawnPad_Post Called on the destination server after the spawn completes
CanGridsSwitchSector CanGridsSwitchSector Called when a grid is about to fly across a sector boundary
CanGridsJumpSector CanGridsJumpSector Called when a grid is about to jump drive across a sector boundary
OnPlayerJoin OnPlayerJoin Called when a player joins the server
OnPlayerLeft OnPlayerLeft Called when a player leaves the server

Event Method Signatures link

public virtual bool DiscordLink(ulong steamID, ulong discordID)

Called when a player runs the !d link command. Return true to allow the link, false to deny it.

Parameters:


InboundGate link

public virtual bool InboundGate(
    MyCubeGrid BiggestGrid,
    List<MyCubeGrid> AllGrids,
    GateAPI Gate,
    List<long> allPlayers,
    ref Vector3D gridSpawnPos,
    ref byte targetServer)

Called on the destination server after a grid spawns through a gate. You can modify the spawn position and target server. Return false to deny the transfer.

Parameters:


OutboundGate link

public virtual void OutboundGate(IEnumerable<MyCubeGrid> grids, GateAPI fromGate)

Called on the origin server when grids are exiting through a gate. Use this for logging, broadcasting messages, or applying effects before departure.

Parameters:


OutboundSpawnpad link

public virtual bool OutboundSpawnpad(ScriptSpawnMessage spawnReqMsg)

Called on the origin server when a spawn pad is activated. Return false to deny the spawn request.

Parameters:


NexusButtonAction link

public virtual void NexusButtonAction(MyButtonPanel buttonPanel, ulong SteamID, long PlayerID)

Called when a player presses a button on an NPC-built button panel that has a script name configured in its custom data.

Parameters:

Warning

Button events only fire for buttons built by NPCs. Players cannot create scripted buttons unless another mod/plugin assigns an NPC built-by identity.


InboundSpawnPad_Pre link

public virtual async Task InboundSpawnPad_Pre(ScriptSpawnMessage spawnReqMsg)

Called on the destination server before the spawn pad processes the request. Use this to modify the spawn message, adjust positions, or perform pre-spawn setup.

Parameters:


InboundSpawnPad_Post link

public virtual async Task InboundSpawnPad_Post(HashSet<MyCubeGrid> spawnedGrids)

Called on the destination server after the spawn has completed. Use this to modify spawned grids, randomize loot, apply damage, or trigger events.

Parameters:


CanGridsSwitchSector link

public virtual bool CanGridsSwitchSector(
    SectorAPI fromSector,
    SectorAPI toSector,
    List<MyCubeGrid> grids,
    List<ulong> players)

Called when grids are about to fly or be pushed across a sector boundary. Return false to deny the transfer and push grids back.

Parameters:


CanGridsJumpSector link

public virtual (bool, string) CanGridsJumpSector(
    SectorAPI fromSector,
    SectorAPI toSector,
    Vector3D jumpTarget,
    long playerIDjumper,
    MyCubeGrid mainGrid)

Called when a grid attempts a jump drive across a sector boundary. Return (false, "reason") to deny the jump with a message to the player.

Parameters:


OnPlayerJoin link

public virtual void OnPlayerJoin(ulong steamID, string playername)

Called when a player joins the server.

Parameters:


OnPlayerLeft link

public virtual void OnPlayerLeft(ulong steamID, string playername)

Called when a player leaves the server.

Parameters:

Tips link