1

I am trying to make a snowball "gun" with an execute command. The gun does damage by giving the wither effect to nearby entities. I want the target selector to include entities within a radius of 1 and to exclude players. From what I have researched, it seems you CAN have a target selector with multiple arguments but nowhere have I found HOW. Here's the command:

/execute @e[type=snowball] ~ ~ ~ /effect @e[r=1,type=!Player] wither 1 6

Please show me how this can correctly be executed.

2

The big problem I ran into while testing this command was the snowball being too fast for r=1 to work. I believe the time between the snowball entering r=1 and being destroyed by hitting the entity is not long enough. If you change it to r=3 it will function. This has the downside of being able to miss an entity by a few blocks and still target it.

Also, to point it out, this will be targeting the snowball in the effect portion of the command. One method I use to determine what is targeted is to use the say command.

Command I used to test your command:

execute @e[type=snowball] ~ ~ ~ execute @e[r=1,type=!Player] ~ ~ ~ say Found

In this case, chat contained several instances of: [Snowball] Found and did not contain any instances of the entity the snowball hit.

I attempted to tag the snowball to exclude it from the target selector. This allowed radius to be reduced to 2 but 1 still does not function.

To add the tag, I used:

scoreboard players tag @e[type=snowball,tag=!Bullet] add Bullet

With the tag, you can exclude it from the effect portion of the command:

execute @e[tag=Bullet] ~ ~ ~ effect @e[r=2,type=!player,tag=!Bullet] Wither 1 6

Neither is a perfect solution though.

Your target selector syntax was correct, including the multiple arguments.

  • You don't need the tag=!Bullet when tagging the snowballs. I don't know what the performance impact would be like one way or the other (I suspect minimal for most cases), but if I were to guess, not having tag=!Bullet would have better performance. – MBraedley Sep 18 '17 at 14:54
  • I added it with the thought of not constantly targeting already tagged snowballs. I am not sure which is more efficient, constantly tagging all snowballs or constantly processing tag=!Bullet for all snowballs. Now I am going to try to come up with a test for this so I can over think it. Thank you for pointing it out, I hadn't really thought much about it. – IronAnvil Sep 18 '17 at 15:03

Your Answer

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