How do I target only players who are at a certain height?
		
		
						I own a server, and have built a large indoor structure at spawn. I would like new players to spawn inside this structure. Upon research, Minecraft automatically spawns all players at the highest available y position, meaning players will spawn on my roof instead of inside. I've tested this myself; used /setworldspawn in the center of the building, and used /kill on myself a bunch of times. About half the time I spawned on the roof, the other half outside my building.
I would like to target all players above y=69 in a 60 block radius and teleport them to x=-62,y=64,z=-245. I have a hopper clock and command block already set up with everything except the ability to target everyone on my roof:
What do I want to put in the command block to teleport anyone on my roof into the building?
Best Answer
The classic, simple and efficient solution is to use a plugin like Essentials to define a precise spawn position. But you need to use bukkit spigot or some other modified server.
If you are on vanilla minecraft (no modification), a workaround is to put pressure plates on all potential spawn places (20x20 => [http://minecraft.gamepedia.com/Spawn#World_spawn][1]) which will activate command block(s).
Then you have 2 options:
The first is simply to teleport players to the position you want:
tp <player> <x> <y> <z>
for example (if 123 456 789 is the world spawn point):
tp @a[x=123,y=456,z=789,r=11] 987 654 321
(r is the radius and if you want to keep a random on spawn point you can use relative coordinates (using "~").
- The second solution is to use a fill clock:
 
(search it on google to know what it is and how to create one).
How to (re)start a fill clock:
setblock <x> <y> <z> air
setblock <x> <y> <z> redstone_block
As x,y,z put the coordinates of the first redstone_block of the fill clock.
What to put on the fill clock: tp @a[x=123,y=456,z=789,r=11] 987 654 321
If you want to be more precise on the area where players must be TP use a invisible ArmorStand with PersistenceRequired:1 to define at first point of the area and use "dx", "dy" and "dz" parameters in the selector to define the relative coordinates of the second point of your area. It will result in a command like this one:
execute @e[type=ArmorStand,name=MyAreaFirstPoint,c=1] ~ ~ ~ tp @a[dx=20,dy=3,dz=20] <x> <y> <z>
    					Pictures about "How do I target only players who are at a certain height?"



How do you know if a player is at a certain y level?
This can be tested out by using stairs, slowly walking up them, using F3 to check the y value while the command is running. The "hi" will appear even if not exactly at the desired y value.How do you target all players in Minecraft?
The @e target selector is used to target all entities in the game. This includes both players and mobs in the world.What is the Spreadplayers command in Minecraft?
You can use the /spreadplayers command to teleport all targeted players to random locations in a specified region.What is DX DY DZ Minecraft?
dx dy dz target selector defines coordinates relative to a block.How to get taller according to basketball players
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: tyler hendy, Mikhail Nilov, SHVETS production, SHVETS production
