Alpha: this compiler is under active development and updates will break your projects. Not recommended for real use yet.
Skip to content

Minigame round timer ​

A timed round: a once-a-second countdown on the action bar, warnings near the end, and everyone's kill count at the finish.

TechniqueWhere
Self-scheduling clockclock.ts: second schedules itself again while #running is 1
if / elif chainclock.ts: round over, last 5 seconds, 10-second warning
Fake-player scorespack.ts: #seconds and #running belong to no player
Criterion objectivepack.ts: points uses playerKillCount, so the game counts kills for you
ts
import { text, Color } from "helix";
import { dp, seconds, running, kills, everyone } from "./pack";
import { second } from "./clock";

dp.public("start").build((ctx) => {
  seconds.set(60);
  running.set(1);
  everyone.forEach(() => kills.set(0));
  ctx.tellraw(everyone, text("Round started - go!").color(Color.GREEN));
  ctx.call(second);
});
ts
import { Datapack, v26_3, Selector, ScoreTarget } from "helix";

export const dp = new Datapack("rounds", v26_3);

const game = dp.objective("game");
const points = dp.objective("points", "playerKillCount");

export const seconds = game.score(ScoreTarget("#seconds"));
export const running = game.score(ScoreTarget("#running"));
export const kills = points.score(Selector.self());
export const everyone = Selector.allPlayers();
ts
import { text, Color, Component, Time } from "helix";
import { dp, seconds, running, everyone } from "./pack";
import { endRound } from "./end";

// Runs once a second while a round is on.
export const second = dp.createFunction("second");
second.build((ctx) => {
  seconds.countDown();
  ctx.title().actionbar(everyone, Component([text("Time left: "), seconds]));

  ctx
    .if(seconds.equal(0), (c) => c.call(endRound))
    .elif(seconds.atMost(5), (c) => c.title().title(everyone, Component(seconds)))
    .elif(seconds.equal(10), (c) => c.tellraw(everyone, text("10 seconds left!").color(Color.YELLOW)));

  ctx.if(running.equal(1), (c) => c.schedule().functionReplace(second, Time.seconds(1)));
});
ts
import { Selector, text, Color, Component } from "helix";
import { dp, running, kills, everyone } from "./pack";

export const endRound = dp.createFunction("end").build((ctx) => {
  running.set(0);
  ctx.title().title(everyone, Component(text("Round over").color(Color.GOLD)));
  everyone.forEach((p) => {
    p.tellraw(Selector.self(), [text("You got "), kills, text(" kills")]);
  });
});

Open in playground

Compiled output - the real files helix emits for the code above:

txt
scoreboard players set #running game 0
title @a title {"text":"Round over","color":"gold"}
execute as @a at @s run tellraw @s [{"text":"You got "},{"score":{"name":"@s","objective":"points"}},{"text":" kills"}]
txt
execute if score #seconds game matches 0 run return run function rounds:zzzprivate/end
execute if score #seconds game matches ..5 run return run title @a title {"score":{"name":"#seconds","objective":"game"}}
execute if score #seconds game matches 10 run return run tellraw @a {"text":"10 seconds left!","color":"yellow"}
txt
execute if score #seconds game matches 1.. run scoreboard players remove #seconds game 1
title @a actionbar [{"text":"Time left: "},{"score":{"name":"#seconds","objective":"game"}}]
function rounds:zzzprivate/second/if_0_chain
execute if score #running game matches 1 run schedule function rounds:zzzprivate/second 1s replace
txt
scoreboard players set #seconds game 60
scoreboard players set #running game 1
execute as @a at @s run scoreboard players set @s points 0
tellraw @a {"text":"Round started - go!","color":"green"}
function rounds:zzzprivate/second
txt
{
  "pack": {
    "description": "rounds\nCreated using Helix",
    "min_format": [
      121,
      0
    ],
    "max_format": [
      121,
      0
    ]
  }
}

Try it

Run /function rounds:start.

Released under the MIT License · Credits
These docs were written with AI; the layout and every page have been reviewed by a human.