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:
| Script | What it does |
|---|---|
/arena | Builds the floor, and rebuilds it for the next round |
/tntrun | Puts you in the game, and makes the floor vanish if you stand still |
| when a player moves | Makes the floor vanish behind you, and notices when you fall |
/leave | Takes 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:
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:
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:
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:
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:
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:
The whole game
Here are all four scripts together, the way they sit in one denovo:
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.