2
I need help with /testfor command!
so i have been making a map and need a command block to do something when a player steps on a block.
currently it is:
/testfor @e[type=player]
but i want to make it only detect players when they step on a certain XYZ coord
and when they do it will detect the player and place a redstone block using /fill on an other block
please help as i have tried for about an hour and none of my attempts have worked :(
currently it is:
/testfor @e[type=player]
but i want to make it only detect players when they step on a certain XYZ coord
and when they do it will detect the player and place a redstone block using /fill on an other block
please help as i have tried for about an hour and none of my attempts have worked :(
Create an account or sign in to comment.
7
ok i found out how to do it!
thanks for the help!
thanks for the help!
As mentioned below, you can detect when a player is within a radius of a coordinate position with /testfor. However, that will test as true for everyone, no matter who steps on the block. This works for some situations, but will screw you up in others. If you want to detect if any player is stepping on a specific block, go ahead and use /testfor.
However, there are better ways to do this, maybe by using /execute.
For example, you could use this to set a redstone lamp when any player stands on coal ore.
There are so many ways to do this that I can't list them all. If you need anything else, let me know what you need this for so I can figure out what you need.
Good luck,
Garlicbreathinator
Some examples of using /testfor, click to reveal
To detect if any player is in a small circular area around the point with the coords x y and z (red values are variables). Note that this assumes you haven't already center-corrected the coords and that your point is on the surface, not underground.:
To detect if any player is standing within a the block at coords xyz, (xyz being the block above the block you're testing for players on) you want this instead:
/testfor @a[x=x.5,y=y.5,z=z.5,r=1] |
To detect if any player is standing within a the block at coords xyz, (xyz being the block above the block you're testing for players on) you want this instead:
/testfor @a[x=x,y=y,z=z,dx=<x+1>,dy=<y+1>,dz=<z+1>] |
However, there are better ways to do this, maybe by using /execute.
For example, you could use this to set a redstone lamp when any player stands on coal ore.
/execute as @a ~ ~ ~ detect ~ ~-0.5 ~ coal_ore 0 setblock <x y z> redstone_block |
Good luck,
Garlicbreathinator
No you don't need tags like the other guy is saying, that overcomplicates something simple. You need to put x y z and radius values in the selector part. For example /testfor @a[x=4,y=33,z=23,r=1]
Using a radius of 1 will only test for a player inside that one block. Make sure the y value is not the value of the block in the ground but one above, so it can actually detect a player inside it.
Then put a chain command block afterwards with whatever command you want triggered
Using a radius of 1 will only test for a player inside that one block. Make sure the y value is not the value of the block in the ground but one above, so it can actually detect a player inside it.
Then put a chain command block afterwards with whatever command you want triggered
You can do this, but again it isn't multiplayer friendly and it's bad practice. An example, lets say I want to give everyone a single item within that area. /testfor isn't capable of doing this without a comparator(which causes lag).
~SUPERIONtheKnight
~SUPERIONtheKnight
It is multiplayer friendly, you wouldn't use testfor for a give command you'd just use give command with the same coords in the selector
If I do that and put it on a clock, I will get multiple items whereas in the above example we only want one. /testfor is a way around that, but players will have to wait for everyone else to leave the area in order to get their items.
~SUPERIONtheKnight
~SUPERIONtheKnight
Note: I'm assuming you are using 1.12.2. If you need commands for a different version, be sure to let me know. :)
First off, I wouldn't use /testfor. It isn't multiplayer friendly, and there isn't anything it can do that other commands can't. 1.13 is also doing away with the command altogether.
In this case, tags are exactly what you need. They are basically like giving a second name to an entity that we can use to select it. They have nothing to do with the scoreboard like the command itself suggests. I have no idea why Mojang added them to the /scoreboard players command, it makes it more confusing than it really is. :P
Anyways, on with the commands! :D
The # after xyz should be replaced with the coordinates you are wanting to check, the rest is self explanatory I hope. Although I will also mention that you should use different tags for checking different areas(for example, use the tag "area" to check 0 0 0, and the tag "area2" to check 100 10 100).
I hope this helps! :)
~SUPERIONtheKnight
First off, I wouldn't use /testfor. It isn't multiplayer friendly, and there isn't anything it can do that other commands can't. 1.13 is also doing away with the command altogether.
In this case, tags are exactly what you need. They are basically like giving a second name to an entity that we can use to select it. They have nothing to do with the scoreboard like the command itself suggests. I have no idea why Mojang added them to the /scoreboard players command, it makes it more confusing than it really is. :P
Anyways, on with the commands! :D
/scoreboard players tag @a[tag=area] remove area
/scoreboard players tag @a[tag=!area,x=#,y=#,z=#,dx=0] add area
/execute @a[tag=area] ~ ~ ~ Command here
The # after xyz should be replaced with the coordinates you are wanting to check, the rest is self explanatory I hope. Although I will also mention that you should use different tags for checking different areas(for example, use the tag "area" to check 0 0 0, and the tag "area2" to check 100 10 100).
I hope this helps! :)
~SUPERIONtheKnight