]> git.lizzy.rs Git - elidragon_v2.git/commitdiff
Add playerlist
authorElias Fleckenstein <eliasfleckenstein@web.de>
Sun, 28 Feb 2021 17:43:31 +0000 (18:43 +0100)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Sun, 28 Feb 2021 17:43:31 +0000 (18:43 +0100)
mods/elidragon_playerlist/init.lua [new file with mode: 0644]
mods/elidragon_playerlist/mod.conf [new file with mode: 0644]
mods/elidragon_ranks/init.lua
worlds/creative/world.mt
worlds/lobby/world.mt
worlds/skyblock/world.mt
worlds/survival/world.mt

diff --git a/mods/elidragon_playerlist/init.lua b/mods/elidragon_playerlist/init.lua
new file mode 100644 (file)
index 0000000..2d55ebd
--- /dev/null
@@ -0,0 +1,41 @@
+local ranks = elidragon.ranks
+
+local player_huds = {}
+
+controls.register_on_press(function(player, key)
+       if key == "sneak" then
+               local name = player:get_player_name()
+               local huds = {}
+               for i, n, _, rank, rank_def in ranks.iterate_players() do
+                       table.insert(huds, player:hud_add({
+                               hud_elem_type = "text",
+                               position = {x = 0.5, y = 0},
+                               offset = {x = 20, y = 53 + (i - 1) * 18},
+                               text = n,
+                               alignment = {x = 1, y = 1},
+                               scale = {x = 100, y = 100},
+                               number = tonumber(rank_def.color, 16),
+                       }))
+                       table.insert(huds, player:hud_add({
+                               hud_elem_type = "image",
+                               position = {x = 0.5, y = 0},
+                               offset = {x = 0, y = 50 + (i - 1) * 18},
+                               text = "server_ping_" .. math.max(1, math.ceil(4 - minetest.get_player_information(n).avg_rtt * 4)) .. ".png",
+                               alignment = {x = -1, y = 1},
+                               scale = {x = 1.5, y = 1.5},
+                               number = 0xFFFFFF,
+                       }))
+               end
+               player_huds[name] = huds
+       end
+end)
+
+controls.register_on_release(function(player, key)
+       if key == "sneak" and player then
+               for _, id in ipairs(player_huds[player:get_player_name()] or {}) do
+                       player:hud_remove(id)
+               end
+       end
+end)
+
+elidragon.playerlist = {}
diff --git a/mods/elidragon_playerlist/mod.conf b/mods/elidragon_playerlist/mod.conf
new file mode 100644 (file)
index 0000000..5bf4473
--- /dev/null
@@ -0,0 +1,4 @@
+name = elidragon_playerlist
+author = Fleckenstein
+description = Show a playerlist similar to minecraft when the sneak key is pressed, people with the highest ranks are shown first
+depends = elidragon, elidragon_ranks, controls
index a5831bdae3542ea8723457b2fbe0ea228cd9eaad..8a97da3eaecce86a925d2618be13d2f5c7886abe 100644 (file)
@@ -23,16 +23,16 @@ function ranks.get(name)
 end
 
 function ranks.get_player_name(name, brackets)
-       local _, def = ranks.get(name)
+       local _, rank_def = ranks.get(name)
        brackets = brackets or {"", ""}
-       return minetest.colorize("#" .. def.color, def.tag) .. brackets[1] .. name .. brackets[2]
+       return minetest.colorize("#" .. rank_def.color, rank_def.tag) .. brackets[1] .. name .. brackets[2]
 end
 
 function ranks.reload(player)
        local name = player:get_player_name()
-       local rank, def = ranks.get(name)
+       local rank, rank_def = ranks.get(name)
        player:set_nametag_attributes({text = rank == "system" and "" or ranks.get_player_name(name)})
-       minetest.set_player_privs(name, assert(def.privs))
+       minetest.set_player_privs(name, assert(rank_def.privs))
 end
 
 function ranks.set(name, rank)
@@ -53,6 +53,34 @@ function ranks.set(name, rank)
        ranks.reload(player)
 end
 
+function ranks.iterate_players(list)
+       local players = {}
+       for _, player in ipairs(list or minetest.get_connected_players()) do
+               local name = player:get_player_name()
+               if name ~= "rpc" then
+                       local rank, rank_def = ranks.get(name)
+                       table.insert(players, {
+                               name = name,
+                               ref = player,
+                               rank = rank,
+                               rank_def = rank_def,
+                               value = rank_def.value
+                       })
+               end
+       end
+       table.sort(players, function(a, b)
+               return a.value > b.value
+       end)
+       local i = 0
+       return function()
+               i = i + 1
+               local player = players[i]
+               if player then
+                       return i, player.name, player.ref, player.rank, player.rank_def
+               end
+       end
+end
+
 minetest.register_on_joinplayer(ranks.reload)
 
 function minetest.send_join_message(name)
@@ -110,48 +138,56 @@ minetest.register_on_mods_loaded(function()
                        color = "900A00",
                        description = "The Developer rank is for the admins who maintain the server software.",
                        privs = all_privs,
+                       value = 7,
                },
                admin = {
                        tag = "[Admin]",
                        color = "FF2D8D",
                        description = "The Admin rank is for people with ssh access to the server, they have all privileges. They are members of the Elidragon group.",
                        privs = all_privs,
+                       value = 6,
                },
                moderator = {
                        tag = "[Moderator]",
                        color = "006BFF",
                        description = "People who moderate the server.",
                        privs = moderator_privs,
+                       value = 5,
                },
                contributor = {
                        tag = "[Contributor]",
                        color = "9D00FF",
                        description = "The Contributor rank is for people that contribute to the server software. It has the same privs as the MVP rank.",
                        privs = mvp_privs,
+                       value = 4,
                },
                builder = {
                        tag = "[Builder]",
                        color = "FF9C00",
                        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.",
                        privs = mvp_privs,
+                       value = 3,
                },
                mvp = {
                        tag = "[MVP]",
                        color = "0CDCD8",
                        description = "The MVP rank can be purchased in out store (upcoming). It is purely cosmetic.",
                        privs = mvp_privs,
+                       value = 2,
                },
                vip = {
                        tag = "[VIP]",
                        color = "2BEC37",
                        description = "The VIP rank can be purchased in out store (upcoming). It is purely cosmetic.",
                        privs = vip_privs,
+                       value = 1,
                },
                player = {
                        tag = "",
                        color = "FFFFFF",
                        description = "This is the rank for normal players.",
                        privs = default_privs,
+                       value = 0,
                },
                console = {
                        tag = "[Console]",
@@ -174,3 +210,5 @@ minetest.register_on_mods_loaded(function()
                },
        }
 end)
+
+elidragon.ranks = ranks
index 791ebf65232b9286a08146645bbca070947bccd4..80b5d260b212b14fbf1206f7a78246b42855befd 100644 (file)
@@ -12,6 +12,7 @@ load_mod_elidragon_db = true
 load_mod_elidragon_grouplist = false
 load_mod_elidragon_luckyblock = false
 load_mod_elidragon_playerdb = true
+load_mod_elidragon_playerlist = true
 load_mod_elidragon_plot = true
 load_mod_elidragon_plotmg = true
 load_mod_elidragon_random = false
index 957910e4a38abf5943daf092126fe6896a1ff596..7c013426d1e408178d6359c68fa8508752785a02 100644 (file)
@@ -12,6 +12,7 @@ load_mod_elidragon_db = true
 load_mod_elidragon_grouplist = false
 load_mod_elidragon_luckyblock = false
 load_mod_elidragon_playerdb = true
+load_mod_elidragon_playerlist = true
 load_mod_elidragon_plot = false
 load_mod_elidragon_plotmg = false
 load_mod_elidragon_random = false
index 1677631704ed1372a5fde0e748aec2da6ec99365..a45260f9961a4eae79359f235c7ef75db168d949 100644 (file)
@@ -12,6 +12,7 @@ load_mod_elidragon_db = true
 load_mod_elidragon_grouplist = true
 load_mod_elidragon_luckyblock = true
 load_mod_elidragon_playerdb = true
+load_mod_elidragon_playerlist = true
 load_mod_elidragon_plot = true
 load_mod_elidragon_plotmg = true
 load_mod_elidragon_random = false
index 24efdc28681e04c5beaf93263703016732b3033f..4ee9e643e5ff909d94d0fc355875005898347f5d 100644 (file)
@@ -12,6 +12,7 @@ load_mod_elidragon_db = true
 load_mod_elidragon_grouplist = false
 load_mod_elidragon_luckyblock = false
 load_mod_elidragon_playerdb = true
+load_mod_elidragon_playerlist = true
 load_mod_elidragon_plot = false
 load_mod_elidragon_plotmg = false
 load_mod_elidragon_random = false