From 149ab033b0ebb033c4899a37a8b1b777715dfad7 Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Tue, 29 Jan 2019 11:47:31 +0530 Subject: [PATCH] Add player count --- chat_mod/init.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/chat_mod/init.lua b/chat_mod/init.lua index 2604750..1e2bdb0 100644 --- a/chat_mod/init.lua +++ b/chat_mod/init.lua @@ -1,10 +1,18 @@ local http_api = minetest.request_http_api() +function tablelength(T) + local count = 0 + for _ in pairs(T) do count = count + 1 end + return count +end + function send_messages(res) for message in string.gmatch(res["data"], "[^\n]+") do if message == "list" then local x = minetest.get_connected_players() - local text = "List of Players:\n" + local text = "List of Players (" + text = text .. tostring(tablelength(x)) .. "/" + text = text .. tostring(minetest.settings:get("max_users")) .. "):" for j, i in ipairs(x) do text = text .. "\n" .. i.get_player_name(i) end