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