Skip to content

Script calls User API

Pheonix KageDesu edited this page Feb 26, 2024 · 11 revisions

⚠️ Information actual for version 0.8.2 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

  • nAPI.ID() - return current game unique ID

  • nAPI.setWaitWhenTransfer(true|false) - same as plugin parameter Wait Map Transfer?, but you can change it dynamically durting game.


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()

Conditions in Events

  • nAPI.getEventParticipant(field)
    return true or false

Using for checking who right now execute current event

Example:
2022-06-21_19-27-40


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))

  • nAPI.setupAutoSyncPropertyForCharacter("fieldName", true|false); - register the character (Game_CharacterBase class) field for auto-synchronization over the network.

  • nAPI.setupAutoSyncPropertyForBattler("fieldName", true|false); - register the battler (Game_BattlerBase class) field for auto-synchronization over the network.

These methods are needed so that you can make auto-synchronization of any additional data (variables, fields) of the character (or actor) if, for example, you use third-party plugins. For example, you are using a plugin that adds a new field (weight) to all characters and you want this variable to synchronize over the network.

Example:

nAPI.setupAutoSyncPropertyForCharacter("_characterImage", true); // add field _characterImage for autosynchronization  
nAPI.setupAutoSyncPropertyForBattler("weight", false); // remove (previously added) field weight from autosynchronizatoin  

⚠️ 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