1

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)?

  • Have you made any attempt to solve this yourself? Arqade works better when askers show effort to solve their own problems; we see that you have a problem you've worked on, and answerers respond to that. You also get a more specific answer that's tailored exactly to the part you're stuck, and Arqade gets a very specific question. Everybody wins! – Frank Oct 22 '15 at 11:54
3

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

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.