Add playerlist dependency
This commit is contained in:
parent
81dc3a7f82
commit
6b4b806aeb
2
mod.conf
2
mod.conf
@ -1,5 +1,5 @@
|
||||
name = elidragon
|
||||
description = The plugins for the Elidragon Server
|
||||
author = Fleckenstein
|
||||
depends = worldedit, moreores, default, flowers, areas, technic, moretrees, controls, bucket, quests
|
||||
depends = worldedit, moreores, default, flowers, areas, technic, moretrees, controls, bucket, quests, playerlist
|
||||
optional_depends = irc
|
||||
|
@ -1,39 +1,22 @@
|
||||
elidragon.playerlist = {}
|
||||
controls.register_on_press(function(player, key)
|
||||
if key == "sneak" then
|
||||
local name = player:get_player_name()
|
||||
local list = {}
|
||||
local players = minetest.get_connected_players()
|
||||
for i, p in pairs(players) do
|
||||
local n = p:get_player_name()
|
||||
local ping = math.max(1, math.ceil(4 - minetest.get_player_information(n).avg_rtt * 4))
|
||||
list[#list + 1] = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
position = {x = 0.5, y = 0},
|
||||
offset = {x = 20, y = 53 + (i - 1) * 18},
|
||||
text = n,
|
||||
alignment = {x = 1, y = 1},
|
||||
scale = {x = 100, y = 100},
|
||||
number = tonumber(elidragon.get_rank(p).color:gsub("#", ""), 16),
|
||||
})
|
||||
list[#list + 1] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0.5, y = 0},
|
||||
offset = {x = 0, y = 50 + (i - 1) * 18},
|
||||
text = "server_ping_" .. ping .. ".png",
|
||||
alignment = {x = -1, y = 1},
|
||||
scale = {x = 1.5, y = 1.5},
|
||||
number = 0xFFFFFF,
|
||||
})
|
||||
end
|
||||
elidragon.playerlist[name] = list
|
||||
function playerlist.iterator()
|
||||
local list = {}
|
||||
for _, player in ipairs(minetest.get_connected_players()) do
|
||||
local rank, i = elidragon.get_rank(player)
|
||||
table.insert(list, {
|
||||
player = player,
|
||||
value = i,
|
||||
color = tonumber(rank.color:gsub("#", ""), 16)
|
||||
})
|
||||
end
|
||||
end)
|
||||
|
||||
controls.register_on_release(function(player, key)
|
||||
if key == "sneak" and player then
|
||||
for _, id in pairs(elidragon.playerlist[player:get_player_name()]) do
|
||||
player:hud_remove(id)
|
||||
table.sort(list, function(a, b)
|
||||
return a.value > b.value
|
||||
end)
|
||||
local i = 0
|
||||
return function()
|
||||
i = i + 1
|
||||
local elem = list[i]
|
||||
if elem then
|
||||
return i, elem.player, elem.color
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user