Denovo
Tutorial

Minigame: TNT Run

A complete minigame in four scripts. The floor vanishes behind you, and the last one standing wins.

TNT Run is simple: everybody stands on a floor of TNT, and every block you step on disappears a moment later. Stop moving and it goes anyway. Fall through and you are out. The last player standing wins.

You will build it from four scripts:

ScriptWhat it does
/arenaBuilds the floor, and rebuilds it for the next round
/tntrunPuts you in the game, and makes the floor vanish if you stand still
when a player movesMakes the floor vanish behind you, and notices when you fall
/leaveTakes you out of the game again

Build the arena

The floor is a 15 by 15 square of TNT high up in the air, at x 0 to 14 and height 100. It is the platform from Building bigger things again, but at a fixed place in the world instead of around the player. Create Location in makes a location from a world and three numbers:

when the command /arena is runplayerargs
set x ▾ to 0
repeat 15 times
set z ▾ to 0
repeat 15 times
set block block at Create Location in world of player x:x y:100 z:z to Tnt ▾
set z ▾ to z + 1
set x ▾ to x + 1
send player the message The arena is ready. Type /tntrun to join.

These are TNT blocks, not lit TNT, so nothing explodes. They just look the part. If something is in the way at that spot in your world, change the 100 and the other numbers in this lesson to match.

Join the game

/tntrun teleports you to the middle of the arena and switches you to adventure mode:

when the command /tntrun is runplayerargs
teleport player to Create Location in world of player x:7.5 y:101 z:7.5
set game mode of player to Adventure ▾
send player a Gold ▾ message Keep moving! The floor disappears behind you.

Adventure mode does two jobs. Players cannot break or place blocks, so nobody digs through the floor or builds a bridge. And it is how every other script knows who is playing: variables start empty for every event, so there is no list of players to look in. The game mode, stored on the player, is what remembers.

7.5 is the middle of the block at 7, the centre of a floor that runs from 0 to 14. Height 101 is the top of the floor at 100.

The floor disappears

Now the heart of the game. Every time a player in adventure mode moves, look at the block under their feet. If it is TNT, wait a moment and remove it:

when a player movesplayerfromto
if game mode of player not like Adventure ▾
return
set below ▾ to block at location of player offset by x:0 y:-1 z:0
if material of below like Tnt ▾
wait 8 ticks
set block below to Air ▾

The first if ends the script straight away for anyone not playing. Checking that first keeps the script cheap, which matters here: when a player moves runs many times a second for every player on the server.

The block is stored in below before the wait, because by the time the wait is over the player has moved on. The variable keeps its block for the rest of this run, so the right block disappears, not the one the player is on now.

Falling out

Somebody who drops below the arena is out. Add a height check to the same script, before the floor check:

when a player movesplayerfromto
if game mode of player not like Adventure ▾
return
if y of location of player smaller than 90
set game mode of player to Spectator ▾
teleport player to Create Location in world of player x:7.5 y:110 z:7.5
send player a Red ▾ message You fell! Watch the others from up here.
return
set below ▾ to block at location of player offset by x:0 y:-1 z:0
if material of below like Tnt ▾
wait 8 ticks
set block below to Air ▾

Spectator mode takes them out of the game, since they are no longer in adventure mode, and lets them fly around and watch. The teleport puts them above the arena with the best view.

No standing still

Right now a player who stands perfectly still is safe forever: no movement, no move event, no disappearing floor. Real TNT Run servers use a timer for that. Denovo has no timer event, but a repeat with a wait inside it works as one. Put it at the end of /tntrun, so every player gets their own:

when the command /tntrun is runplayerargs
teleport player to Create Location in world of player x:7.5 y:101 z:7.5
set game mode of player to Adventure ▾
send player a Gold ▾ message Keep moving! The floor disappears behind you.
repeat 300 times
wait 10 ticks
if game mode of player not like Adventure ▾
return
set below ▾ to block at location of player offset by x:0 y:-1 z:0
if material of below like Tnt ▾
set block below to Air ▾

Every half a second it removes the block under the player, wherever they are. Once they fall and turn into a spectator, the game mode check ends the timer.

Why 300 and not forever?

One run of a script has a budget of 10,000 steps, and the waits do not reset it. Each pass of this loop takes about 27 steps, so 300 passes, two and a half minutes, fit comfortably. That is plenty for a round on a 15 by 15 floor.

Leaving

Finally a way out. Slow falling makes sure the trip down to the ground does not hurt:

when the command /leave is runplayerargs
set game mode of player to Survival ▾
give player effect Slow Falling ▾ for 200 ticks at level 0
teleport player to Create Location in world of player x:7.5 y:101 z:-3.5

The whole game

Here are all four scripts together, the way they sit in one denovo:

when the command /arena is runplayerargs
set x ▾ to 0
repeat 15 times
set z ▾ to 0
repeat 15 times
set block block at Create Location in world of player x:x y:100 z:z to Tnt ▾
set z ▾ to z + 1
set x ▾ to x + 1
send player the message The arena is ready. Type /tntrun to join.
when the command /tntrun is runplayerargs
teleport player to Create Location in world of player x:7.5 y:101 z:7.5
set game mode of player to Adventure ▾
send player a Gold ▾ message Keep moving! The floor disappears behind you.
repeat 300 times
wait 10 ticks
if game mode of player not like Adventure ▾
return
set below ▾ to block at location of player offset by x:0 y:-1 z:0
if material of below like Tnt ▾
set block below to Air ▾
when a player movesplayerfromto
if game mode of player not like Adventure ▾
return
if y of location of player smaller than 90
set game mode of player to Spectator ▾
teleport player to Create Location in world of player x:7.5 y:110 z:7.5
send player a Red ▾ message You fell! Watch the others from up here.
return
set below ▾ to block at location of player offset by x:0 y:-1 z:0
if material of below like Tnt ▾
wait 8 ticks
set block below to Air ▾
when the command /leave is runplayerargs
set game mode of player to Survival ▾
give player effect Slow Falling ▾ for 200 ticks at level 0
teleport player to Create Location in world of player x:7.5 y:101 z:-3.5

Play a round

Build

One player types /arena.

Join

Everybody types /tntrun, and the running starts.

Win

Keep moving and stay on the floor. When one player is left, they have won. Type /arena for the next round, then everybody joins again with /tntrun.

What this version cannot do yet

Scripts cannot remember anything from one event to the next, and cannot look up all online players, so the game does not count who is left or announce the winner. Everyone can see it happen, though. If the flint and steel script from the TNT lesson is switched on too, anyone holding flint and steel can light the floor under the others. Whether that is a bug or a feature is up to you.

Try it yourself

  • Make the floor two layers deep, at 100 and 95, and move the fall check down to 85. Build the second layer from its own command, /arena2, so each command stays within its budget.
  • Play a sound to the player each time a block vanishes under them.
  • Give joining players a speed effect for a faster game.

On this page