1 local playerdb = elidragon.playerdb
5 local players = playerdb.players
6 local admin = minetest.settings:get_string("name")
7 playerdb.initial_data.rank = "player"
9 function ranks.get(name)
13 local playerdata = players[name]
14 if not playerdata then
15 return name == admin and "console" or "offline"
17 return playerdata.rank
20 function ranks.get_def(name)
21 return ranks.defs[ranks.get(name)]
24 function ranks.get_player_name(name, brackets)
25 local def = ranks.get_def(name)
26 brackets = brackets or {"", ""}
27 return minetest.colorize("#" .. def.color, def.tag) .. brackets[1] .. name .. brackets[2]
30 function ranks.reload(player)
31 local name = player:get_player_name()
32 local def = ranks.get_def(name)
33 player:set_nametag_attributes({text = ranks.get_player_name(name)})
34 minetest.set_player_privs(name, assert(def.privs))
37 function ranks.set(name, rank)
39 return false, "The rank of the rpc player cannot be changed."
41 if not ranks.defs[rank] then
42 return false, "Invalid rank."
44 local player = minetest.get_player_by_name(name)
46 return false, name .. " is not online."
48 local playerdata = players[name]
49 playerdata.rank = rank
54 minetest.register_on_joinplayer(function(player)
55 minetest.chat_send_all(ranks.get_player_name(player) .. " has joined the Server.")
59 minetest.register_on_leaveplayer(function(player)
60 minetest.chat_send_all(ranks.get_player_name(player) .. " has left the Server.")
63 minetest.register_on_chat_message(function(name, message)
64 if not minetest.check_player_privs(name, {shout = true}) then
67 minetest.chat_send_all(ranks.get_player_name(name, {"<", ">"}) .. " " .. message)
71 minetest.register_chatcommand("rank", {
72 params = "<player> <rank>",
73 description = "Set a player's rank",
74 privs = {privs = true},
75 func = function(name, param)
76 local target = param:split(" ")[1] or ""
77 local rank = param:split(" ")[2] or ""
78 return ranks.set(target, rank)
82 local function get_privs_setting(setting, tbl)
83 local privs = minetest.string_to_privs(minetest.settings:get_string(setting))
85 for k, v in pairs(tbl) do
92 minetest.register_on_mods_loaded(function()
93 local all_privs = minetest.registered_privileges
94 local default_privs = get_privs_setting("default_privs")
95 local moderator_privs = get_privs_setting("moderator_privs", default_privs)
96 local vip_privs = get_privs_setting("vip_privs", default_privs)
97 local mvp_privs = get_privs_setting("mvp_privs", vip_privs)
104 description = "The Developer rank is for the admins who maintain the server software.",
110 description = "The Admin rank is for people with ssh access to the server, they have all privileges. They are members of the Elidragon group.",
116 description = "People who moderate the server.",
117 privs = moderator_privs,
120 tag = "[Contributor]",
122 description = "The Contributor rank is for people that contribute to the server software. It has the same privs as the MVP rank.",
128 description = "The Builder rank is for people that have helped constructing the buildings in the lobby etc. It has the same privs as the MVP rank.",
134 description = "The MVP rank can be purchased in out store (upcoming). It is purely cosmetic.",
140 description = "The VIP rank can be purchased in out store (upcoming). It is purely cosmetic.",
146 description = "This is the rank for normal players.",
147 privs = default_privs,
152 description = "This is an offline rank for the console.",
157 description = "This is the default offline rank.",
162 description = "This is the rank for the rpc player, which is a bot.",