Skip to content

Script calls User API

Pheonix KageDesu edited this page Jan 15, 2022 · 11 revisions

⚠️ Information actual for version 0.7 and above

Script calls

System:

  • nAPI.startNetworkGameScene() - starts network game scene (network menu)
    Use this script call if you have custom Title Scene or custom main menu

Network game state and information:

  • nAPI.isNetworkGame() - is current game in multiplayer?
  • nAPI.myPlayerIndex() - client index (in room), host always 1
  • nAPI.myActorId() - client Actor ID
  • nAPI.playersCount() - players count in game
  • nAPI.isMasterClient() - current client is host?

Show different alerts and messages to players:

  • nAPI.showGreenAlert(text)
  • nAPI.showRedAlert(text)
  • nAPI.showInfoMessage(text, subText)
  • nAPI.hideInfoMessage()

For developers:

  • nAPI.getPlayerInfo(field, byField, value)
    field, byField: actor, actorId, netId, actorName, playerName, playerIndex, info (return field)

Example:

nAPI.getPlayerInfo("actorId", "playerName", "Player 333"); // returns integer Actor ID
nAPI.getPlayerInfo("playerName", "actorName", "Reid"); // returns string "Player 333"
  • nAPI.getPlayerCharacter(byField, value)
    (return NETCharacter (inhereted from Game_Character))

⚠️ Examples you can find in Demo Project, map nAPI (script calls)


Create own commands to server in game

You can define your custom server commands and send them to all players. When players received your command, game will start common event that you can specify for each custom command.

  • nAPI.registerCommonEventForCommand(name, commonEventId) - register common event for command with NAME
  • nAPI.sendCustomCommand(name) - send for all command NAME (call registered common event for this command)

⚠️ Example: see event CustomCmd (003) in Demo Project on map nAPI (script calls)


Create own commands to server in code (for plugin developers)

Example code:

// 1. SEND CUSTOM COMMAND
var data = {}; // * some data if you need it (or null)
nAPI.sendCustomCommand("someName", data);

// 2. RECEIVE AND WORK WITH YOUR CUSTOM COMMAND

//@[ALIAS] // Aliasing is REQUIRED!
var _alias_nAPI_onCustomCommand = nAPI.onCustomCommand;
nAPI.onCustomCommand = function (name, data) {
    _alias_nAPI_onCustomCommand.call(this, ...arguments);
    if(name == "someName") {
        // YOUR CODE
    }
};

Download example code file

Clone this wiki locally