5 local playerlist_key = minetest.settings:get("playerlist_key")
6 if playerlist_key == "" then
7 playerlist_key = "sneak"
10 function playerlist.iterator()
11 return ipairs(minetest.get_connected_players())
14 function playerlist.count()
15 return #minetest.get_connected_players()
18 controls.register_on_press(function(user, key)
19 if key == playerlist_key and user then
20 local user_name = user:get_player_name()
21 local huds = {user:hud_add({
22 hud_elem_type = "image",
23 position = {x = 0.5, y = 0},
24 offset = {x = 0, y = 20},
25 text = "playerlist_background.png",
26 alignment = {x = 0, y = 1},
27 scale = {x = 400, y = playerlist.count() * 18 + 8},
30 for i, player, color, text in playerlist.iterator() do
31 local name = player:get_player_name()
32 local ping = math.max(1, math.ceil(4 - minetest.get_player_information(name).avg_rtt * 50))
33 table.insert(huds, user:hud_add({
34 hud_elem_type = "text",
35 position = {x = 0.5, y = 0},
36 offset = {x = 0, y = 23 + (i - 1) * 18},
38 alignment = {x = 0, y = 1},
39 scale = {x = 100, y = 100},
40 number = color or 0xFFFFFF,
42 table.insert(huds, user:hud_add({
43 hud_elem_type = "image",
44 position = {x = 0.5, y = 0},
45 offset = {x = -195, y = 20 + (i - 1) * 18},
46 text = "server_ping_" .. ping .. ".png",
47 alignment = {x = 1, y = 1},
48 scale = {x = 1.5, y = 1.5},
52 playerlist.huds[user_name] = huds
56 controls.register_on_release(function(user, key)
57 if key == playerlist_key and user then
58 for _, id in pairs(playerlist.huds[user:get_player_name()]) do