2

I'm trying to count entities and execute when there are 0 left.

All of the answers I've found no longer apply in Minecraft 1.16.200

How to count entities with commands/check if there are only one or a certain number of entities or players left?

That link using scoreboard was the latest but it's sadly outdated as well. It gives errors. The closest I've come without errors is as follows; /execute if ~~~ test for @e[type=!player, r=100, c=1]

However it just says no targets match selector. I kill all entities and summon only one. It never finds it.

Maybe someone can show me where I'm going wrong or they can correct the above post to work in the updated version?

2
  • 3
    The answer you found are not outdated, but they're for Java Edition, which has a very different command system. Bedrock Edition commands are stuck in an older system, and it's tricky to get some things done. Dec 25 '20 at 18:11
  • Ah cool thanks for the info. I did some messing around and got close but not there yet. Most of the stuff I'm finding must be for the Java
    – C G
    Dec 26 '20 at 2:39
0

I figured it out with the above linked post as a guide. Thanks Fabian and AMJ! Ok so I have bedrock edition 1.16.200 and as we know the code is different etc. I used command blocks for everything. I created a battle arena that once you press the button it summons enemies, teleports you in. Then once the enemies are dead you teleport out. The last part was very hard to figure out in BE.

Here is the info for anyone who wants to do the same thing. I won't go over teleporting you in and summoning enemies. That is pretty straight forward and can be found easily.

Steps: Create your world. Setup scoreboard like this using chat first.

/scoreboard objectives add entityCount dummy

Place command chain block at end of your summon/teleport chain with this code. It will start the whole checking for bad guys chain by placing a redstone block in front of the second set / chain of command blocks.

/setblock -14 4 12 redstone_block Places a block to wherever you need it (replace numbers with your own of course.)

The second chain set starts as follows: First block type REPEAT, UNCONDITIONAL, NEEDS REDSTONE, DELAY IN TICKS 20 (so it won't be spamming, just checking once per second)

/scoreboard players set count entityCount 0

Second block: CHAIN, CONDITIONAL, ALWAYS ACTIVE, 0 TICKS

/execute @e[type=!player] ~~~ scoreboard players add count entityCount 1 Important note! type=!player will also count arrows etc. So you might want to specify zombie, vex or whatever you have. I don't allow bows, block drops, enemy drops etc.

Third block: CHAIN, UNCONDITIONAL, ALWAYS ACTIVE, 0 TICKS

/scoreboard players test count entityCount 0 0 This checks that the number it has counted has now reached a range of 0. Range of 0 to 0.

Fourth block: CHAIN, CONDITIONAL, ALWAYS ACTIVE, 0 TICKS

/tp @p -24 5 9 Teleports you to whatever numbers you put in there.

Fifth block: CONDITIONAL, ALWAYS ACTIVE, 0 TICKS

/setblock -14 4 12 air 0 Replaces that redstone block you placed earlier with air. This stops the chain hence ends the cycle. It will start again when you hit your button and it places the redstone block at the beginning again.

Sixth block: CHAIN, CONDITIONAL ALWAYS ACTIVE, 0 TICKS

/say YOU WON! YOU KILLED THEM ALL! This is optional. You can make it give you experience or food or start another round, or move you to a harder area, or summon a new harder set of bosses. The sky is the limit!

I hope it helps everyone. It sure opened up my possibilities and the way I thought about the coding.

1
  • TL;DR: Scoreboard counting entities, scoreboard test command to detect when none are left. Jan 21 at 4:09

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.