HyperScript
Docs

← All scripts

Ranks.hs

Ranks without a permissions plugin. A rank is a name, how it is shown, and a permission that goes with it, so the sidebar, the tab list and the chat prefixes all know who is what.

by HyperScript TeamHyperScript 1.7.35+1 command1 event handler134 linesrankspermissionsadminserver template
In the script list

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

# ==============================================================
#  Ranks.hs - ranks you give with /rank
# ==============================================================
#
# Requires: 1.7.35
# Author: HyperScript Team
# Tags: ranks, permissions, admin, server template
#
# Ranks without a permissions plugin. A rank is a name, how it
# is shown, and a permission that goes with it, so the sidebar,
# the tab list and the chat prefixes all know who is what.
#
# /rank                       your own rank
# /rank list                  the ranks there are
# /rank info <player>         somebody's rank
# /rank set <player> <rank>   give a rank
# /rank remove <player>       back to the lowest rank
#
# Notes
#  - The ranks are in ranks() below, from the lowest to the
#    highest, and how each is shown is in shown(). Add one in
#    both places; the first in ranks() is what a new player is.
#  - A player with the rank "vip" gets the permission
#    "rank.vip", and loses the one of the rank they had. Give
#    your other plugins and scripts that permission to check.
#  - How a rank is shown is kept as {%player%.rank_prefix},
#    which ChatPrefixes.hs puts in front of chat messages.
#  - Giving and taking ranks needs the permission "ranks.admin".
#  - Tab offers what comes next: the actions, then the players
#    who are online, then the ranks.
#  - The player has to be online to be given a rank.
#  - With a permissions plugin such as LuckPerms, use that for
#    ranks instead: it does far more than this.

options:
    name: "MY SERVER"
    prefix: "&8[&6Ranks&8] "
    # Tell everybody when somebody is given a rank.
    announce: true

# The ranks, from the lowest to the highest.
local function ranks():
    return ["player", "vip", "mod", "admin", "owner"]

# How a rank is shown in chat and in lists.
local function shown({_rank}):
    if {_rank} is "owner":
        return "&4&lOWNER"
    if {_rank} is "admin":
        return "&c&lADMIN"
    if {_rank} is "mod":
        return "&9&lMOD"
    if {_rank} is "vip":
        return "&6&lVIP"
    return "&7PLAYER"

# Gives a player a rank: what is kept about it, and the permission that goes with it.
local function give_rank({_who}, {_rank}):
    for each {_other} in ranks():
        permission {_who} remove "rank.%{_other}%"
    set {%{_who}%.rank} to {_rank}
    set {%{_who}%.rank_prefix} to shown({_rank})
    permission {_who} add "rank.%{_rank}%"

on player join:
    # A new player is the lowest rank, and everybody's rank is put in place again.
    set {_lowest} to item 1 of ranks()
    if {%player%.rank} is not set:
        set {%player%.rank} to {_lowest}
    set {%player%.rank_prefix} to shown({%player%.rank})

command /rank [action] [target] [rank]:
    description: See and give ranks
    usage: "&cUse /rank, /rank list, /rank info <player>, /rank set <player> <rank> or /rank remove <player>"
    # What Tab offers: the actions, then a player for those that take one, then the ranks for "set".
    tab complete:
        set arg.1 to "list", "info", "set", "remove"
        if arg.1 is "info" or arg.1 is "set" or arg.1 is "remove":
            set arg.2 to server.players
        if arg.1 is "set":
            set arg.3 to ranks()
    trigger:
        set {_lowest} to item 1 of ranks()
        if arg.1 is not set:
            if player is not set:
                send "{@prefix}&cSay whose: /rank info <player>"
                stop
            set {_mine} to shown({%player%.rank})
            send "{@prefix}&7Your rank on &f{@name}&7 is %{_mine}%&7."
            stop
        if arg.1 is "list":
            send "{@prefix}&7The ranks of &f{@name}&7, lowest first:"
            for each {_rank} in ranks():
                set {_looks} to shown({_rank})
                send " &8- &f%{_rank}% &8(%{_looks}%&8)"
            stop
        if arg.1 is "info":
            if arg.2 is not set:
                send "{@prefix}&cSay whose: /rank info <player>"
                stop
            if arg.2 is not a player:
                send "{@prefix}&c%arg.2% is not online."
                stop
            set {_theirs} to shown({%arg.2%.rank})
            send "{@prefix}&f%arg.2% &7is %{_theirs}%&7."
            stop
        if arg.1 is "set" or arg.1 is "remove":
            if player is set:
                if player does not have permission "ranks.admin":
                    send "{@prefix}&cYou may not change ranks."
                    stop
            if arg.2 is not set:
                send "{@prefix}&cSay whom: /rank %arg.1% <player>"
                stop
            if arg.2 is not a player:
                send "{@prefix}&c%arg.2% is not online."
                stop
            set {_new} to {_lowest}
            if arg.1 is "set":
                if arg.3 is not set:
                    send "{@prefix}&cSay which rank: /rank set %arg.2% <rank>. &7/rank list shows them."
                    stop
                if not (ranks() contains arg.3):
                    send "{@prefix}&cThere is no rank called %arg.3%. &7/rank list shows the ones there are."
                    stop
                set {_new} to lowercase arg.3
            give_rank(arg.2, {_new})
            set {_looks} to shown({_new})
            send "{@prefix}&f%arg.2% &7is now %{_looks}%&7."
            if {@announce} is true:
                broadcast "{@prefix}&f%arg.2% &7is now %{_looks}%&7!"
            stop
        send "{@prefix}&cUse /rank, /rank list, /rank info <player>, /rank set <player> <rank> or /rank remove <player>"