Level Editor/Scripting/Client HUD
client.gd draws your mode. It starts with extends GamemodeClientScript and runs on every player's machine, so it can read and show but never change anything: its api, a GamemodeClientApi, has no way to write. Its hooks are on GamemodeClientScript.
What it can read
- The counters the server declared: api.get_player, api.get_team and api.get_global. The client script declares nothing; the server's counters arrive by themselves.
- api.counter_maximum: a counter's declared maximum. Read limits from here instead of copying the server's numbers, so the two scripts cannot disagree.
- Who is who: api.local_player (the player at this keyboard, or -1 when there is none yet), api.team_of and api.players.
- The teams: api.teams, api.team_name and api.team_maximum.
- api.match_state, and the payload tracks' lengths and checkpoints (see Payload tracks).
Hooks
_start(): the server's counters have arrived. Put your widgets on screen here._counter_changed(scope, key, name, value): a counter changed.scopeisapi.SCOPE_PLAYER,api.SCOPE_TEAMorapi.SCOPE_GLOBAL;keyis the player's entity id, the team, or 0 for a global counter. Widgets update by themselves, so you only need this hook for something of your own._match_ended(team): the round is decided.teamis the winner, or 0 for a draw.
Widgets
api.show_widget puts one of TeamSpec's HUD widgets on screen and returns a handle for api.remove_widget. You name the widget and hand it a Dictionary of settings; counter names can be written as plain strings. A widget opens showing the current values and keeps itself up to date, so there is nothing to call every frame. A name that is not one of the five below shows nothing.
func _start() -> void:
api.show_widget(&"team_score", {
"counter": "score",
"threshold": api.counter_maximum(api.SCOPE_TEAM, &"score"),
})
team_score
Every team's value of one team counter, side by side in team order, followed by the goal. Teams 1 and 2 have their own colors.
counter: the team counter to show.threshold: the winning number, shown after the scores. 0 hides it.warn_at: highlight a team's number once it reaches this. 0 means never.
carry_pips
A row of pips for one player counter, for the player the HUD is following: the local player, or whoever they are spectating.
counter: the player counter to show.maximum: how many pips to draw.label: optional text beside the row.
round_timer
A clock showing minutes and seconds left.
counter: a global counter holding the seconds left.warn_at: at or under this many seconds the clock takes its warning look. 0 means never.setup: optional global counter; while it is not 0 the clock shows SETUP.overtime: optional global counter; while it is not 0 the clock shows OVERTIME instead of the time.
payload_progress
A bar the cart marker rides along, with a pip per checkpoint.
counter: a global counter holding how far the cart has come, from 0 toscale.scale: that counter's value at the end of the track.checkpoints: an Array of each checkpoint's position along the bar, from 0 to 1. Divide each of api.track_checkpoints by api.track_length.pushers: optional global counter, shown while above 0.blocked: optional global counter; while it is not 0 the bar shows BLOCKED.rollback: optional global counter; while it is not 0 the bar shows ROLLING BACK.
boss_health
Two bars for a two-team boss mode: the player's own team's boss on the left, the enemy's on the right, each in its team's color, with the share it has left. A boss at 0 shows SLAIN. A player on no team sees team 1 on the left, with the teams' names on the bars.
counter: a team counter holding each team's boss's health, from 0 (dead) toscale, keyed by the team the boss belongs to.scale: that counter's value for a boss at full health.warn_at: a living boss at or under this takes the warning look. 0 means never.team_names: a Dictionary of team to name, for a player on no team. Build it from api.teams and api.team_name.
Messages
A client script cannot send messages: it only knows about the person at its own keyboard. Tell a player something from the server instead, with api.notify. See Server rules.