-
Notifications
You must be signed in to change notification settings - Fork 0
Create your first Neutron Mod
Neutron Mod is written in Node.js, please ensure that you have the following environment before creating Mods:
- Node.js ( >= 8.0 )
- npm
- A wise brain
Next, go to the project directory and execute:
npm i neutron_nodeNext, add this part into your code:
var neutron_node=require("neutron_node");
neutron_node.startNeutron((Listener,cancelListener,Game)=>{
Listener("PlayerMessage",(data)=>{
Game.ExecCommand(`say ${data.sender}:${data.msg}`);
});
});To explain the script above, startNeutron is a function. When the connection between Neutron plug-ins and the main program is opened, the incoming callback function will be executed.
The callback function would return three values: Listener, cancelListener and Game.
1. Listener
Listener is a function to subscribe events from the server. Only the subscribed events would/can be captured. The function prototype as follows:
function Listener(Event,callback)
//Event should be a monitored event, passed in as a string, callback is a callback function, the format is as follows:
function callback(data)
//When this event occurs, the callback will be called and the content will be stored in data (type is Object).2. cancelListener
cancelListener is a function to cancel an 'event subscription'. Its function prototype as follows:
function cancelListener(Event)
//Event should be a monitored event, passed in as a string.3. Game
Game is an object in where the game methods were stored. You can call functions in this object to modify the game.
For how to use, go subsequent documents.