3
Entity detection
Hello, I am working on a mini-game and need to know when all mobs have been killed. I know I need the scoreboard for this but can find the commands. This does need to be in a section area of a world as there are other things that would mess it up otherwise. what are the commands to do this?
Thank you,
Thank you,
7
TheLithium have you tried the @e[type=!Player] tag? This will detect every entity that isn't a player. You could use this to verify that there are no entities other than the player within a certain distance. You'd want to make sure the mobs don't drop items though, or else players would need to collect all the drops first or change the command to include items.
you dont need scoreboard just
/execute unless entity @e[type=(your mob),distance=..(max radius)] run (command)
if you want more than one mob tell me and I can tell you that too (or just make multiple of this)
/execute unless entity @e[type=(your mob),distance=..(max radius)] run (command)
if you want more than one mob tell me and I can tell you that too (or just make multiple of this)
I have a lot of them that change with each wave.
If the goal is to detect when all hostile mobs within the area are dead and the types of mobs tracked don't change (like if zombies did count in wave 1 but after wave 5 they don't and you can finish a wave without killing them all) you can include multiple "unless" statements in the same command.
For example, this will run when all zombies, skeletons, and spiders within 100 blocks are dead.
/execute unless entity @e[type=zombie,distance=..100] unless entity @e[type=skeleton,distance=..100] unless entity @e[type=spider,distance=..100] run (command)
Tags (datapack tags, I will call them #tags) can also be used as a tool to group things, like types of blocks or types of entities. for example, @e[type=#raiders,distance=..100] includes Evokers, Vidicators, Illusioners, Pillagers, Ravagers, and Witches. With a datapack, you can create your own entity type #tag that groups all the mobs you want to count.
A different feature also called tags (I will call it /tags) can be used to mark specific mobs manually either through their data when they are spawned or through the /tag command. For example, you could add a /tag called "marked" to a mob with /tag add <mob> marked and then detect it with @e[tag=marked]. You can also define a mobs /tags in its NBT data, so they spawn with a /tag already applied to them. For example, /summon minecraft:zombie ~ ~ ~ {Tags:[marked]}. By using the NBT of a spawn egg, you can make a spawn egg for a mob with this data attached to it.
For example, this will run when all zombies, skeletons, and spiders within 100 blocks are dead.
/execute unless entity @e[type=zombie,distance=..100] unless entity @e[type=skeleton,distance=..100] unless entity @e[type=spider,distance=..100] run (command)
Tags (datapack tags, I will call them #tags) can also be used as a tool to group things, like types of blocks or types of entities. for example, @e[type=#raiders,distance=..100] includes Evokers, Vidicators, Illusioners, Pillagers, Ravagers, and Witches. With a datapack, you can create your own entity type #tag that groups all the mobs you want to count.
A different feature also called tags (I will call it /tags) can be used to mark specific mobs manually either through their data when they are spawned or through the /tag command. For example, you could add a /tag called "marked" to a mob with /tag add <mob> marked and then detect it with @e[tag=marked]. You can also define a mobs /tags in its NBT data, so they spawn with a /tag already applied to them. For example, /summon minecraft:zombie ~ ~ ~ {Tags:[marked]}. By using the NBT of a spawn egg, you can make a spawn egg for a mob with this data attached to it.
setup:
/scoreboard objectives add count dummy
/scoreboard players add 1 count 1
loop:
/execute as @e run scoreboard players add count count 1
/execute if score count count = 1 count run
/scoreboard players set count count 0
(1 because player if you want multyplayer ask again)
/scoreboard objectives add count dummy
/scoreboard players add 1 count 1
loop:
/execute as @e run scoreboard players add count count 1
/execute if score count count = 1 count run
/scoreboard players set count count 0
(1 because player if you want multyplayer ask again)
Wouldn't it be something else to detect the mobs? the players stay the same until they die, the number of mobs and the types of mobs change.
you can also do the same thing with tags so its just mobs(spawn your mobs with tags, this will work in multiplayer too)
setup:
/scoreboard objectives add count dummy
/scoreboard players add 0 count 0
loop:
/execute as @e[tag=mob] run scoreboard players add count count 1
/execute if score count count = 0 count run
/scoreboard players set count count 0
setup:
/scoreboard objectives add count dummy
/scoreboard players add 0 count 0
loop:
/execute as @e[tag=mob] run scoreboard players add count count 1
/execute if score count count = 0 count run
/scoreboard players set count count 0
