Test if there is a minimum amount of mobs within a radius without a scoreboard?

Minecraft 1.12.2

I want to create a re-spawn system for the enemies in the different map areas. I could use a counter on a scoreboard with an armor stand as the entity but with all the areas I have in my map I think it would cause lag.

For example:

I want 5 zombies in an area of 20 block, the player comes and kills 2 of them. The player leaves. The system re-spawns the dead mobs making a total of 5 again.

I know how to test if the player left the area:

/testfor @a[r={radius}]

But what I don't know how to test for the minimum amount of enemies without a scoreboard i can't make it.

I tried the Count modifier in the selector but I realized that is not how it works. I tried something like this:

/testfor @e[type={entity},r={radius},c={amount}]

but it would activate when there was only 1.

In the end:

Is there a way too test for a minimum amount of mobs in a certain radius without a scoreboard?


Could you use tags? Here's a method I whipped up:

You'll want to tag the zombies one by one until you can't tag them anymore, then detect where the tagging stopped. Let's assume you have a maximum of 5 zombies. Repeat these two commands 5 times in a command block, each time adding the number in the first command by 1:

scoreboard players tag @e[type=zombie,tag=!tagged] add 1
scoreboard players tag @e[type=zombie,tag=1] add tagged

This machine will stop tagging zombies once the number tag is equal to the amount of zombies. You can then use these testfor commands to see if there are 3 but not 4 zombies, for example.

testfor @e[type=zombie,tag=3]
testfor @e[type=zombie,tag=4]

Combine with chain command blocks/comparators (whichever is best for you in your situation) until you have the machine you need. And of course you'll have to remove the tags 1 2 3 4 5 and tagged from all zombies, and combine with the radius condition.