3

So I am giving Command Blocks a first try and I've found that with the comparator you can make it so it perceives a player is near them (and of course if you use the [r=x] tag.
The scenario I am trying to make is one where are 2 players or more, (player N and player M.)

  • N is in range and the Command Block's condition applies.
  • M enters the range while N also is in it. Condition applies too.

Essentially, I am trying to make a bubble that, whenever someone enters, gets the perks of being inside without the need of the other one leaving; on the contrary, I am getting no change if someone is in range already.

The layout I am using is the following: redstone layout
By the way, I know this work if people take turns, but I want them to work even when there is someone in the range already, so I am open to change the layout if necessary.
Thanks in advance.

1

This is the down side of using comparators. NOT MP friendly. When one player enters, the command block is already triggered.

Solution 1:

This will constantly re-apply the perk to anyone in range.

Setup:

/scoreboard objectives add inRange dummy

Clock(20tps Fill Clock)

/scoreboard players set @a inRange 0
/scoreboard players set @a[x=<X>,y=<Y>,z=<Z>,r=<Range>] inRange 1
Run commands that will give the perks using the player selector @a[score_inRange_min = 1]

Solution 2:

Simpler version of Solution 1

Clock(20tps Fill Clock)

Run commands that will give the perks using the player selector @a[x=<X>,y=<Y>,z=<Z>,r=<Range>

Solution 3:

Give perk upon entering range.

Setup:

/scoreboard objective add inRange dummy

Clock(20tps Fill Clock)

Run Commands that will give the perks using the player selector @a[x=<X>,y=<Y>,z=<Z>,r=<Range>,score_inRange = 0]
/scoreboard players set @a inRange 0
/scoreboard players set @a[x=<X>,y=<Y>,z=<Z>,r=<Range>] inRange 1

Explanation:

Solution 1:

First reset the score of all players. Then mark all players within range on a scoreboard, and finally run a command on all marked players.

Solution 2:

Straight up run a command on all players within range

Solution 3:

Run a command on all players that are in range but have not been marked aka. just entered the range. Then reset the score and mark all players in range.

| improve this answer | |

Your Answer

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

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