Minecraft – Is it possible to spawn mobs in random places

minecraft-commandsminecraft-java-edition

I was wondering if it is possible for you to make a command block spawn hostile mobs in random places in a specified area?

I need the mobs spawned on different Y coordinates too because you need to fight your way up a tower to the top and I want the mobs to vary on each level to have specialty to each floor every time you play the mini game.

Best Answer

I'm not sure if this would fit your needs, but you could try the spreadplayers command. Despite it's name, it is also capable of spreading mobs, with the in Minecraft 1.8 newly introduced @e selector.

/spreadplayers x z distance radius false @e[type=Creeper]

x z: The coordinates of where the mobs should go.
distance: The approximate distance the mobs should have.
radius: The radius of the area in which the mobs are spread (not a circle, but a square).
false: Just leave this at false, it is intended to respect teams when spreading players.
@e[type=Creeper]: The mob selector, the type=Creeper is very important. You can write other mobs name in this, but do not leave it out, as that would spread itemframes, signs, minecarts... And that would be a mess.

Of course this only spreads the mobs, but you have to summon them first, but i think that is no problem, just use command blocks with /summon Creeper x y z and you're good to go ;)