-
Notifications
You must be signed in to change notification settings - Fork 171
Mute Script
Muting someone is useful to let the user stay on the server and even do battles while not letting him write anything into the server's channels.
PO provides no built-in mute function, so you have to write one on your own. It's not much work though.
function POUser() {
this.muted = false;
}
SESSION.registerUserFactory(POUser);
Everyone who joins the server will be unmuted per default. Funny thing: You can also set this.muted
to true; it will automute new users.
Now that every player session has an indicator if someone is muted, you need to have a command to change this indicator.
// Place this somewhere in your commands
if (command == "mute") {
if (sys.auth(src) >= 1) { // this allows users to use this command as moderator and higher
if (command_data != undefined) {
var tar = sys.id(command_data);
if (sys.auth(src) > sys.auth(tar)) { // you need this so you can only mute lower auth
if (!SESSION.users(tar).muted) {
SESSION.users(tar).muted = true;
sys.sendAll(command_data + " was muted by " + sys.name(src) + "!", chan);
return; // you need to return here, otherwise the else tree is executed
} else {
sys.sendMessage(src, command_data + " is already muted.", chan);
}
} else {
sys.sendMessage(src, "You can only mute lower auth.", chan);
}
} else {
sys.sendMessage(src, "You need to select a player.", chan);
}
} else {
sys.sendMessage(src, "You don't have permission to use this command.", chan);
}
}
If you use the command handling from here you will have the variables command and command_data defined, so this won't be a problem. src and chan you should be available if you use those a parameters when the declaring the beforeChatMessage event.
Last thing to do is getting if someone is muted. As you only want to block chat messages, you need only one event.
beforeChatMessage : function(src, message, chan) {
if (SESSION.users(src).muted) {
sys.stopEvent();
sys.sendMessage(src, "You are muted, so you can't talk.", chan);
}
}
Now always when someone sends a message into a channel, the server checks if the sender is muted. If that's the case, it stops the message from being send and notifies the player that he is muted.