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