1

How can I program a command block (or a combination of blocks) to teleport nearby player only if there is exactly one player nearby?

I.e. when button pressed, if there are more than one player within a radius of 6 blocks, don't teleport.

I tried two approaches:

  1. combining /execute if score with /testfor

  2. using testfor with a comparer block to compare with the constant 1

The first approach resulted in a syntax error.

The second approach the command block output was stuck on _ and I also couldn't find a way to enter 1 into the the comparer (no constant option in the command block documentation)

I have tested this on the latest versions of Minecraft for Android (1.5.1) and for Xbox (1.5.1), both Bedrock editions.

Is there any way to do this?

  • Which version are you on? I'm going to suggest you use the latest, 1.13, because commands were overhauled and are much more powerful now. Because of the overhaul, testfor no longer exists, but that's a good thing, since testfor was mostly useless. (This might have actually been the perfect use for testfor, ironically enough, but I'd have to think about the solution a bit more.) – MBraedley Jul 23 '18 at 14:06
  • I didn't even know that testfor still existed. Since 1.8 you only need it rarely, since 1.9 even rarer and now in 1.13 you should completely forget about it. What is a "comparer block" in your understanding? There's a comparator, but you don't need that for a command block system either. The list of commands can be found in the wiki under "commands", not under "command block". – Fabian Röling Jul 23 '18 at 23:33
  • @MBraedley I'm using the Bedrock edition, not the Java edition. The version numbers seem to be different. – Danny Varod Jul 23 '18 at 23:49
  • @Fabian I read the wiki, however, the documentation regarding execute commands seems to be lacking details. – Danny Varod Jul 23 '18 at 23:56
  • @DannyVarod You're on Bedrock edition? Wow, that changes everything. I don't think they even have the new command system yet. But you should still be able to test for one player and test for two players, just not as easily as in Java edition. – Fabian Röling Jul 24 '18 at 1:03
0

Testfor is in P.E.

/testfor @a[r=3] 

This will activate when someone is in a 3 block radius (Toggle the number as needed) also add c to toggle the max.

Example: testfor @a[r=3,c=5]

Comparators will produce a current from one to five which is max detection limit is 5.

Testfor was removed in version 1.13 (aka the “aquatic update”) on the computer. Also the “r” was replaced with the word “distance”. Computer players should use the following.

Execute @a[distance=3] ~ ~ ~ (your command here)

(Computer information was found on Minecraftforum.net by user OuOun)

| improve this answer | |
  • Thanks for the answer, however, question refers to Bedrock Edition. – Danny Varod Jan 8 '19 at 16:44
  • Edits done on the answer – Bratworst Jan 8 '19 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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