How to give a player an effect while near a certain mob? [closed]

I’m trying to make it so that players within 5 blocks of a wolf get a defense boost, how do I pull that off?


It is in fact very simple, and took just a bit of messing around. There are a few steps to building the command:

  1. Build need a Repeat Always active command block
  2. You'll need a /execute at command, so the command is executed from a different position than that of the command block.
  3. Specify the entity selector: @e[type=Wolf], so that the command is executed at every wolf.
  4. Create the command you want to apply on players around wolves: run effect @a[distance=..5] minecraft:resistance 1 0

Now combine all that into one command:

/execute at @e[type=minecraft:wolf] run effect give @a[distance=..5] minecraft:resistance 1 0

This command gives the Resistance effect to every plpayer that is 5 or less blocks away from a wolf.