-
Notifications
You must be signed in to change notification settings - Fork 171
Permanent Channels
Garma edited this page Jul 20, 2013
·
2 revisions
Scripting/Server/Permanent Channels
Per default all channels you create on a server are destroyed once the last player leaves it (with the exception of the main channel). You can, however easily make a channel permanent so it stays there even if it's already empty.
function POChannel() {
this.permanent = false;
}
SESSION.registerChannelFactory(POChannel);
Now you need 2 commands to change the "permanent" value.
if (command == "perm") {
if (sys.auth(src) >= 1) {
if (command_data != undefined) {
if (sys.existChannel(command_data)) {
var chan_id = sys.channelId(command_data);
if (!SESSION.channels(chan_id).permanent) {
SESSION.channels(chan).permanent = true;
sys.sendMessage(src, "The channel " + command_data + " is now permanent.", chan);
} else {
sys.sendMessage(src, "The channel " + command_data + " is already permanent.", chan);
}
} else {
sys.sendMessage(src, "That channel doesn't exist.", chan);
}
} else {
sys.sendMessage(src, "You need to select a channel.", chan);
}
} else {
sys.sendMessage(src, "You don't have permission to use this command.", chan);
}
}
if (command == "unperm") {
if (sys.auth(src) >= 1) {
if (command_data != undefined) {
if (sys.existChannel(command_data)) {
var chan_id = sys.channelId(command_data);
if (SESSION.channels(chan_id).permanent) {
SESSION.channels(chan).permanent = false;
sys.sendMessage(src, "The channel " + command_data + " is not permanent anymore.", chan);
} else {
sys.sendMessage(src, "The channel " + command_data + " is not permanent.", chan);
}
} else {
sys.sendMessage(src, "That channel doesn't exist.", chan);
}
} else {
sys.sendMessage(src, "You need to select a channel.", chan);
}
} else {
sys.sendMessage(src, "You don't have permission to use this command.", chan);
}
}
Last thing is catching the channelDestroyed event.
beforeChannelDestroyed : function(chan) {
if (SESSION.channels(chan).permanent) {
sys.stopEvent();
}
}
And that's it!