SetScoreboardColumns
Adds columns to the scoreboard - kills, score, a rank - whose cells are the players’ state values.
columns is a list of tables, at most 8, each a column:
| key | what it is |
|---|---|
key |
the player state key whose value the column shows in each player’s row (1 to 48 characters) - required; two columns cannot show the same key |
label |
the heading, 32 characters at most |
width |
the column’s width on a screen 1080 pixels tall, 0 to 2000; 0 or left out lets the board decide |
align |
"left" (the default), "center" or "right" |
format |
how a cell reads its value: "" (as it is, the default), "number", "time" or "percent" |
color |
0xRRGGBBAA for the cells; left out is the board’s own colour |
visible |
"all" (the default) or "admin": who is sent the column |
The cells are the values the mode keeps with SetPlayerState under each key: change the state and the cell changes.
What "admin" hides is the column, never the data: every player’s game already holds every player’s state, so an
admin-only column is drawn for admins alone but its values are in every game’s copy of the state - keep nothing secret
there.
Without a player the columns are the ones everyone sees, and whoever joins later; they replace any list made for a
single player. With a player that list is theirs alone and replaces the shared one for them. nil takes the columns
back: for everyone it leaves the scoreboard with none, for a player it returns them to the shared ones. Each player’s
game is sent the columns they may see when they join, when the columns change and when their admin flag does
(SetPlayerAdmin); a reload of the mode empties them: set them in OnGameModeInit.
KCD:MP’s own scoreboard keeps its three columns - the number, the name and the ping; the columns set here are drawn by a scoreboard built as a web page.
The answer is true, or false and the reason, which names the column: "too many columns (8 at most)", "column 2: the key is a player state key (1-48 characters)", "column 2: two columns show the key 'kills'", "column 2: the label is over 32 characters", "column 2: the width is 0-2000", "column 2: align is left, center or right", "column 2: format is empty, number, time or percent", "column 2: visible is all or admin" or "no such player". A call with any
bad column changes nothing.
Syntax
Section titled “Syntax”SetScoreboardColumns(columns [, pid])| Parameter | Type | |
|---|---|---|
columns |
table | nil | a list of { key, label, width, align, format, color, visible } - at most 8; nil takes the columns back |
pid |
number | nil | the player whose own list this is; nil for everyone (optional) |
Returns
Section titled “Returns”true, or false, reason - the reason as a person reads it
Example
Section titled “Example”function OnGameModeInit() SetScoreboardColumns({ { key = "kills", label = "Kills", width = 90, align = "right", format = "number" }, { key = "score", label = "Score", width = 110, align = "right", format = "number" }, { key = "rank", label = "Rank", visible = "admin" }, -- only the admins are sent this one })end
local kills = {}
function OnPlayerDeath(pid, attacker) if attacker >= 0 then kills[attacker] = (kills[attacker] or 0) + 1 SetPlayerState(attacker, "kills", kills[attacker]) -- the column's cell follows the state endendSee also
Section titled “See also”SetPlayerState · SetPlayerAdmin · SetPlayerInterfaceOptions · the Interface group of the index
