Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Pair with https://pastebin.com/ga0KRZ4f to view the logs
- You will need a 6 wide monitor
- Simple startup file
- if not peripheral.find("playerDetector") then
- term.setCursorPos(1, 1)
- term.write("No player detector found")
- return
- end
- if not peripheral.find("monitor") then
- term.setCursorPos(1, 1)
- term.write("No monitor found to display logs")
- return
- end
- shell.openTab("lookUp.lua")
- shell.openTab("visitorLog.lua")
- ]]
- Monitor = peripheral.find("monitor")
- term.clear()
- function EnterInput()
- term.setCursorPos(1, 1)
- term.clearLine()
- term.write("'list' to list logged names")
- term.setCursorPos(1, 2)
- term.clearLine()
- term.write("<playerName> to display logs of player")
- term.setCursorPos(1, 3)
- term.clearLine()
- term.write("Input: ")
- return read()
- end
- function GetLogs()
- local visitorFile = fs.open("visitorLog.txt", "r")
- local log = visitorFile.readAll()
- visitorFile.close()
- return textutils.unserialize(log)
- end
- local function formatSeconds(seconds, noDays)
- local days = math.floor(seconds/86400)
- local hours = math.floor(math.mod(seconds, 86400)/3600)
- local minutes = math.floor(math.mod(seconds,3600)/60)
- local seconds = math.floor(math.mod(seconds,60))
- if noDays then
- return string.format("%02d:%02d:%02d",hours,minutes,seconds)
- else
- return string.format("%d:%02d:%02d:%02d",days,hours,minutes,seconds)
- end
- end
- function DisplayLogs(lookUpName)
- Monitor.clear()
- Monitor.setCursorPos(1, 1)
- Monitor.setTextColor(colors.white)
- Monitor.write("Logs for ")
- Monitor.setCursorPos(10, 1)
- Monitor.setTextColor(colors.blue)
- Monitor.write(lookUpName)
- Monitor.setCursorPos(10+#lookUpName, 1)
- Monitor.setTextColor(colors.white)
- Monitor.write(" | ")
- Monitor.setCursorPos(10+#lookUpName+3, 1)
- Monitor.setTextColor(colors.orange)
- Monitor.write(formatSeconds(GetPlayerTotalTime(lookUpName)))
- local visitorLogs = GetLogs()
- if not visitorLogs[lookUpName] then
- Monitor.setCursorPos(1, 2)
- Monitor.write("No logs found")
- return
- end
- local playersLogs = visitorLogs[lookUpName]
- for i,v in ipairs(Reverse(playersLogs)) do
- Monitor.setCursorPos(1, i+1)
- Monitor.setTextColor(colors.green)
- Monitor.write(v[1])
- Monitor.setCursorPos(24, i+1)
- Monitor.setTextColor(colors.white)
- Monitor.write(" | ")
- Monitor.setCursorPos(27, i+1)
- Monitor.setTextColor(colors.red)
- Monitor.write((v[2] or "?"))
- Monitor.setCursorPos(51, i+1)
- Monitor.setTextColor(colors.orange)
- Monitor.write(formatSeconds(v[3] or 0))
- end
- end
- function GetPlayerTotalTime(playerName)
- local playersLogs = GetLogs()[playerName]
- if not playersLogs then
- return 0
- end
- local totalTime = 0
- for i,v in ipairs(playersLogs) do
- if v[2] then
- totalTime = totalTime + v[3]
- end
- end
- return totalTime
- end
- function ListPlayers()
- local logs = GetLogs()
- term.setCursorPos(1, 5)
- term.clearLine()
- term.write("There are logs for...")
- local count = 0
- for i,v in pairs(logs) do
- term.setCursorPos(1, 6+count)
- term.clearLine()
- term.setTextColor(colors.blue)
- term.write(i)
- term.setCursorPos(#i+1, 6+count)
- term.setTextColor(colors.white)
- term.write(" | ")
- term.setCursorPos(#i+4, 6+count)
- term.setTextColor(colors.orange)
- term.write(formatSeconds(GetPlayerTotalTime(i)))
- term.setTextColor(colors.white)
- count = count+1
- end
- end
- function Reverse(table)
- for i = 1, #table/2, 1 do
- table[i], table[#table-i+1] = table[#table-i+1], table[i]
- end
- return table
- end
- while true do
- local search = EnterInput()
- if search == "list" or search == "List" then
- ListPlayers()
- else
- DisplayLogs(search)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement