2015-07-23 22:00:59 +02:00
|
|
|
local time_interval = 5.0
|
2015-08-03 13:01:07 +02:00
|
|
|
local fifo_path = "/home/quentinbd/mff/worlds/minetestforfun/mt_players_fifo"
|
2015-07-06 16:39:17 +02:00
|
|
|
|
|
|
|
function players_data()
|
|
|
|
local ps = {}
|
|
|
|
for _, player in ipairs(minetest.get_connected_players()) do
|
|
|
|
local pos = player:getpos()
|
|
|
|
local pname = player:get_player_name()
|
|
|
|
local data = {
|
|
|
|
name = pname,
|
|
|
|
x = pos.x,
|
|
|
|
y = pos.y,
|
|
|
|
z = pos.z }
|
|
|
|
table.insert(ps, data)
|
|
|
|
end
|
|
|
|
if table.getn(ps) == 0 then
|
|
|
|
return '[]\n'
|
|
|
|
end
|
|
|
|
return minetest.write_json(ps) .. '\n'
|
|
|
|
end
|
|
|
|
|
|
|
|
function time_interval_func()
|
|
|
|
local players = players_data()
|
|
|
|
local fifo = io.open(fifo_path, 'w')
|
|
|
|
if (fifo ~= nil) then
|
|
|
|
fifo:write(players)
|
|
|
|
fifo:close()
|
|
|
|
end
|
|
|
|
minetest.after(time_interval, time_interval_func)
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.after(time_interval, time_interval_func)
|