HyperScript
Docs

← All scripts

ChatPrefixes.hs

Every chat message gets the player's prefix in front of it: their rank from Ranks.hs, or one you gave them yourself.

by HyperScript TeamHyperScript 1.7.35+1 command1 event handler82 lineschatprefixranksserver template
In the script list

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

# ==============================================================
#  ChatPrefixes.hs - a prefix in front of everybody's chat
# ==============================================================
#
# Requires: 1.7.35
# Author: HyperScript Team
# Tags: chat, prefix, ranks, server template
#
# Every chat message gets the player's prefix in front of it:
# their rank from Ranks.hs, or one you gave them yourself.
#
# /prefix set <player> <text>   give a player a prefix of their own
# /prefix clear <player>        back to the prefix of their rank
#
# Notes
#  - How a message looks is "format" below. %{_prefix}% is the
#    prefix, and %player.name% and %event.message% are filled
#    in for each message.
#  - A player's prefix is, in this order: one given with
#    /prefix set, the one of their rank (Ranks.hs keeps it as
#    {%player%.rank_prefix}), and "default" if there is neither.
#    Without Ranks.hs everybody has "default" until you give
#    them one.
#  - "server_tag" puts your server's name in front of every
#    message as well, for a network where chat is shared.
#  - /prefix needs the permission "prefix.admin". A prefix may
#    have colours: "&6&lKING".
#  - Use one script for how chat looks. Another that sets the
#    chat format as well would fight this one over it.

options:
    name: "MY SERVER"
    prefix: "&8[&bPrefix&8] "
    # How a chat message looks.
    format: "%{_prefix}% &f%player.name%&8: &7%event.message%"
    # The prefix of a player who has none.
    default: "&7PLAYER"
    # Put the server's name in front of every message too.
    server_tag: false

# The prefix a player has: their own, their rank's, or the default.
local function prefix_of({_who}):
    if {%{_who}%.chat_prefix} is set:
        return {%{_who}%.chat_prefix}
    if {%{_who}%.rank_prefix} is set:
        return {%{_who}%.rank_prefix}
    return "{@default}"

on player chat:
    set {_prefix} to prefix_of(player)
    if {@server_tag} is true:
        set {_prefix} to "&8[&f{@name}&8] %{_prefix}%"
    set chat format to "{@format}"

command /prefix [action] [target] [text]:
    description: Give a player a chat prefix of their own
    permission: "prefix.admin"
    usage: "&cUse /prefix set <player> <text> or /prefix clear <player>"
    tab complete:
        set arg.1 to "set", "clear"
        set arg.2 to server.players
    trigger:
        if arg.2 is not set:
            send "{@prefix}&cUse /prefix set <player> <text> or /prefix clear <player>"
            stop
        if arg.2 is not a player:
            send "{@prefix}&c%arg.2% is not online."
            stop
        if arg.1 is "set":
            if arg.3 is not set:
                send "{@prefix}&cSay what: /prefix set %arg.2% <text>"
                stop
            set {%arg.2%.chat_prefix} to arg.3
            send "{@prefix}&f%arg.2% &7now has the prefix %arg.3%&7."
            stop
        if arg.1 is "clear":
            delete {%arg.2%.chat_prefix}
            set {_now} to prefix_of(arg.2)
            send "{@prefix}&f%arg.2% &7has the prefix %{_now}% &7again."
            stop
        send "{@prefix}&cUse /prefix set <player> <text> or /prefix clear <player>"