SHOW:
|
|
- or go back to the newest paste.
| 1 | --[[ | |
| 2 | Made by arc13 | |
| 3 | LifeIsPeripheral required | |
| 4 | TODO : Adapt to other mods | |
| 5 | --]] | |
| 6 | ||
| 7 | local e = peripheral.find("EntityDetector")
| |
| 8 | local w = peripheral.find("WorldInterface")
| |
| 9 | ||
| 10 | if not fs.exists("/logs/") then
| |
| 11 | fs.makeDir("/logs/")
| |
| 12 | end | |
| 13 | - | --fs.delete("/logs/"..actualPlayer)
|
| 13 | + | |
| 14 | local function getPlayerCoords(tActualPlayer) | |
| 15 | local nPlayerX = math.floor(math.abs(tActualPlayer["x"])) | |
| 16 | - | local file = fs.open("/logs/"..actualPlayer, "w")
|
| 16 | + | local nPlayerY = math.floor(math.abs(tActualPlayer["y"])) |
| 17 | local nPlayerZ = math.floor(math.abs(tActualPlayer["z"])) | |
| 18 | ||
| 19 | print("@ "..nPlayerX..", "..nPlayerY..", "..nPlayerZ)
| |
| 20 | - | local nPlayerX = math.floor(math.abs(tActualPlayer["x"])) |
| 20 | + | |
| 21 | - | local nPlayerY = math.floor(math.abs(tActualPlayer["y"])) |
| 21 | + | local nChunkX = math.floor(math.abs(nPlayerX / 16)) |
| 22 | - | local nPlayerZ = math.floor(math.abs(tActualPlayer["z"])) |
| 22 | + | local nChunkY = math.floor(math.abs(nPlayerY / 16)) |
| 23 | local nChunkZ = math.floor(math.abs(nPlayerZ / 16)) | |
| 24 | - | print(actualPlayer.."\n".."@ "..nPlayerX..", "..nPlayerY..", "..nPlayerZ) |
| 24 | + | |
| 25 | print("C : "..nChunkX..", "..nChunkY..", "..nChunkZ)
| |
| 26 | - | local nChunkX = math.floor(math.abs(nPlayerX / 16)) |
| 26 | + | |
| 27 | - | local nChunkY = math.floor(math.abs(nPlayerY / 16)) |
| 27 | + | return nChunkX, nChunkY, nChunkZ |
| 28 | - | local nChunkZ = math.floor(math.abs(nPlayerZ / 16)) |
| 28 | + | |
| 29 | ||
| 30 | - | print("C : "..nChunkX..", "..nChunkY..", "..nChunkZ)
|
| 30 | + | local function compare(a, b) |
| 31 | return a["time"] > b["time"] | |
| 32 | end | |
| 33 | - | file.write(tPlayerInfos) |
| 33 | + | |
| 34 | while true do | |
| 35 | - | local file = fs.open("/logs/"..actualPlayer, "r")
|
| 35 | + | |
| 36 | local actualPlayer = w.getPlayerList()[1] | |
| 37 | local tActualPlayer = e.getPlayerDetail(actualPlayer)[actualPlayer] | |
| 38 | ||
| 39 | if not fs.exists("/logs/"..actualPlayer) then
| |
| 40 | - | local file = fs.open("/logs/"..actualPlayer, "w")
|
| 40 | + | file = fs.open("/logs/"..actualPlayer, "w")
|
| 41 | ||
| 42 | local tPlayerInfos = {}
| |
| 43 | ||
| 44 | print(actualPlayer) | |
| 45 | local nChunkX, nChunkY, nChunkZ = getPlayerCoords(tActualPlayer) | |
| 46 | ||
| 47 | table.insert(tPlayerInfos, {chunkX=nChunkX, chunkY=nChunkY, chunkZ=nChunkZ, time=1})
| |
| 48 | table.sort(tPlayerInfos, compare) | |
| 49 | file.write(textutils.serialise(tPlayerInfos)) | |
| 50 | else | |
| 51 | file = fs.open("/logs/"..actualPlayer, "r")
| |
| 52 | local tPlayerInfos = file.readAll() | |
| 53 | tPlayerInfos = textutils.unserialise(tPlayerInfos) | |
| 54 | file.close() | |
| 55 | ||
| 56 | file = fs.open("/logs/"..actualPlayer, "w")
| |
| 57 | ||
| 58 | if not tPlayerInfos then | |
| 59 | file = fs.open("/logs/"..actualPlayer, "w")
| |
| 60 | ||
| 61 | tPlayerInfos = {}
| |
| 62 | ||
| 63 | print(actualPlayer) | |
| 64 | local nChunkX, nChunkY, nChunkZ = getPlayerCoords(tActualPlayer) | |
| 65 | ||
| 66 | table.insert(tPlayerInfos, {chunkX=nChunkX, chunkY=nChunkY, chunkZ=nChunkZ, time=1})
| |
| 67 | table.sort(tPlayerInfos, compare) | |
| 68 | else | |
| 69 | print(actualPlayer) | |
| 70 | local nChunkX, nChunkY, nChunkZ = getPlayerCoords(tActualPlayer) | |
| 71 | ||
| 72 | local bResult = false | |
| 73 | ||
| 74 | for i = 1, #tPlayerInfos do | |
| 75 | if tPlayerInfos[i]["chunkX"] == nChunkX and tPlayerInfos[i]["chunkZ"] == nChunkZ then | |
| 76 | bResult = true | |
| 77 | ||
| 78 | tPlayerInfos[i]["time"] = tPlayerInfos[i]["time"] + 1 | |
| 79 | ||
| 80 | break | |
| 81 | end | |
| 82 | end | |
| 83 | ||
| 84 | if not bResult then | |
| 85 | table.insert(tPlayerInfos, {chunkX=nChunkX, chunkY=nChunkY, chunkZ=nChunkZ, time=1})
| |
| 86 | end | |
| 87 | ||
| 88 | table.sort(tPlayerInfos, compare) | |
| 89 | end | |
| 90 | ||
| 91 | file.write(textutils.serialise(tPlayerInfos)) | |
| 92 | end | |
| 93 | ||
| 94 | file.close() | |
| 95 | end | |
| 96 | ||
| 97 | sleep(1) | |
| 98 | end |