0

Hey I am making a multiplayer map and it includes magical blocks that will give you certain effects for example:

/execute @p[r=10000] ~ ~ ~ detect ~ ~-1 ~ wool 15 /effect @p invisibility 12 3 true

which gives invisibility when the "nearest" player stands on it. How can I give the effect to the player who stands on it, not just the nearest player to the commandblock giving the command?

2 Answers 2

6

The reason it is selecting the closest player to the command block is because you have set the selector to @p, which selects the closest player to the command block to fit the rule...

You're better off selecting everybody who the rule fits to run the command on.

/execute @a[r=10000] ~ ~ ~ detect ~ ~-1 ~ wool 15 effect @p invisibility 12 3 true

This command executes the /effect command on everybody who is within 10,000 blocks of your command block and has a Black Wool block under their feet.

Also, when specifying the command to run, you do not need a second slash.
Secondly, don't forget to run this command in a redstone clock!

3
  • Question: Would this be able to work with multiple people standing on that block. And when I tested this command with multiple villagers (Since I got no one to test it with) they all became invisible. Commented Sep 3, 2015 at 9:40
  • @Phoenix81167 There's a difference between @a and @e. If you want only all players, then use @a. If you want all entities (including Ender Dragons and dropped items), use @e. | btw, Villagers are not players. They have to be selected with @e[type=Villager]
    – aytimothy
    Commented Sep 3, 2015 at 11:21
  • Oh ok. Thank you for the information and I hope I can do the rest of the commands on my own. ;) Commented Sep 3, 2015 at 13:33
0

VERSION 1.16+

execute at @a[distance=10000] if block ~ ~-1 ~ [block] run effect give @p [effect] [seconds] [amplifier] true

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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