Make a HUD
A 5Stack HUD file is a .zip with a hud.json and one XML layout per variant. The game streamer draws it on the GPU the same way it draws the built-in 5Stack HUD, which is written in this format too. Import it under Settings → Application → Broadcast HUDs; see Broadcast HUDs.
A small HUD
hud.json:
{
"format": "5stack-hud",
"formatVersion": 1,
"name": "Minimal",
"font": "Oxanium",
"text": { "size": 18, "weight": 600, "color": "#f0f6fc" },
"colors": {
"panel": "#0c0f14db",
"CT": "#4794eb",
"T": "#f99e2f",
"red": "#ff6452"
},
"hide": ["sponsor"],
"variants": { "main": "main.xml" }
}main.xml:
<hud>
<style name="pn" bg="$panel" radius="8" clip="true"/>
<def name="card" params="p">
<col key="p.steamid" w="152" class="pn" pad="8" gap="6" opacity="{{ 1 if p.alive else 0.5 }}" transition="280ms">
<text ellipsis="true">{{ p.name }}</text>
<bar h="6" radius="3" bg="#ffffff1f" value="p.health" max="100" fill="${{ p.side }}" animate="280ms smooth"/>
<row justify="between" size="15">
<text color="#8fdca4">{{ p.money|money }}</text>
<text>{{ p.kills }}/{{ p.deaths }}</text>
</row>
</col>
</def>
<piece name="scoreboard" flow="row" x="760" y="18" w="400" h="56" class="pn" align="center" justify="between" pad-x="16">
<text color="${{ left.side }}">{{ left.name }}</text>
<text size="28">{{ left.score }} : {{ right.score }}</text>
<text color="${{ right.side }}">{{ right.name }}</text>
</piece>
<piece name="players_left" flow="row" x="24" bottom="24" gap="6">
<each in="left.players" as="p" key="p.steamid"><use def="card" p="{{ p }}"/></each>
</piece>
<piece name="players_right" flow="row" right="24" bottom="24" gap="6" reverse="true">
<each in="right.players" as="p" key="p.steamid"><use def="card" p="{{ p }}"/></each>
</piece>
<piece name="bomb" if="bomb.planted" x="810" y="90" w="300" class="pn" pad="12" gap="8"
enter="fold 240ms fold" exit="fold 200ms ease-in">
<row gap="8" align="center"><icon name="c4" h="20" color="$red"/><text>{{ t('bomb_planted') }}</text></row>
<bar h="6" fill="$red" max="1" value="bomb.left" animate="100ms linear"/>
</piece>
</hud>This HUD draws the scoreboard, the player cards and the bomb timer. It leaves out the radar, the round history, the series and the other pieces, so the streamer draws its own in their place, and it hides the sponsor, so nobody draws that.
The zip
my-hud.zip
├── hud.json
├── shared.xml styles and defs every variant reads
├── horizontal.xml one layout per variant
├── icons/flag.svg your own icons
├── img/logo.png your own pictures
└── fonts/MyFont.ttf your own fontsOnly hud.json and the layouts are needed. The files can also sit inside one top-level folder. Leave index.html out: a zip with hud.json and no index.html is checked as a HUD file whatever hud.json says, so a mistake in it is shown. Files and folders whose name starts with a dot are left out and don't count, and so are __MACOSX/, Thumbs.db and desktop.ini.
File names are UTF-8, also in a zip made on a Mac. A name in decomposed letters (é as an e and an accent) is another name than the composed one. The import says so for the files hud.json names.
| Limit | |
|---|---|
| Zip | 32 MB |
| Unpacked | 96 MB |
| Files | 300 |
| The HUD's name | 100 letters |
| Nodes written in the layouts | 2,000 per variant |
Nodes once every use and each is worked out | 4,000 per frame |
| Nesting | 64 deep as written, 200 once every use is worked out, a use inside a use 16 deep |
| Variants | 8 |
| Attributes on a node | 128 |
shared files | 16 |
hud.json and the layouts together | 1 MB |
| One expression | 1,000 characters written, 10,000 characters of result |
| Work per frame | 50,000 steps (nodes looked at, each rounds and expressions) |
Links (symlinks), absolute paths, paths with .. and paths with \ are refused. An expression that takes too long to work out is stopped.
hud.json
| Key | |
|---|---|
format | Required, "5stack-hud". |
formatVersion | Required, 1. |
name | Required. |
variants | Required. Name to layout file, such as { "horizontal": "horizontal.xml" }. The first is the default. A name is 1 to 64 letters, digits, _, . or -, and not . or ... |
canvas | { "width": 1920, "height": 1080 }, the size the layouts are written for. 1 to 8192 each, 1920 × 1080 if left out. |
font | The font family text uses unless a node says otherwise. |
fonts | Font files in the zip (.ttf or .otf) to load. Oxanium, DejaVu Sans Mono and Noto Sans (with its Arabic, Japanese, Korean and Chinese cuts) are always there. |
text | What text looks like where nothing says otherwise: size and weight (1 to 1000), line (times the size), color. Without it text is 16 px, weight 400, white. |
colors | Named colors, such as { "panel": "#0c0f14db" }. A layout uses them as $panel, or $panel/50 at half its opacity. |
shared | Files every variant reads first. They hold only <style> and <def>. |
hide | Pieces nobody draws, not this HUD and not the streamer. |
Any other key is a problem, except $schema.
Layouts
A layout is a <hud> that holds <style>, <def> and <piece> elements. Comments (<!-- -->) are fine. Text outside a <text> is a problem, since it would not be drawn.
Nodes
| Node | What it is | Its own attributes |
|---|---|---|
piece | A part of the HUD, placed on the canvas. Goes right inside <hud>. Its children stack in a column, or in a row with flow="row". Without a position it sits at the top left. | name, flow |
row | Children side by side. | |
col, box | Children one under the other. | |
each | Its children once for every item of a list. | in and as (required), index, sort, limit |
use | A def's nodes. | def (required) and the def's params |
text | Text, with {{ }} in it. | roll |
img | A picture. | src (required), fit, pos, grayscale, fallback, crop |
icon | An SVG icon in the text color. | name (required) |
bar | A meter. | value (required), max, fill, fill-to, dir, segments, seg-gap, animate, ghost, ghost-time |
radar | The radar, with players, grenades and the bomb. | dot, ct, t, watched, ink, bomb, defused, smoke, fire, grid, smooth, labels, label-weight, blast |
camera | A place the camera of the player being watched shows through. |
Every node can also have:
if: an expression; the node and everything in it are drawn only when it is true.key: an expression that keeps a node the same node from one frame to the next, so a player card keeps its place in its animation when the list around it changes. Usekey="p.steamid"on anything repeated byeach.class: styles to apply, by name (not oneachoruse).piece: the node belongs to that piece. It hides with the piece, and the HUD counts as drawing it, so a piece can live inside another one (not oneachoruse).- The style attributes below (not on
eachoruse).
each
inis a list, such asleft.players, or a number to repeat that many times (up to 1,000).asnames the item,indexnames its number, from 0.sort="kills"sorts by a field of the items,sort="-kills"the other way.limitkeeps the first so many.
img
srcis a file in the zip (img/logo.png), adata:URI, or a picture from the data, such asleft.logoorp.photo. PNG, JPEG, WebP, GIF and SVG work. The import doesn't check it: where a picture is missing, the node'sfallbackis drawn, or nothing if it has none.fit:contain(the default),coverorstretch.pos:left,right,top,bottomorcenter, such aspos="bottom".grayscale: true or false.fallback: text drawn when there is no picture, such as{{ left.name|initials }}.crop: the part of the picture to show, asleft top width heightfractions, such as0.2 0 0.6 0.5.
icon
name is icons/<name>.svg from the zip if it is there, else one of the streamer's weapon and equipment icons, named as CS2 names them: ak47, awp, m4a1_silencer, deagle, hegrenade, flashbang, smokegrenade, molotov, c4, planted_c4, defuser, armor_helmet, taser, knife and the rest. A player's weapons carry their icon name, as in p.best.icon. An icon is drawn in the node's color; a name with no icon draws a plain gun shape.
bar
valueandmax(100 unless given) are expressions; the bar fillsvalue / max.fillis a color,fill-toa second color for a gradient.dir:right(the default),left,upordown.segmentssplits it into that many blocks,seg-gappixels apart (2 unless given).animatemoves it to a new value over a time.ghostleaves a trail in that color when the value drops, which catches up overghost-time(600ms 250ms outunless given).
radar
The radar reads radar from the data by itself. dot is the player dot size (20 unless given). ct, t, watched, ink, bomb, defused, smoke, fire and grid are colors. smooth moves the dots over a time. Each dot carries the player's observer key in the ink color; labels="false" leaves the keys off, and label-weight is their font weight. blast is how a bomb going off shows: wave (the default) runs it down the map's corridors, lines adds the 2D player's blast radius to the wave, and none shows neither. On a map with no radar image, only the dots are drawn.
Styles and classes
<style name="card" bg="$panel" pad="8 10" radius="8"/>
<style name="dead" opacity="0.42"/>
<row class="card {{ 'dead' if not p.alive }}" pad-l="3">…</row>A <style> takes any of the style attributes. A node's class applies them in order, and its own attributes win over them. Text attributes (color, font, size, weight, line, upper, tabular, spacing, text-align, ellipsis) are handed down to the nodes inside, as in CSS.
Style attributes
| Group | Attributes |
|---|---|
| Place | x, y, right, bottom: any of them takes the node out of the flow, to that place in its parent. w, h, min-w, max-w, min-h, max-h. |
| Flow | grow, shrink, basis, flex (grow from nothing), gap, align and self (start, center, end, stretch, baseline), justify (start, center, end, between, around), reverse, clip. |
| Space | pad, pad-x, pad-y, pad-t, pad-r, pad-b, pad-l, and the same for margin. pad and margin take one to four values, as CSS does. |
| Look | bg, with bg-to and bg-angle (0 points up, 90 right) for a gradient. border, border-t, border-r, border-b, border-l, border-color and border-t-color and so on. radius (one to four corners). shadow (x y blur spread color). opacity, scale. hatch, hatch-width, hatch-gap for diagonal stripes. |
| Text | color, font, size, weight, line (times the size, or 24px), upper, tabular, spacing (pixels between letters), text-align (left, center, right), ellipsis. |
| Motion | enter, exit, transition, move, resize. See Motion. |
- Lengths are pixels (
24or24px), percent of the parent (50%) orauto. - Colors are
#rgb,#rgba,#rrggbb,#rrggbbaa,rgb(r,g,b),rgba(r,g,b,a),white,black,transparent, or one fromhud.jsonas$nameor$name/50. - True and false are
true,yes,1andfalse,no,0,none.
Motion
A time is written 280ms, 280ms settle (with an ease), or 600ms 250ms smooth (start 250 ms later). The eases are linear, out, in, in-out, ease, ease-in, ease-out, settle, smooth, fold and pop, or your own as bezier(x1,y1,x2,y2).
enterandexit: how a node comes and goes:fade,slide-up,slide-down,slide-left,slide-right,foldorpop, then a time. A slide can say how far (slide-up 40 180ms settle, 24 px unless given), a pop what size it starts from (pop 1.4 240ms pop, 0.6 unless given). They all fade too;fold 240ms fold, fade 180ms 140ms easegives the fade its own time.transition: opacity, fill, border, text color and scale change over this long.move: a node that moves to a new place in its parent gets there over this long.resize: a size or place set in pixels changes over this long.rollon atextrolls the digits that change, as an odometer does (roll="700ms settle", orroll="true").pulseloops for as long as a node is shown:pulse="700ms 0.5 1.12"takes its opacity to 0.5 and its size to 1.12 and back every 700 ms. The HUD draws every frame while anything pulses, so keep it for what must catch the eye.
Defs
A <def> is a part you write once and use many times. params names what it takes; <use> has to give all of them.
<def name="logo" params="src, name, size">
<img if="src" w="{{ size }}" h="{{ size }}" src="{{ src }}"/>
<col if="not src" w="{{ size }}" h="{{ size }}" radius="6" bg="#ffffff24" align="center" justify="center">
<text size="{{ (size * 0.4)|round }}" weight="700">{{ name[:1] }}</text>
</col>
</def>
<use def="logo" src="{{ left.logo }}" name="{{ left.name }}" size="{{ 30 }}"/>- An attribute that is a lone
{{ }}passes its value as it is: a player, a list, a number,{{ true }}. Anything else passes text, so writesize="{{ 30 }}", notsize="30". - Inside a def, the names are its params and the data; the
asnames of aneacharound theuseare not there, so pass them as params.
Expressions
{{ }} goes in text and in any attribute. Expressions are Jinja expressions: names and fields (left.score, colors[p.side]), numbers and text, + - * /, ~ to join text (* multiplies numbers only, so 'x' * 3 is refused), comparisons, and, or, not, x if y else z, and slices such as name[:2]. There are no statements or loops; each and if do that.
if, key, each's in and limit, and bar's value, max, segments and seg-gap, and radar's dot and label-weight are expressions already, so if="p.alive" and if="{{ p.alive }}" are the same.
The filters are these, and only these:
| Filter | Example | Gives |
|---|---|---|
money | {{ 12850|money }} | $12,850 |
clock | {{ 64.2|clock }} | 1:05 |
pad | {{ 7|pad }}, {{ 7|pad(3) }} | 07, 007 |
upper | {{ left.name|upper }} | NIGHT SHIFT |
round | {{ 12.6|round }}, {{ 12.25|round(1) }} | 13, 12.2 |
initials | {{ left.name|initials }} | NS |
Besides the data, an expression can read colors (the colors of hud.json, as #rrggbbaa text), variant (the variant being drawn), and t().
A name the data doesn't have is a problem when the HUD is imported, with the closest name it could have meant. On air, a field that is empty reads as nothing, and a value that turns out wrong, such as a color that isn't one, is skipped for that frame.
Text
Inside a <text>, runs of spaces and line breaks become one space, as in HTML. Control characters in names become spaces, and a text stops at 500 characters.
Translations
t('key'), t('key', {'count': 3}) and t('key', {}, 'shown instead') give the streamer's own words in the HUD language set under Settings → Application → Broadcast HUDs, in any of the 18 languages the web app has, with English for anything missing. {name} in a message takes {'name': …}, and a message written one | many picks its form by count. A key with no message draws the third argument. The import refuses a key no language has, unless it has a third argument. It can't check a key that is worked out, such as t('round_' ~ n): on air, one with no message and no third argument draws nothing. Text you write yourself is drawn as you wrote it.
The keys
| Key | English |
|---|---|
round_of | Round {n} of |
ot_round | OT {ot}, round |
map_of | Map {n} of |
final | Final |
pause | Pause |
timeouts_left | {count} timeout left | {count} timeouts left |
best_of | Best of |
map_n | Map |
series_tied | Series tied {a}– |
series_leads | {team} leads {a}– |
series_wins | {team} wins the series {a}– |
picked_by | Picked by |
decider_map | Decider map |
live | Live |
finished | Finished |
decider | Decider |
presented_by | Presented by |
timeout | Timeout |
left | {count} left |
technical_pause | Technical pause |
match_paused | Match paused |
halftime | Halftime |
teams_switch | Teams switch sides |
warmup | Warmup |
starts_soon | Match starts soon |
planting | {player} is planting |
bomb_planted | Bomb planted |
defusing | {player} is defusing |
defusing_kit | {player} is defusing with a kit |
in_time | In time |
too_late | Too late |
wins_round | {team} wins the round |
team_eliminated | Team eliminated |
bomb_detonated | Bomb detonated |
bomb_defused | Bomb defused |
time_ran_out | Time ran out |
round_mvp | Round MVP |
defused_bomb | Defused the bomb |
planted_bomb | Planted the bomb |
kills | {count} kill | {count} kills |
damage | {count} damage |
damage_title | Damage |
kills_title | Kills |
full_buy | Full buy |
force_buy | Force buy |
eco | Eco |
equipment | Equipment |
loss_bonus | Loss bonus |
team_money | Team money |
maps_won | Maps won |
round_history | Round history |
k, d, a, adr | K, D, A, ADR |
tournament.round_labels.round | Round |
tournament.round_labels.wb_round | WB Round |
tournament.round_labels.lb_round | LB Round |
tournament.round_labels.opening_round | Opening Round |
tournament.round_labels.wb_opening_round | WB Opening Round |
tournament.round_labels.quarter_finals | Quarter Finals |
tournament.round_labels.wb_quarter_finals | WB Quarter Finals |
tournament.round_labels.semi_finals | Semi Finals |
tournament.round_labels.wb_semi_finals | WB Semi Finals |
tournament.round_labels.final | Final |
tournament.round_labels.wb_final | WB Final |
tournament.round_labels.grand_final | Grand Final |
tournament.round_labels.lb_final | LB Final |
A tournament stage has no words of its own to write: draw it in the HUD's language, with the English name where the language has none, with
<text if="match.stage_key or match.stage">{{ t(match.stage_key, match.stage_params, match.stage) }}</text>Pieces
A piece is a part of the HUD the streamer knows by name. A layout draws a piece with <piece name="…">, or with piece="…" on any node. A <piece> with no name is only a group, placed on the canvas.
| Piece | What it is |
|---|---|
scoreboard | The teams, the score and the round clock |
players_left, players_right | The player cards of each team |
observed | The player being watched |
camera | The camera of the player being watched |
radar | The radar |
bomb | The plant and defuse timer |
rounds | The round history |
series | The maps of the series |
timeout | Timeouts, pauses, halftime and warmup |
round_end | Who won the round, and how |
freezetime | Money and buys during freezetime |
match_end | The end of a map |
clutch | A player alone against several |
sponsor | The sponsor's pictures |
mvp | The round's MVP |
A piece a variant doesn't draw is drawn by the streamer, in the first free spot. A piece named under hide in hud.json is drawn by nobody. A streamer can still hide the whole HUD from the Control Room.
The data
These are the names a HUD can read. The left and right teams are the teams on each side of the HUD; they stay put when the teams change sides, unless the operator presses Swap sides.
| Name | Fields |
|---|---|
ready | CS2 has sent its first update. |
swapped | The operator swapped the sides. |
match | The series: id, event, stage (of the tournament, in English), stage_key and stage_params (the same for t()), best_of, wins_needed, number (of the map being played), map_count, leader (left, right or empty), leader_name, leader_wins, other_wins, decided, maps |
match.maps | name, label, number, state (finished, live, upcoming), current, decider, picked_by, picked_by_name, picked_by_logo, winner, winner_name, left_score, right_score |
map | name, label, mode, phase (warmup, live, intermission, gameover), overtime |
round | number, max, phase (freezetime, live, over), since (seconds in that phase; about 1000 when the HUD did not see the phase begin), live, freezetime, over, pistol, last_of_half, frozen (nobody can move), halftime |
clock | text, seconds, phase, low (ten seconds or less), paused, shown |
left, right, ct_team, t_team | A team |
observed | The player being watched, or nothing |
bomb | state (carried, dropped, planting, planted, defusing, defused, exploded), player, player_name, planted, planting, defusing, defused, exploded, dropped, seconds, timer_known, total, left (0 to 1), low, action_seconds, action_total, action_done (0 to 1), kit, in_time |
rounds | One per round of regulation, or of the overtime being played: number, played, current, new_half, winner (left or right), side (CT or T), reason (elimination, bomb, defuse or time) |
timeout | active, team, side, name, seconds, text, remaining |
pause | active: a technical pause |
round_end | active, winner, side, name, reason, star (the round's MVP, a player), star_why (defused, planted, kills or damage) |
match_end | active (from 3 seconds after the last round, so its last kill is seen), winner, side, name, series_over, left_wins, right_wins, draw |
clutch | active, team, player, player_name, versus, star |
radar | What <radar> draws: map, image, players, grenades, bomb, and blasting while a bomb's blast plays |
camera | on, steamid |
sponsor | on, image (the one shown now), images |
team
at (left or right), side (CT or T), is_ct, is_t, name, short_name, initials, logo, score, series_wins, series (one true or false per map needed), timeouts, losses, loss_bonus, money, equip_value, buy (full, force or eco), buy_label, utility (smokes, flashes, hes, fires, decoys, total, percent), alive, health, won_round, match_point, map_point, players.
player
steamid, name, country, avatar, photo, photo_kind (roster, a cut-out that stands on the bottom edge; avatar, a square; or none), camera (their camera's picture, when it is on), initials, at, side, is_ct, is_t, key (the observer key), observed, alive, health, low, armor, helmet, kit, bomb, c4_health (the health a planted bomb would leave them if it went off now), flashed, smoked, burning, money, equip_value, round_kills, round_headshots, round_damage, kills, assists, deaths, kd, adr, mvps, score, weapon (in hand), primary, secondary, best (the primary, else the pistol), grenades, taser.
A weapon has name, label, icon, slot (primary, secondary, knife, grenade, bomb or other), active, reloading, reload (how far the reload is, 0 to 100), seated (the new magazine is in), silent (a reload slow enough to make no sound), lost (the rounds thrown away with the old magazine), has_ammo, clip, clip_max, reserve, low and count (grenades of a kind are one entry).
Checking a HUD
The import checks the whole HUD before it is saved, and lists every problem with its file, line and column, such as:
main.xml:12:9 unknown-name `p` has no `helth`, did you mean `health`?On a machine with the game streamer, 5stack-hud validate my-hud.zip (or a folder) prints the same as JSON, {ok, kind, variants, pieces, errors: [{file, line, col, code, message}]}, and exits with 1 when there is a problem. The limit on the HUD's name is the import's alone: validate doesn't know it, and the import says so in one sentence, without a file or line.
| Code | Meaning |
|---|---|
bad-zip, too-large, too-many-files, symlink, bad-path | The zip can't be read or breaks a limit. |
bad-name | A file's name isn't UTF-8, or the zip has two names for it. |
missing-file | A file named in hud.json isn't in the zip. |
bad-icon | An icon with a picture (<image>) or an entity (<!ENTITY>) in it. |
bad-json, not-a-hud, wrong-version, unknown-key, missing-name, missing-variants, bad-variant-name, bad-canvas, bad-color | Something in hud.json. |
bad-xml, bad-root | A layout isn't XML, or doesn't start with <hud>. |
unknown-element, misplaced, stray-text | A node that doesn't exist, or is in the wrong place. |
unknown-attribute, missing-attribute, bad-value | An attribute a node doesn't take, needs, or can't read. |
bad-expression, unknown-name, unknown-filter | An expression that can't be read, or reads a name or filter that doesn't exist. |
unknown-message | A t() key that no language has, with no third argument. |
unknown-class, unknown-def, unknown-piece, duplicate | A style, def or piece that doesn't exist, or two with the same name. |
too-many-variants | More than 8 variants. |
too-many-attributes | A node with more than 128 attributes. |
internal | The HUD could not be checked. The import says no more than that. |
too-many-nodes, too-deep | A layout over the node limits. |