#Script - Custom commands

4 messages · Page 1 of 1 (latest)

unreal horizon
#

How to make a command like
If i entered "!cboutput" the gamerule will turn false,and if i do it again,it will turn true,or depends on world's gamerule

import { world } from '@minecraft/server';

world.events.beforeChat.subscribe(async (eventData) => {
    const player = eventData.sender;
    if (!player.hasTag('Admin')) return;
    switch (eventData.message) {
        case '!help':
            eventData.cancel = true;
            await player.runCommandAsync('tellraw @p {"rawtext":[{"text":"§l×××××××××××××××××××××××××××§r\n§lAdmin commands§r\n§7Prefix *§f!§7*§r\n\nhelp §7- show lists of cmds§r\ngms §7- survival mode§r\ngmc §7- creative mode§r\nspec §7- spectator mode§r\ncb §7- command block§r\ncboutput §7- disable commandblock output§r\nc §7- clear inventory§r\n§l××××××××××××××××××××××××××××"}]}');
            break;
        case '!gmc':
            eventData.cancel = true;
            await player.runCommandAsync('gamemode c');
            break;
        case '!gms':
            eventData.cancel = true;
            await player.runCommandAsync('gamemode s');
            break;
        case '!cb':
            eventData.cancel = true;
            await player.runCommandAsync('give @p command_block');
            break;
        case '!spec':
            eventData.cancel = true;
            await player.runCommandAsync('gamemode spectator');
            break;
        case '!cboutput':
            eventData.cancel = true;
            await player.runCommandAsync('gamerule commandblockoutput false');
            break;
        case '!c':
            eventData.cancel = true;
            await player.runCommandAsync('clear @p');
            break;
        default: break;
    }
});
ivory flicker
#

Wth is that vertical sentence

solemn trout
#

@unreal horizon You could do this a couple of ways. I would first try assigning a variable to the result of 'gamerule commandBlockOutput', and see if you cannot read the Promise to find if the gamerule was on or not. Then you can assign true or false to the gamerule depending on its value.

#

If that does not return the current value of the gamerule, then you could implement some toggle that will flip the gamerule.

Run these commands somewhere to initialize some scoreboards:

scoreboard objectives add gamerule dummy
scoreboard objectives add const dummy
scoreboard players set "2" const 2

Have the script invoke a function containin these commands, assuming you can use new /execute:

scoreboard players add commandBlockOutput gamerule 1
scoreboard players operation commandBlockOutput gamerule %= "2" const
execute if score commandBlockOutput gamerule matches 1 run gamerule commandBlockOutput true
execute if score commandBlockOutput gamerule matches 0 run gamerule commandBlockOutput false