HyperScript
Docs

← All scripts

Sidebar.hs

A sidebar to start a server with. Everybody sees it from the moment they join, and it is kept up to date several times a second. It shows a title that shimmers, the date, the player's rank, coins and ping, their world, how full the server is and its TPS, and your address at the bottom. Ping and TPS are green, yellow or red by how good they are, and coins are written short: 1.2k, 3.4M.

by HyperScript TeamHyperScript 1.7.50+1 command1 event handler2 timers194 linessidebarscoreboarddisplayserver template
In the script list

Put the file in plugins/HyperScript/scripts and it is live. Or type /hyperscript install sidebar on your server.

# ==============================================================
#  Sidebar.hs - a server sidebar with ranks and a moving title
# ==============================================================
#
# Requires: 1.7.50
# Author: HyperScript Team
# Tags: sidebar, scoreboard, display, server template
#
# A sidebar to start a server with. Everybody sees it from the
# moment they join, and it is kept up to date several times a
# second. It shows a title that shimmers, the date, the
# player's rank, coins and ping, their world, how full the
# server is and its TPS, and your address at the bottom. Ping
# and TPS are green, yellow or red by how good they are, and
# coins are written short: 1.2k, 3.4M.
#
# /sidebar    hide the sidebar, or show it again
#
# Notes
#  - Everything to set is in "options:" below: the name, the
#    address, the colours and signs, how often it is redrawn,
#    and which lines are shown. Put false after a "show_"
#    option to take that line out.
#  - The signs (the star, the rule down the side, the arrow) are
#    options too. If one shows as a box on your players'
#    screens, put a plain one in its place: "*", "|", ">".
#  - "refresh" is how often the lines are redrawn; 3 ticks is
#    about seven times a second. "title_speed" is how long each
#    colour of the title stays.
#  - The rank is the one Ranks.hs gives with /rank set, shown
#    the way Ranks.hs shows it: the same rank the tab list and
#    the chat prefixes show. It is kept as
#    {%player%.rank_prefix}. Without Ranks.hs everybody is
#    "no_rank" below.
#  - Coins are {%player%.coins}. Use your own variable if
#    yours is called something else, or put false after
#    "show_coins" if your server has no coins.
#  - /sidebar switches it off for the player who types it, and
#    on again. The choice is remembered.
#  - A rank given while a player is online shows on the next
#    redraw.

options:
    # What the sidebar is called and what stands at the bottom.
    name: "MY SERVER"
    address: "play.example.com"
    # How often the lines are redrawn, and how long one colour of the title stays.
    refresh: 3 ticks
    title_speed: 10 ticks
    # The colours of the title: it shimmers from the first to the second and back.
    title_dark: "&6&l"
    title_light: "&e&l"
    title_flash: "&f&l"
    # What stands on either side of the title, and in front of a heading.
    star: "✦"
    # A heading, what a line is called, what stands between that and its value, and the value.
    heading: "&6&l"
    label: "&8┃ &7"
    arrow: " &8» "
    value: "&f"
    # The line that stands above and below everything: the colour, and how long it is.
    rule: "&8&m"
    rule_length: 22
    # From what ping on it is shown yellow, and red; and below what TPS.
    ping_ok: 80
    ping_bad: 180
    tps_ok: 18
    tps_bad: 15
    # Which lines are shown. Put false to take one out.
    show_date: true
    show_rank: true
    show_coins: true
    show_ping: true
    show_online: true
    show_world: true
    show_tps: true
    show_address: true
    # What the rank line says for a player who has no rank, which is everybody without Ranks.hs.
    no_rank: "&7PLAYER"
    # What a player is told when they switch it off and on.
    hidden_message: "&7Sidebar hidden. &f/sidebar &7shows it again."
    shown_message: "&7Sidebar shown."

# The title, one step of its shimmer after the other: dark, light, a flash of white, light.
local function title():
    set {_frames} to ["{@title_dark}{@star} {@title_dark}{@name} {@title_dark}{@star}", "{@title_dark}{@star} {@title_light}{@name} {@title_dark}{@star}", "{@title_light}{@star} {@title_flash}{@name} {@title_light}{@star}", "{@title_dark}{@star} {@title_light}{@name} {@title_dark}{@star}"]
    set {_count} to size of {_frames}
    set {_frame} to ({temp.sidebar.frame} % {_count}) + 1
    return item {_frame} of {_frames}

# A line across the sidebar. Two lines of a sidebar cannot be the same, so each gets a number,
# which is written as a colour and so is not seen.
local function rule({_number}):
    set {_line} to " " repeated {@rule_length} times
    return "{@rule}%{_line}%&%{_number}%"

# Green, yellow or red for a number where a low one is good.
local function low_is_good({_n}, {_ok}, {_bad}):
    if {_n} >= {_bad}:
        return "&c"
    if {_n} >= {_ok}:
        return "&e"
    return "&a"

# The same where a high one is good.
local function high_is_good({_n}, {_ok}, {_bad}):
    if {_n} < {_bad}:
        return "&c"
    if {_n} < {_ok}:
        return "&e"
    return "&a"

# The player's rank, as Ranks.hs shows it.
local function rank():
    if {%player%.rank_prefix} is set:
        return {%player%.rank_prefix}
    return {@no_rank}

# Draws the sidebar. Lines are counted as they are written, so one that is switched off leaves
# no gap; what is left over from a longer sidebar is taken away at the end.
local function show_sidebar():
    set {_title} to title()
    set title of player's scoreboard to {_title}
    set {_n} to 0
    if {@show_date} is true:
        set {_date} to now formatted as "d MMM yyyy"
        add 1 to {_n}
        set line {_n} of player's scoreboard to "&7%{_date}%"
    add 1 to {_n}
    set line {_n} of player's scoreboard to rule(1)
    add 1 to {_n}
    set line {_n} of player's scoreboard to "{@heading}{@star} &f&l%player.name%"
    if {@show_rank} is true:
        set {_rank} to rank()
        add 1 to {_n}
        set line {_n} of player's scoreboard to "{@label}Rank{@arrow}%{_rank}%"
    if {@show_coins} is true:
        set {_coins} to short({%player%.coins} + 0)
        add 1 to {_n}
        set line {_n} of player's scoreboard to "{@label}Coins{@arrow}&e%{_coins}%"
    if {@show_ping} is true:
        set {_colour} to low_is_good(player.ping, {@ping_ok}, {@ping_bad})
        add 1 to {_n}
        set line {_n} of player's scoreboard to "{@label}Ping{@arrow}%{_colour}%%player.ping% &7ms"
    add 1 to {_n}
    set line {_n} of player's scoreboard to "&2"
    add 1 to {_n}
    set line {_n} of player's scoreboard to "{@heading}{@star} &f&lServer"
    if {@show_online} is true:
        add 1 to {_n}
        set line {_n} of player's scoreboard to "{@label}Online{@arrow}&a%server.online_players%&8/&7%server.max_players%"
    if {@show_world} is true:
        add 1 to {_n}
        set line {_n} of player's scoreboard to "{@label}World{@arrow}{@value}%player.world%"
    if {@show_tps} is true:
        set {_tps} to round(server.tps)
        set {_colour} to high_is_good({_tps}, {@tps_ok}, {@tps_bad})
        add 1 to {_n}
        set line {_n} of player's scoreboard to "{@label}TPS{@arrow}%{_colour}%%{_tps}%"
    add 1 to {_n}
    set line {_n} of player's scoreboard to rule(3)
    if {@show_address} is true:
        add 1 to {_n}
        set line {_n} of player's scoreboard to "&e{@address}"
    while {_n} < 15:
        add 1 to {_n}
        delete line {_n} of player's scoreboard

# One step of the title for everybody, so that all sidebars change together.
every {@title_speed}:
    add 1 to {temp.sidebar.frame}

# Shown to everybody who has not switched it off.
every {@refresh} for all players:
    unless {%player%.sidebar_off} is true:
        show_sidebar()

on player join:
    unless {%player%.sidebar_off} is true:
        show_sidebar()

command /sidebar:
    description: Hide or show the sidebar
    players only: true
    trigger:
        if {%player%.sidebar_off} is true:
            delete {%player%.sidebar_off}
            show_sidebar()
            send "{@shown_message}"
        else:
            set {%player%.sidebar_off} to true
            clear player's scoreboard
            send "{@hidden_message}"