mtsatellite/mods/track_players/init.lua

29 lines
616 B
Lua
Raw Normal View History

2015-03-09 11:49:55 +01:00
local time_interval = 1.0
2015-03-09 15:01:05 +01:00
local fifo_path = "/tmp/mt_players_fifo"
2015-03-09 11:49:55 +01:00
function players_data()
2016-08-13 12:04:08 +02:00
local ps = minetest.get_connected_players()
local pcount = #ps
if pcount == 0 then
return "[]\n"
end
for i = 1,pcount do
local player = ps[i]
2024-01-07 14:52:54 +01:00
local data = player:get_pos()
2016-08-13 12:04:08 +02:00
data.name = player:get_player_name()
ps[i] = data
end
return minetest.write_json(ps) .. "\n"
end
function time_interval_func()
2016-08-13 12:04:08 +02:00
local fifo = io.open(fifo_path, "w")
if fifo then
fifo:write(players_data())
fifo:close()
end
minetest.after(time_interval, time_interval_func)
2015-03-09 11:49:55 +01:00
end
minetest.after(time_interval, time_interval_func)