M BUZZ CRAZE NEWS
// updates

How to apply potion effects only in a certain radius, without applying it to yourself?

By Jessica Wood

I'm trying to apply potion effects to mobs in a certain radius of me without applying it to myself as well, is this possible to do with the current state of commands in Minecraft 1.17?

2 Answers

You can use type=!player to exclude players.

If you want to only exclude yourself, this works:

/execute as @e[distance=..<distance>] unless entity @s[name=<your name here>] run effect give <effect>

4
/effect give @e[distance=0.01..R] <Effect>

Where R is the radius of the effect. It simply means, Every entity that is from 0.01 up to R meters and since the commands in being ran by you, the distance from you to you is 0, which is outside the range given. Considering there is push back, no mob will ever be 0 distance from you.

In case you want to run this from a command block, you will need to use /execute at <target> run ... to get the target's pos (You, in this case). If any questions about execute appear, visit the Wiki or ask another question here in Arqade.