TransWikia.com

Can I exclude a player within a radius from a game-mode change?

Arqade Asked by Forgest on October 5, 2021

I know you can change all players to the ‘adventure’ game mode within a certain radius, but is there a way to exclude certain players from this?

The server I’m in is vanilla, with 0 plug-ins/mods and therefore, no claim blocks.

I am hoping there is a way to change the gamemode of everyone in the radius to adventure mode, except for the property owner. Is this even possible?

One Answer

To set the gamemode to Adventure of all players whose name isn't "gamer" within 32 blocks from the entity invoking the command, simply use:

/gamemode adventure @a[distance=..32, name=!gamer]

The name selector argument can be used multiple times to exclude more entities (note the requirement of " in the case spaces are present in the name):

/gamemode adventure @a[distance=..32, name=!gamer, name=!"epic gamer"]

This is one of the most commonly used ways to exclude yourself from your own commands.


Another alternative is through the use of tags and the /tag command, which will allow you to permanently mark specific players to be excluded from having their gamemode changed.

To add a tag to the calling entity (in case it's a player) and then set everyone else's withing 32 blocks mode to Adventure, use these two commands:

/tag @s add noAdventure
/gamemode adventure @a[distance=..32, tag=!noAdventure]

... or alternatively you can set the mode for everyone having no tags:

/gamemode adventure @a[distance=..32, tag=]

To remove a tag from yourself use /tag @s remove noAdventure, to see all current tags on yourself, use /tag @s list.


Another approach coming to mind is taking advantage of knowing the number of players participating so that you would exclude yourself. If exactly 10 players are present in the 32 block area, then to set everyone else's mode except the one of yourself, use:

/gamemode adventure @a[distance=..32, limit=9, sort=furthest]

This leverages the fact the furthest entities will be targeted first and if there are at least 9 other players within the range with you, they will be targeted before you and the command will end before reaching you as well.


One last approach I can think of can be handy in case you are the only player nearby in Creative (say, after having built an adventure map for others). Then to set everyone else nearby to Adventure, the command once again becomes simple:

/gamemode adventure @a[distance=..32, gamemode=!creative]

A bonus command - to set everyone's game mode back to Survival from Adventure, use:

/gamemode survival @a[gamemode=adventure]

I hope one of these methods will come in handy. In case of any questions, don't hesitate to ask.

I invite you to read more about the target selector arguments in the excellent wiki article about commands.

Answered by Marty Cagas on October 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP