From 03ce6db43ec2a7a8083fd700b0e76078693d0b11 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Fri, 26 Mar 2021 10:39:24 +0100 Subject: [PATCH] Make key configurable --- README.md | 4 +++- init.lua | 11 +++++++---- settingtypes.txt | 2 ++ 3 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 settingtypes.txt diff --git a/README.md b/README.md index 98b0a8f..4ed4d07 100644 --- 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. diff --git a/init.lua b/init.lua index 49f46aa..6b9d7bd 100644 --- 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 index 0000000..3437746 --- /dev/null +++ b/settingtypes.txt @@ -0,0 +1,2 @@ +# The key that players need to press to show the playerlist +playerlist_key (Playerlist key) string sneak