2021-03-01 08:31:25 +00:00
|
|
|
playerlist = {
|
2021-03-01 08:19:38 +00:00
|
|
|
huds = {}
|
|
|
|
}
|
2020-10-06 08:21:03 +00:00
|
|
|
|
2021-03-01 08:19:38 +00:00
|
|
|
function playerlist.iterator()
|
|
|
|
return ipairs(minetest.get_connected_players())
|
|
|
|
end
|
|
|
|
|
|
|
|
function playerlist.count()
|
|
|
|
return #minetest.get_connected_players()
|
|
|
|
end
|
|
|
|
|
|
|
|
controls.register_on_press(function(user, key)
|
2020-10-06 08:21:03 +00:00
|
|
|
if key == "sneak" then
|
2021-03-01 08:19:38 +00:00
|
|
|
local user_name = user:get_player_name()
|
|
|
|
local huds = {user:hud_add({
|
|
|
|
hud_elem_type = "image",
|
|
|
|
position = {x = 0.5, y = 0},
|
|
|
|
offset = {x = 0, y = 20},
|
|
|
|
text = "playerlist_background.png",
|
|
|
|
alignment = {x = 0, y = 1},
|
|
|
|
scale = {x = 400, y = playerlist.count() * 18 + 8},
|
|
|
|
number = 0xFFFFFF,
|
|
|
|
})}
|
|
|
|
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))
|
|
|
|
table.insert(huds, user:hud_add({
|
2020-10-06 08:21:03 +00:00
|
|
|
hud_elem_type = "text",
|
|
|
|
position = {x = 0.5, y = 0},
|
2021-03-01 08:19:38 +00:00
|
|
|
offset = {x = 0, y = 23 + (i - 1) * 18},
|
|
|
|
text = text or name,
|
|
|
|
alignment = {x = 0, y = 1},
|
2020-10-06 08:21:03 +00:00
|
|
|
scale = {x = 100, y = 100},
|
2021-03-01 08:19:38 +00:00
|
|
|
number = color or 0xFFFFFF,
|
|
|
|
}))
|
|
|
|
table.insert(huds, user:hud_add({
|
2020-10-06 08:21:03 +00:00
|
|
|
hud_elem_type = "image",
|
|
|
|
position = {x = 0.5, y = 0},
|
2021-03-01 08:19:38 +00:00
|
|
|
offset = {x = -195, y = 20 + (i - 1) * 18},
|
2020-10-06 08:21:03 +00:00
|
|
|
text = "server_ping_" .. ping .. ".png",
|
2021-03-01 08:19:38 +00:00
|
|
|
alignment = {x = 1, y = 1},
|
2020-10-06 08:21:03 +00:00
|
|
|
scale = {x = 1.5, y = 1.5},
|
|
|
|
number = 0xFFFFFF,
|
2021-03-01 08:19:38 +00:00
|
|
|
}))
|
2020-10-06 08:21:03 +00:00
|
|
|
end
|
2021-03-01 08:19:38 +00:00
|
|
|
playerlist.huds[user_name] = huds
|
2020-10-06 08:21:03 +00:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2021-03-01 08:19:38 +00:00
|
|
|
controls.register_on_release(function(user, key)
|
|
|
|
if key == "sneak" and user then
|
|
|
|
for _, id in pairs(playerlist.huds[user:get_player_name()]) do
|
|
|
|
user:hud_remove(id)
|
2020-10-06 08:21:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|