form can be resized, works with 44 players

master
bosapara 2019-09-22 19:50:32 +04:00
parent 51bbe9f2d4
commit 26a1da899f
1 changed files with 35 additions and 15 deletions

View File

@ -1,23 +1,40 @@
minetest.register_chatcommand('online', {
description = 'Show online players',
privs = {},
privs = {interact = true},
params = "",
func = function(name, param)
local y = 0;
local players_total = #minetest.get_connected_players()
local p = {};
--12 23 34
local f_size = 5
if players_total >= 12 and players_total <= 22 then
f_size = 10
elseif players_total >= 23 and players_total <= 33 then
f_size = 15
elseif players_total >= 34 then
f_size = 20
end
local fs = "size ["..f_size..",9] bgcolor[#080808BB;true] background[0,0;8,8;gui_formbg.png;true] label[0.3,0.1;"..minetest.colorize("#dddddd", "Online Players: "..players_total.." / "..minetest.setting_get("max_users")).."]"
local count = 0
local fsx = 0
local fsy = 0.7
for k,v in pairs(minetest.get_connected_players()) do
local name = v:get_player_name()
local name = v:get_player_name()
local head = "[combine:8x8:-8,-8=character.png"
local ping_texture = "[combine:10x8:0,-32=ping_pics.png"
local ping = math.floor((minetest.get_player_information(name).avg_rtt / 2) * 1000)
if minetest.get_modpath("simple_skins") then
head = "[combine:8x8:-8,-8="..skins.skins[name]..".png"
end
end
if ping >= 0 and ping <= 100 then
ping_texture = "[combine:10x8:0,0=ping_pics.png"
@ -31,18 +48,21 @@ minetest.register_chatcommand('online', {
ping_texture = "[combine:10x8:0,-32=ping_pics.png"
end
y = y + 0.7;
count = count + 1
fs = fs .. "image["..(fsx+0.3)..","..fsy..";0.7,0.7;".. head .. "] image["..(fsx+4)..","..(fsy+0.025)..";0.454,0.568;".. ping_texture .. "] box["..(fsx+0.3)..","..fsy..";4.2,0.6;black] label["..(fsx+1.2)..","..(0.05+fsy)..";"..minetest.colorize("white", name).."]"
fsy = fsy + 0.75
p[#p+1] = "image[0.3,"..y..";0.7,0.7;".. head .. "] image[4,"..(y+0.025)..";0.454,0.568;".. ping_texture .. "] box[0.3,"..y..";4.2,0.6;black] label[1.2,"..(0.05+y)..";"..minetest.colorize("white", name).."]"
if count == 11 or count == 22 or count == 33 then
-- start next row
fsx = fsx + 5
fsy = 0.7
end
end
local text = table.concat(p,"\n")
local form = "size [5,9] label[0.3,0.1;"..minetest.colorize("#dddddd", "Online Players: "..players_total.." / "..minetest.setting_get("max_users")).."]"
form = form .. text
minetest.show_formspec(name, "robot_msg", form);
minetest.show_formspec(name, "robot_msg", fs);
end,
})
})