Split and desactivate connected_players from utilities
This commit is contained in:
parent
d63f1904eb
commit
7715dedaa6
1
init.lua
1
init.lua
@ -18,3 +18,4 @@ dofile(path.."/shortcuts.lua")
|
||||
dofile(path.."/vanish.lua")
|
||||
dofile(path.."/aliases.lua")
|
||||
dofile(path.."/shutdown.lua")
|
||||
dofile(path.."/players.lua")
|
||||
|
30
players.lua
Normal file
30
players.lua
Normal file
@ -0,0 +1,30 @@
|
||||
--------------- CONNECTED PLAYERS
|
||||
|
||||
local interval = tonumber(minetest.settings:get("connected_players.interval")) or 25
|
||||
local players_file = minetest.get_worldpath() .. "/connected_players.txt"
|
||||
local timer = 0
|
||||
|
||||
|
||||
local function save_data()
|
||||
local file, err = io.open(players_file, "w")
|
||||
if file then
|
||||
for i,player in ipairs(minetest.get_connected_players()) do
|
||||
local name = player:get_player_name()
|
||||
file:write(name .. "\n")
|
||||
end
|
||||
io.close(file)
|
||||
return true
|
||||
end
|
||||
minetest.log("info", "Could not write players file: " .. err)
|
||||
return false
|
||||
end
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
timer = timer + dtime
|
||||
if timer >= interval then
|
||||
save_data()
|
||||
timer = 0
|
||||
else
|
||||
return
|
||||
end
|
||||
end)
|
@ -164,34 +164,3 @@ minetest.register_chatcommand("spawn", {
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
--------------- CONNECTED PLAYERS
|
||||
|
||||
local interval = tonumber(minetest.settings:get("connected_players.interval")) or 25
|
||||
local players_file = minetest.get_worldpath() .. "/connected_players.txt"
|
||||
local timer = 0
|
||||
|
||||
|
||||
local function save_data()
|
||||
local file, err = io.open(players_file, "w")
|
||||
if file then
|
||||
for i,player in ipairs(minetest.get_connected_players()) do
|
||||
local name = player:get_player_name()
|
||||
file:write(name .. "\n")
|
||||
end
|
||||
io.close(file)
|
||||
return true
|
||||
end
|
||||
minetest.log("info", "Could not write players file: " .. err)
|
||||
return false
|
||||
end
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
timer = timer + dtime
|
||||
if timer >= interval then
|
||||
save_data()
|
||||
timer = 0
|
||||
else
|
||||
return
|
||||
end
|
||||
end)
|
||||
|
Loading…
x
Reference in New Issue
Block a user