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