]> git.lizzy.rs Git - playerlist.git/blob - init.lua
Initial Commit
[playerlist.git] / init.lua
1 local playerlist = {}
2
3 controls.register_on_press(function(player, key)
4         if key == "sneak" then
5                 local name = player:get_player_name()
6                 local list = {}
7                 local players = minetest.get_connected_players()
8                 for i, p in pairs(players) do
9                         local n = p:get_player_name()
10                         local ping = math.max(1, math.ceil(4 - minetest.get_player_information(n).avg_rtt * 4))
11                         list[#list + 1] = player:hud_add({
12                                 hud_elem_type = "text",
13                                 position = {x = 0.5, y = 0},
14                                 offset = {x = 20, y = 53 + (i - 1) * 18},
15                                 text = n,
16                                 alignment = {x = 1, y = 1},
17                                 scale = {x = 100, y = 100},
18                                 number = 0xFFFFFF,
19                         })
20                         list[#list + 1] = player:hud_add({
21                                 hud_elem_type = "image",
22                                 position = {x = 0.5, y = 0},
23                                 offset = {x = 0, y = 50 + (i - 1) * 18},
24                                 text = "server_ping_" .. ping .. ".png",
25                                 alignment = {x = -1, y = 1},
26                                 scale = {x = 1.5, y = 1.5},
27                                 number = 0xFFFFFF,
28                         })
29                 end
30                 playerlist[name] = list
31         end
32 end)
33
34 controls.register_on_release(function(player, key)
35         if key == "sneak" and player then
36                 for _, id in pairs(playerlist[player:get_player_name()]) do
37                         player:hud_remove(id)
38                 end
39         end
40 end)
41