-
Notifications
You must be signed in to change notification settings - Fork 5
Script calls User API
Pheonix KageDesu edited this page Apr 20, 2021
·
11 revisions
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()
nAPI (script calls)
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)
CustomCmd (003) in Demo Project on map nAPI (script calls)
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
}
};