Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Made by arc13
- LifeIsPeripheral required
- TODO : Adapt to other mods
- --]]
- local e = peripheral.find("EntityDetector")
- local w = peripheral.find("WorldInterface")
- if not fs.exists("/logs/") then
- fs.makeDir("/logs/")
- end
- local function getPlayerCoords(tActualPlayer)
- local nPlayerX = math.floor(math.abs(tActualPlayer["x"]))
- local nPlayerY = math.floor(math.abs(tActualPlayer["y"]))
- local nPlayerZ = math.floor(math.abs(tActualPlayer["z"]))
- print("@ "..nPlayerX..", "..nPlayerY..", "..nPlayerZ)
- local nChunkX = math.floor(math.abs(nPlayerX / 16))
- local nChunkY = math.floor(math.abs(nPlayerY / 16))
- local nChunkZ = math.floor(math.abs(nPlayerZ / 16))
- print("C : "..nChunkX..", "..nChunkY..", "..nChunkZ)
- return nChunkX, nChunkY, nChunkZ
- end
- local function compare(a, b)
- return a["time"] > b["time"]
- end
- while true do
- for i = 1, #w.getPlayerList() do
- local actualPlayer = w.getPlayerList()[1]
- local tActualPlayer = e.getPlayerDetail(actualPlayer)[actualPlayer]
- if not fs.exists("/logs/"..actualPlayer) then
- file = fs.open("/logs/"..actualPlayer, "w")
- local tPlayerInfos = {}
- print(actualPlayer)
- local nChunkX, nChunkY, nChunkZ = getPlayerCoords(tActualPlayer)
- table.insert(tPlayerInfos, {chunkX=nChunkX, chunkY=nChunkY, chunkZ=nChunkZ, time=1})
- table.sort(tPlayerInfos, compare)
- file.write(textutils.serialise(tPlayerInfos))
- else
- file = fs.open("/logs/"..actualPlayer, "r")
- local tPlayerInfos = file.readAll()
- tPlayerInfos = textutils.unserialise(tPlayerInfos)
- file.close()
- file = fs.open("/logs/"..actualPlayer, "w")
- if not tPlayerInfos then
- file = fs.open("/logs/"..actualPlayer, "w")
- tPlayerInfos = {}
- print(actualPlayer)
- local nChunkX, nChunkY, nChunkZ = getPlayerCoords(tActualPlayer)
- table.insert(tPlayerInfos, {chunkX=nChunkX, chunkY=nChunkY, chunkZ=nChunkZ, time=1})
- table.sort(tPlayerInfos, compare)
- else
- print(actualPlayer)
- local nChunkX, nChunkY, nChunkZ = getPlayerCoords(tActualPlayer)
- local bResult = false
- for i = 1, #tPlayerInfos do
- if tPlayerInfos[i]["chunkX"] == nChunkX and tPlayerInfos[i]["chunkZ"] == nChunkZ then
- bResult = true
- tPlayerInfos[i]["time"] = tPlayerInfos[i]["time"] + 1
- break
- end
- end
- if not bResult then
- table.insert(tPlayerInfos, {chunkX=nChunkX, chunkY=nChunkY, chunkZ=nChunkZ, time=1})
- end
- table.sort(tPlayerInfos, compare)
- end
- file.write(textutils.serialise(tPlayerInfos))
- end
- file.close()
- end
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement