I just made a minecraft server and was wondering if in the server it would be possible to change a player's gamemode when they visit someone else's building(s) (this excludes the owner of the building).
I used the /testfor command but I'm not sure how to select a specific land and change the game mode of the player on it.
2 Answers
Selectors (you should probably use @a for this) can have "Selector arguments". The ones you're interested in for selecting a specific area are:
x, y, z- the coordinates for the starting point of the selection, useless without at least one of the three below:r- the max radius that a player can be from the starting point (like a sphere)rm- the min radius that a player can be from the starting point (so targets anyone outside the sphere)dx, dy, dz- the max x, y, and z that a player can be from the starting point (like a cuboid)
Using a radius is the easiest method. If the build is at 20, 64, -10 for example, you could change your commands to:
/gamemode 1 @a[x=20,y=64,-10,r=15]Which sets the gamemode of anyone within 15 blocks of that point to creative.
With the cuboid selectors, your starting point should be the corner of the cuboid with the lowest coordinates on all axis (so lowest north-western).
dx, dy, dz should then be the positive width, height, and length of the cuboid, as such:
These are more complicated than a radius selector, which you might want to stick with, but will allow you a more accurate area if your build area is cuboid.
Two more selector arguments you should use for this, along with the area selection, are m and name.
mstands for gamemode, which means you can set layers to survival only if their in creative, and vice versa, to avoid repeatedly changing the gamemode of someone already in the gamemode you want them innamewill allow you to "exclude the owner of the building"
Your final command should look something like:
/gamemode 1 @a[x=20,y=64,-10,r=15,m=!1,name=!LyadLaphir]Which changes the gamemode to creative for anyone within 15 blocks of 20, 64, -10, if they're not already in creative, and if their name is not "LyadLaphir" (the !'s mean "not").
This isn't as complex or as fine as the other most popular answer, but I hope it will do.
You can place a powered repeating command block underneath a person's home, and simply use
/gamemode 1 @a[r=whateveryouwant,m=!1]If you want to exclude a certain person or team, use @a[team=!xxx] or @a[name=!xxx], because an exclamation point before the selector means "not".