Detect Mob between 5 and 10 blocks away from you

Detect Mob between 5 and 10 blocks away from you - Traffic light with red color and TV tower between skyscrapers

I am making a lightning sword. I want to strike lightning on a mob that is within 10 blocks, but at least 5 blocks away from me. Is there any command that can do that (Multiplayer friendly)?



Best Answer

What you need to do is to chain the execute command, and use the r and rm target selector arguments. The latter denote maximum and minimum radius distance from the execution point, respectively.

First, you have to execute on every player triggering the lightning sword. For this command, I'll assume those players have a triggerLightning score of 1 (How or when you set the score is beyond the scope of this question/answer.)

At the location of this player, we start looking for a (single, c=1) entity between 5 and 10 blocks away (r=10,rm=5).

At the location of the entity, we summon the lightning bolt.

execute @a[score_triggerLightning_min=1] ~ ~ ~ execute @e[r=10,rm=5,c=1] ~ ~ ~ summon LightningBolt



Pictures about "Detect Mob between 5 and 10 blocks away from you"

Detect Mob between 5 and 10 blocks away from you - Young office employee listening to music on Manhattan street
Detect Mob between 5 and 10 blocks away from you - From below of young handsome black male in smart suit listening to music and waiting for car to pass while standing near street sign in Manhattan on sunny day
Detect Mob between 5 and 10 blocks away from you - View of Golf Playground Between Rows of Tall Trees



How do you detect if a player is in a certain area?

Range 2 is the range a player want for a command block under a floor. Keep in mind that it will produce a globe shaped trigger area (rather than a cube), so a range of 2 makes an approximately 5\xd75\xd75 area and a range of 1 makes a 3\xd73\xd73 area (more like a + pattern with an extra block above and below the center).

Do command blocks have a range?

2. Type the Command
  • Test if Players are within 10 blocks. In this example, we will test to see if there are any players within a 10 block radius with the following command: /testfor @a[r=10] ...
  • Test if Mooshrooms are within 50 blocks. ...
  • Test if Nearest Player is at Level 20 experience.




  • HOW Is This 5 Blocks Away From Spawn?




    Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

    Images: Tim Gouw, Ketut Subiyanto, Ketut Subiyanto, Antony Trivet