added player list system
This commit is contained in:
parent
1bba1f0716
commit
a8d131bc18
10
mods/playerlist/README.txt
Normal file
10
mods/playerlist/README.txt
Normal file
@ -0,0 +1,10 @@
|
||||
Playerlist mod
|
||||
==================
|
||||
By Kaadmy, for Pixture
|
||||
|
||||
Adds player lists(recent/current).
|
||||
|
||||
Use the chatcommand "/plist" to show current players
|
||||
Use the chatcommand "/precent" to show players that have connected in the last hour
|
||||
|
||||
Source license: WTFPL
|
1
mods/playerlist/depends.txt
Normal file
1
mods/playerlist/depends.txt
Normal file
@ -0,0 +1 @@
|
||||
default
|
77
mods/playerlist/init.lua
Normal file
77
mods/playerlist/init.lua
Normal file
@ -0,0 +1,77 @@
|
||||
--
|
||||
-- Playerlist mod
|
||||
-- By Kaadmy, for Pixture
|
||||
--
|
||||
|
||||
playerlist = {}
|
||||
|
||||
playerlist.step = tonumber(minetest.setting_get("playerlist_step")) or 3
|
||||
|
||||
-- current players format:
|
||||
-- {<playername> = <last connect(if connected, or nil)>}
|
||||
playerlist.players = {}
|
||||
|
||||
local function divmod(f, d)
|
||||
return {math.floor(f / d), f % d}
|
||||
end
|
||||
|
||||
local function prettytime(time)
|
||||
local a = divmod(time, 60)
|
||||
local seconds = a[2]
|
||||
local minutes = a[1]
|
||||
|
||||
local b = divmod(minutes, 60)
|
||||
local hours = b[1]
|
||||
minutes = b[2]
|
||||
|
||||
local c = divmod(hours, 24)
|
||||
local days = c[1]
|
||||
hours = c[2]
|
||||
|
||||
local str = ""
|
||||
if days ~= 0 then str = str .. days .. "d " end
|
||||
if hours ~= 0 then str = str .. hours .. "h " end
|
||||
if minutes ~= 0 then str = str .. minutes .. "m " end
|
||||
str = str .. seconds .. "s"
|
||||
|
||||
return str
|
||||
end
|
||||
|
||||
local function on_joinplayer(player)
|
||||
local name = player:get_player_name()
|
||||
|
||||
playerlist.players[name] = minetest.get_gametime()
|
||||
end
|
||||
|
||||
local function on_leaveplayer(player)
|
||||
local name = player:get_player_name()
|
||||
|
||||
playerlist.players[name] = minetest.get_gametime()
|
||||
end
|
||||
|
||||
minetest.register_on_joinplayer(on_joinplayer)
|
||||
minetest.register_on_leaveplayer(on_leaveplayer)
|
||||
|
||||
minetest.register_chatcommand(
|
||||
"plist",
|
||||
{
|
||||
description = "List players that are connected and have connected since the last server restart",
|
||||
func = function(name, param)
|
||||
local time = minetest.get_gametime()
|
||||
|
||||
minetest.chat_send_player(name, "Player list:")
|
||||
|
||||
local player_count = 0
|
||||
for name, jointime in pairs(playerlist.players) do
|
||||
if minetest.get_player_by_name(name) ~= nil then
|
||||
player_count = player_count + 1
|
||||
minetest.chat_send_player(name, " " .. name .. ": connected for " .. prettytime(time - jointime))
|
||||
else
|
||||
minetest.chat_send_player(name, " " .. name .. ": last seen " .. prettytime(time - jointime) .. " ago")
|
||||
end
|
||||
end
|
||||
|
||||
minetest.chat_send_player(name, player_count .. " players connected")
|
||||
end
|
||||
})
|
||||
default.log("mod:playerlist", "loaded")
|
Loading…
x
Reference in New Issue
Block a user