#custom mute command

1 messages · Page 1 of 1 (latest)

civic sonnet
#

I'm trying to make a custom mute command. I have had a start, but i need some pointing to the right direction, because i'm not sure what to do next. I want it to look like this: !mute {player}. Is someone able to help me out?

crimson totem
# civic sonnet I'm trying to make a custom mute command. I have had a start, but i need some po...
// Whenever a chat message is sent...
world.beforeEvents.chatSend.subscribe(function (event) {
    // ... check if they are operator and if they are an operator
    if (event.message.startsWith(".") && event.sender.isOp()) {
        // If they are, then cancel the normal event and find what command they are trying to use
        event.cancel = true;
        // Wait till the next tick so we can modify stuff in the world
        system.runTimeout(function () {
            // ".mute Tsranuna Pogazu" -> "mute"
            switch (event.message.slice(1).split(" ")[0]) {
                case "mute": {
                    // ".mute SomeGuyWith Spaces" -> "SomeGuyWith Spaces"
                    // Find the player based on the input, then give them the tag "scripts:muted" if they exist
                    const player = world.getPlayers({ name: event.message.split(" ").slice(1).join(" ") })[0];
                    if (player === undefined) return void event.sender.sendMessage(`§cPlayer not found`);
                    player.addTag("scripts:muted");
                    event.sender.sendMessage(`§i${player.name} muted.`);
                }; break;
#
                case "unmute": {
                    // ".mute SomeGuyWith Spaces" -> "SomeGuyWith Spaces"
                    // Find the player based on the input, then give them the tag "scripts:muted" if they exist
                    const player = world.getPlayers({ name: event.message.split(" ").slice(1).join(" ") })[0];
                    if (player === undefined) return void event.sender.sendMessage(`§cPlayer not found`);
                    player.removeTag("scripts:muted");
                    event.sender.sendMessage(`§i${player.name} unmuted`);
                }; break;
                // If the command wasn't matched, lest the sender know the command doesn't exist
                default: event.sender.sendMessage("§cCommand not found."); break;
            }
        });
        // Exit the rest of our behaviors
        return;
    }
    // If the sender has the tag "scripts:muted"...
    if (event.sender.hasTag("scripts:muted")) {
        // ... then cancel the normal event and inform them.
        event.sender.sendMessage("§cYou are muted and cannot speak.");
        event.cancel = true;
    }
});