]> git.lizzy.rs Git - playerlist.git/commitdiff
Make key configurable
authorElias Fleckenstein <eliasfleckenstein@web.de>
Fri, 26 Mar 2021 09:39:24 +0000 (10:39 +0100)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Fri, 26 Mar 2021 09:39:24 +0000 (10:39 +0100)
README.md
init.lua
settingtypes.txt [new file with mode: 0644]

index 98b0a8f8903389b22b9bdb4a212ee7aef95b9375..4ed4d07677a42071690d506ef13a18014365ba9f 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,3 +1,5 @@
 # playerlist
-Show a list of all online players (similar to minecrafts tab-list) when a player is sneaking.
+Show a list of all online players (similar to minecrafts tab-list) when a player is pressing the playerlist key (by default: sneak).
 Provides an API that can be used to hide or nick players, sort them and display them with different colors. (E.g. Display admins at the top of the list and make their name red). There is also a ping bar for every player (<= 20ms -> 4, <= 40ms -> 3, <= 60ms -> 2, > 60ms -> 1).
+
+The playerlist key can be configured by changing the playerlist_key setting. Possible values are up, down, left, right, jump, aux1, sneak, dig, place or zoom.
index 49f46aa1a3a05977986d4395cb6f1e2846aa6a25..6b9d7bdd6eea8035e92e824496cd2ee6527e8e05 100644 (file)
--- a/init.lua
+++ b/init.lua
@@ -2,6 +2,9 @@ playerlist = {
        huds = {}
 }
 
+local playerlist_key = minetest.settings:get("playerlist_key") or "sneak"
+print(playerlist_key)
+
 function playerlist.iterator()
        return ipairs(minetest.get_connected_players())
 end
@@ -11,7 +14,7 @@ function playerlist.count()
 end
 
 controls.register_on_press(function(user, key)
-       if key == "sneak" then
+       if key == playerlist_key and user then
                local user_name = user:get_player_name()
                local huds = {user:hud_add({
                        hud_elem_type = "image",
@@ -24,7 +27,7 @@ controls.register_on_press(function(user, key)
                })}
                for i, player, color, text in playerlist.iterator() do
                        local name = player:get_player_name()
-                       local ping = math.max(1, math.ceil(4 - minetest.get_player_information(name).avg_rtt * 50))                     
+                       local ping = math.max(1, math.ceil(4 - minetest.get_player_information(name).avg_rtt * 50))
                        table.insert(huds, user:hud_add({
                                hud_elem_type = "text",
                                position = {x = 0.5, y = 0},
@@ -49,10 +52,10 @@ controls.register_on_press(function(user, key)
 end)
 
 controls.register_on_release(function(user, key)
-       if key == "sneak" and user then
+       if key == playerlist_key and user then
                for _, id in pairs(playerlist.huds[user:get_player_name()]) do
                        user:hud_remove(id)
                end
        end
 end)
+
diff --git a/settingtypes.txt b/settingtypes.txt
new file mode 100644 (file)
index 0000000..3437746
--- /dev/null
@@ -0,0 +1,2 @@
+# The key that players need to press to show the playerlist
+playerlist_key (Playerlist key) string sneak