1

This question already has an answer here:

I have an area where players drop down from the lobby in the sky down to the ground on my server but I want the area where they drop down to have a thing set up so they become adventure mode, but when leave that radius go into survival mode, and when go back in the area the become adventure mode again. So like spawn protection but I want to use command blocks. I know how to use them I just need the command for it!

marked as duplicate by Timmy Jim, Lore Friendly, user973, dly, Wrigglenite Jun 19 '17 at 11:53

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

How to Set up a Radius Based Command for Setting Gamemodes

  1. Find the center of the area you want to affect
    • The shape will be a circular pattern
    • Height is also included in this radius(Sphere not cylinder)
  2. Hide the Command block at the Center of the area
    • Depending on Minecraft Version, use either a redstone clock(Pre 1.9) or a Repeating Command Block(1.9 and forward) to power it.
  3. In the Command Block Paste the Following Command(I will add more details on this later)
    • Adventure: /gamemode a @a[r=3]
    • Survival: /gamemode s @a[r=3]
    • Creative: /gamemode c @a[r=3]
    • Spectator: /gamemode sp @a[r=3]
  4. Test. Make sure that it works before relying on it for security

The Command

note: replace {gamemode} with 0, s, survival or 1, c, creative or 2, a, Adventure or 3, sp, spectator

/gamemode {gamemode} @e[r=#]

using the @e[r=#] allows you to affect all players(@a) in a radius([r=#]) around the command block. You can use this with any command(the /gamemode command in this case) that you don't want to affect all things globally.

Extra Customization

You can Target only Players in a specific gamemode by using @a[r=#,m={gamemode}]

You can also target all players not in a specific gamemode using @a[r=#,m=!{gamemode}]

Targeting only specific gamemodes(or at least ignoring the one they are becoming) will reduce chat spam

Using @a[r=#,name=!{YourName}] will allow you to be ignored by the command block(so you can stay in creative but stop others from being in creative)

If you don't want the command block at the center of the location you can use @a[r=#,x=#,y=#,z=#] to change the location of the command execution

Tips/Tricks/Other

  1. Make sure two gamemode changing commands to not overlap to prevent the user from being repetitively changed back and forth
  2. You can avoid Overlapping radius's by ensuring the only entry/exit is through a specific path, you can then use a smaller radius and only affect those entering/exiting the location.
  3. Another way to prevent overlap is to have your spawn area far away from the rest of the world and use /tp command to move players between the two locations
  4. [rm=#] can be used to select an area outside of a radius. useful for setting up two command blocks that affect the whole world(one for inside the spawn area, and one for outside the spawn area)
  5. Assumptions were made that this is a vanilla server (and thus, redstone security) if not then there are several plugins that can help with setting up permissions based on location(which I believe goes beyond this question so I will leave it at that)

Sources

I received all of my information from the Minecraft Wiki.

Commands: http://minecraft.gamepedia.com/Commands

Command Blocks: http://minecraft.gamepedia.com/Command_Block

I also verified my understanding by testing in Minecraft (1.9.2)

0

From the minecraft wiki:

Syntax

gamemode [mode] [player]

Must be one of: survival (can be abbreviated as s or 0) for survival mode

creative (can be abbreviated as c or 1) for creative mode

adventure (can be abbreviated as a or 2) for adventure mode

spectator (can be abbreviated as sp or 3) for spectator mode

So for yours, you would do "gamemode a [playername]"

  • i know that but how would a i make it in a certain radius the became that them when left became srv. mode – IcyBlade Aug 11 '16 at 23:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.