Can I exclude a player within a radius from a game-mode change?
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.