The Toolbox search is your friend! Use it to look up blocks or events you are not sure about.

In this activity, you will recreate the experience of being overrun by hordes of zombies. You will also see the effect of exponential growth: every time you kill one zombie, many more will be created to take its place. What does that feel like? Let’s find out!
The event handler that you will be using is ||mobs:on monster killed|| to trigger new zombies to spawn when one is killed.
||mobs:Mobs|| Toolbox drawer, drag a ||mobs:on killed|| block into the coding Workspace.mobs.onMobKilled(CHICKEN, function () {
})
From the ||mobs:MOBS|| Toolbox drawer, drag a ||mobs:monster|| drop-down block out to replace the default, animal.
Using the drop-down menu in the ||mobs:monster|| block, select the zombie spawn egg.

Now let’s set up the game so that when a zombie is killed, two new ones will spawn at a random location near your player.
||mobs:Mobs|| Toolbox drawer, drag a ||mobs:spawn animal|| block under the ||mobs:on killed|| event handler block.mobs.onMobKilled(mobs.monster(ZOMBIE), function () {
mobs.spawn(CHICKEN, pos(0, 0, 0))
})
animal setting with zombie in the ||mobs:spawn|| block.mobs.onMobKilled(mobs.monster(ZOMBIE), function () {
mobs.spawn(mobs.monster(ZOMBIE), pos(0, 0, 0))
})
You want to spawn two zombies for every one you kill, so from the ||loops:Loops|| Toolbox drawer, drag a ||loops:repeat|| loop onto the work area. This ||loops:repeat|| loop should be inside the ||mobs:on killed|| event, and your ||mobs:spawn|| block should be inside the ||loops:repeat|| loop.
In the ||loops:repeat|| loop, enter the number 2.
mobs.onMobKilled(mobs.monster(ZOMBIE), function () {
for (let i = 0; i < 2; i++) {
mobs.spawn(mobs.monster(ZOMBIE), pos(0, 0, 0))
}
})
Now you need to tell Minecraft where to spawn the zombies. Notice that, by default, the relative coordinates are set to your player’s current location (~0 ~0 ~0). Relative coordinates are covered in more detail in Lesson 3. If you use (~0 ~0 ~0), you will spawn two zombies right on top of your character. This isn’t a great idea, so let’s make the new zombies show up just a little farther away, at random locations.
(~0 ~0 ~0) with a ||positions:pick random position|| block.The two sets of coordinates in the ||positions:pick random position|| block describe opposite corners of a box within which zombies will spawn at random locations. Let’s choose a box 10 blocks around your player, which should create an area of 441 square blocks centered on your location.
||positions:pick random position|| block, enter the from coordinates as (~10 ~0 ~10) and the to coordinates as (~-10 ~0 ~-10).mobs.onMobKilled(mobs.monster(ZOMBIE), function () {
for (let i = 0; i < 2; i++) {
mobs.spawn(mobs.monster(ZOMBIE), randpos(
pos(10, 0, 10),
pos(-10, 0, -10)
))
}
})
Shared Program: https://makecode.com/_VseXqc2Vjbv9
When you are playing with zombies, everything has to be just right. Zombies are kind of grumpy at times.
Open a Minecraft world suitable for meeting a zombie in. Before testing your code, it is important that you get a few settings correct. You can do this by using terminal commands after you are in a world.
You will set the gamemode to Creative and the difficulty to Easy, and you will use your fists for this first experiment.
While in a world, open the terminal (chat window) by pressing the T key.
Set the gamemode to Creative by entering the following command in the chat window and pressing Enter:
/gamemode c
/difficulty easy
Next you need to equip the spawn zombie egg. Press E to open your inventory. You can search for this!

Throw out an egg and create a zombie. In Creative mode, the zombie will not attack you, but zombies like rough play, so go ahead and chase your zombie. Hit the zombie until it dies. You should see new zombies spawning after each zombie is killed. That is your code working!!! Test it out further…
Now you can change some things to make your own different and unique situations!
Use the existing ||mobs:on killed|| event, but change a few things. How would you spawn five cave spiders every time a cave spider is killed?
Now you’ll change the monster back to zombie and set your code to spawn five zombies every time a zombie is killed.
Ok, all this is good, but it’s not exactly like the zombie or monster movies. These entities (zombies and cave spiders) are acting too friendly and do not do anything when you hit them. This is because you are in Creative mode. You can use the ||loops:on start|| event to trigger a more zombie-like mood!
To do this, you need to add the ||loops:on start|| event and change the mode to Survival. Can you find these blocks in the Toolbox drawer and set this up?
The code should change the mode to Survival on start. Then, if there are any zombies, you will notice that they will chase you.
You want your assault on the zombie horde to begin the same way each time. It would be nice to be able to start the zombies whenever you want without having to equip spawn zombie eggs. Also, too many older zombies from your previous plays might still be hanging around, so you need to eliminate them to clear the world. You want to have a fresh start if your player dies. Finally, what about giving your character something to protect themselves with?
To do these things, let’s use a new event, ||player:on died||, and add a ||player:on chat|| event as well.
First, clear out all the old zombies in the ||player:on died|| event.
Can you add a block to the ||player:on killed|| event to make this happen?
Next, let’s spawn one zombie when you enter the command Z in a ||player:on chat|| event. You also want to give yourself an iron sword at this time so your character can protect themselves.
Add a ||player:on chat|| event.
Spawn one zombie.
Here there are no rules… Copy the code for the experiments and change things around to see what kind of results you can create. Suggestions are given, but do as you like!
What if your player inventory already had a weapon - ideally a ranged weapon like a bow - at the beginning of the game? You will need some arrows as well. Try other weapons or items! Arm yourself with blocks and try to build a wall to stop the zombies.
Use this code to start with.
Now that you have played around with some events, you might add even more to them to create the perfect zombie movie setting. You could change things like the time of day or the weather, spawn more monsters, or do other things to start the game with a real rush. Maybe you could equip your player with a weapon like a bow and arrow so they have a better chance at surviving! Give some of these ideas a try to set up your zombie apocalypse!

Use this code to start with.