This little code will let you display a message on the users screen when they are disconnected from the node server or when the node-server is down.
There are two ways to do this, through a switch to set on / off, or through a variable, or both 🙂
open in your plugin folder: Online_network_player.
find the following line in the plugin:
socket = $gameNetwork._socket.netplayers;
For a variable:
Add underneath the following line:
Change the 1700 = the number of the variable and 5 = the value assigned to the variable when disconnected.
// Control variable after connection is lost
socket.on(‘disconnect’, function() {
$gameVariables.setValue(1700, 5);
});
Find the following line in the plugin:
networkName = data.name;
add beneath this line:
Change the 1700 to the number of the variable you want change when connection is back.
//Control variable when connection is restored.
$gameVariables.setValue(1700, 0);
Tip from Squareware, you can use the variable to set a certain text before the user is logged in or display a picture corresponding depending on the value the variable ha,s like this example:
var [x = 0], not yet connected.
var [x = 1], connected.
var[ x =2], disconnected.
You need to be creative but you will think of something.
For the switches, you do the same except a switch is either on or off.
So when a switch is turned on because of a connection issue, you can run a commen event to display a warning message or do something else. When the connection is restored, the switch is turned back off.
You just need the change the variable from the above snippit to a switch:
And copy past it at the same palces.
In this snippe t 1700 is the switch that being true = on and false = off.
// Control variable after connection is lost
socket.on(‘disconnect’, function() {
$gameSwitches.setValue(1700, true);
});
//Control variable when connection is restored.
$gameSwitches.setValue(1700, false);