Arqade Asked by SanCookie on February 16, 2021
I’m making an adventure map and came to a point where all players have to be within three blocks to activate a command.
I tried using the /execute command on a repeating, always active command block but that command executed as soon as one player came within three blocks.
execute if entity @a[distance=..3] run tp @a -424.5 80.1 108.5 135 0
If all players are nearby, that means that no players are far away. In command form:
/execute unless entity @a[distance=3..] run <command>
But that still executes if someone is in other dimensions, you can fix that this way:
/execute unless entity @a[distance=3..] in the_nether unless entity @a[distance=0..] in the_end unless entity @a[distance=0..] run <command>
If you want the command to execute in the overworld, you have to add in overworld
before run
.
Correct answer by Fabian Röling on February 16, 2021
This reason yours is not working is that it is testing for all the players in that area.
If you want to execute a command if all of the players are within range. You probably need to use scoreboards. First would need to create a scoreboard.
/scoreboard objectives add PlayerCount dummy "Number of Players"
Next you either need to have a datapack function that repeats every tick or 2 repeating command blocks which perform these commands
/execute store result score PlayersInWorld PlayerCount run execute if entity @a
(Stores the number of players in the world into PlayersInWorld constant)
/execute store result score PlayersInArea PlayerCount run execute if entity @a[distance=..3]
(Stores the number of players in the range into PlayersInArea constant)
And finally, you test if all the players in the Minecraft world are in that spot by doing
/execute if score PlayersInArea PlayerCount = PlayersInWorld PlayerCount run tp @a -424.5 80.1 108.5 135 0
That is a rather complex solution. Here's a much more simple one, which tests if there are no players outside of the radius rather than testing if all the players are in the radius.
/execute unless entity @p[distance=3..] run tp @a -424.5 80.1 108.5 135 0
Side Note
By using the first solution you can display the scoreboard which would help you know how many players still need to go into the area. You could also replace PlayersInWorld to PlayersRequired and set it to a specific number so that rather than needing all of the players you only need a certain amount.
Answered by Jaedon KLB on February 16, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP