-2

This question already has an answer here:

I am trying to make this command where a lightning bolt will be summoned at every arrow shot from a specific bow, and I need it to work on multiplayer. I have tried to use the /testfor command but cannot figure out how to target the exact player shooting the bow. Does anyone know how to do this?

marked as duplicate by Fabian Röling, greg-449, Schism, RudolfJelin, Wondercricket May 13 at 12:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Have a look at this question and this question. They are very similar questions. Your question may be considered a duplicate question of the first one. – IronAnvil Sep 4 '17 at 2:44
0

What you are asking for is a bit complicated. It uses a scoreboard and never requires testfor to be used.

Create an objective named TheArrow for targeting purposes:

/scoreboard objectives add TheArrow dummy

Manually type that in chat. I also recommend disabling command block output to prevent chat spam. You can do that with:

/gamerule commandBlockOutput false

Now we have to target the player holding the bow, target the arrows the player shoots, detect when they are in the ground, summon the lightning bolt, and remove the score from the arrow afterwards. I used 6 command blocks in 2 different chains.

Blocks

First command block is a repeating / unconditional / always active. It finds any player holding a bow named Electric and sets TheArrow score to 1 for that player. Its command:

scoreboard players set @a TheArrow 1 {SelectedItem:{id:"minecraft:bow",tag:{display:{Name:"Electric"}}}}

Second command block is a chain / conditional / always active. It finds any arrow within a radius of 2 from a player with a score 1 (holding the named bow) and gives that arrow a score of 2. Its command:

execute @a[score_TheArrow_min=1,score_TheArrow=1] ~ ~ ~ scoreboard players set @e[type=Arrow,r=2] TheArrow 2

Third command block is a chain / conditional / always active. It resets the score for all players. Its command:

scoreboard players reset @a TheArrow 

That is it for the first chain. We have targeted the player holding the bow and targeted his arrows. Now to the rest of it.

Fourth command block is a repeating / unconditional / always active. It targets entities with a score of 2 (targeted arrows) that are in the ground (not still flying) and gives them a score of 3. Its command:

scoreboard players set @e[score_TheArrow_min=2,score_TheArrow=2] TheArrow 3 {inGround:1b}

Fifth command block is a chain / conditional / always active. Now that we have a targeted arrow in the ground, it's time for some lightning. Its command:

execute @e[score_TheArrow_min=3] ~ ~ ~ summon Lightning_Bolt ~ ~ ~

Sixth command block is a chain / conditional / always active. It removes the score from the arrow. If you do not add this, lighting will be summoned at all the previously fired arrows that have not despawned, as well.

scoreboard players reset @e[score_TheArrow_min=3] TheArrow

With that, shoot an arrow from a bow named Electric and you get: Lightning

Here is what happens if you don't have the sixth command block to remove the score: Multiple

You can disable the sixth command block by setting it to impulse and set the fifth command block to unconditional and you get this at each arrow fired. I wouldn't recommend leaving it but it's fun. Lots

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