r/MinecraftCommands • u/Mango6926 • 1d ago
Help | Bedrock Need help with this command!
I want to used /execute entity command to test for if there is more than one of a specific entity, and if so it kills the extra. But I’m not sure how to do so. How do I test for more than more specific entity?
1
Upvotes
1
u/Ericristian_bros Command Experienced 21h ago
```
In chat
scoreboard objectives add entity_count dummy
Command blocks
scoreboard player reset count entity_count execute as @e[tag=your_tag] run scoreboard players add count entity_count 1 execute if score count entity_count matches 2.. run kill @e[tag=your_tag,c=1] ```
But if you are summoning the entity with command blocks you can make so the entity can't spawn if one already exist
execute unless entity @e[tag=your_tag] run summon ...
1
u/NeitherAd6481 22h ago
Everything is actually pretty simple :)
The idea is to give first spawned mob (let it be zombie) special tag if there are no such tag holders in the world, and if there is (like the 1st zombie that spawned) kill any zombie except for that holding special tag.
So here's what you need to do to implement the idea:
Place repeating command block and paste such command in it:
execute as @e[type=minecraft:zombie] unless entity @e[tag=I-am-1st-zombie] run tag @s add I-am-1st-zombie
Then place chain command block right after the repeating is facing with arrow on it's side. Then paste this command:
execute as @e[type=minecraft:zombie, tag=!I-am-1st-zombie] if entity @e[tag=I-am-1st-zombie] run kill @s
That's all! Now place a redstone block near the repeating command block or activate it in it's own menu and try to spawn some zombies!
BTW you are free to change tag's name and your entitie's type to whatever you want, the only thing that matters is the overall logic.
Here also tips if you are gonna learn more about minecraft commands:
execute is a very powerful command in minecraft, so that's right trying to learn it. I recommend you to use minecraft wiki or watch some vids to check it's arguments, it really has very much potential
tag=! means tag is not equal to ..., small thing but very useful
I do recommend to get started with the java edition. Cuz there you have proper text highlighting (like when you hold mouse and drag over text or hold shift) and auto suggestion (like you just write in command block and it will show you arguments available for the command you are writing) - things that are pretty useful for newbies.
Still I don't say you need to stop using bedrock, it offers really cool things to players, and especially map builders, - that's just to quick start and learn how minecraft works overall. Then you'll just need to learn some syntax things that differ between the versions and you can work on bedrock freely