Make key configurable

This commit is contained in:
Elias Fleckenstein 2021-03-26 10:39:24 +01:00
parent a84a62544f
commit 03ce6db43e
3 changed files with 12 additions and 5 deletions

@ -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.

@ -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)

2
settingtypes.txt Normal file

@ -0,0 +1,2 @@
# The key that players need to press to show the playerlist
playerlist_key (Playerlist key) string sneak