Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function write(screen,x,y,text)
- screen.setCursorPos(x,y)
- screen.write(text)
- end
- function clearEventLog()
- eventLog.setBackgroundColor(colors.black)
- eventLog.clear()
- for y = 1, 20 do
- for x = 1, 63 do
- if y == 1 then
- eventLog.setBackgroundColor(colors.blue)
- elseif y%2 == 0 then
- eventLog.setBackgroundColor(colors.gray)
- else
- eventLog.setBackgroundColor(colors.black)
- end
- eventLog.setCursorPos(x,y)
- eventLog.setTextColor(colors.white)
- if x == 9 or x == 30 then
- eventLog.write("|")
- else
- eventLog.write(" ")
- end
- end
- end
- eventLog.setBackgroundColor(colors.blue)
- eventLog.setTextColor(colors.black)
- write(eventLog,3,1,"Time")
- write(eventLog,16,1,"Object")
- write(eventLog,46,1,"Event")
- end
- function testData()
- object1 = { time = "21:23", category = "turtle", object = "turtle:mining", event = "turtle ran out of fuel" }
- object2 = { time = "22:11", category = "energy", object = "energyLevel", event = "energylevel reached below 20%" }
- object3 = { time = "22:34", category = "item", object = "redstone", event = "now less than 10.000 redstone" }
- object4 = { time = "22:56", category = "command", object = "command", event = "redstone farm turned off" }
- object5 = { time = "23:03", category = "screen", object = "screen241", event = "natie3 is using screen241" }
- object6 = { time = "23:23", category = "turtle", object = "turtle:felling", event = "turtle ran out of fuel" }
- object7 = { time = "23:37", category = "energy", object = "energyLevel", event = "energylevel reached below 20%" }
- object8 = { time = "23:46", category = "item", object = "diamond", event = "now less than 1.000 diamond" }
- object9 = { time = "23:59", category = "command", object = "command", event = "all doors are now locked" }
- object10 = { time = "00:12", category = "screen", object = "screen145", event = "c00lgamer is using screen145" }
- table.insert(events,object1)
- table.insert(events,object2)
- table.insert(events,object3)
- table.insert(events,object4)
- table.insert(events,object5)
- table.insert(events,object6)
- table.insert(events,object7)
- table.insert(events,object8)
- table.insert(events,object9)
- table.insert(events,object10)
- end
- function displayEvents(category)
- clearEventLog()
- current = category
- eventLog.setTextColor(colors.white)
- count = 0
- index = #events
- while count < 19 and index > 0 do
- if category == nil or events[index].category == category then
- count = count + 1
- if count%2 == 1 then
- eventLog.setBackgroundColor(colors.gray)
- else
- eventLog.setBackgroundColor(colors.black)
- end
- write(eventLog,2,count+1,events[index].time)
- write(eventLog,11,count+1,events[index].object)
- write(eventLog,32,count+1,events[index].event)
- end
- index = index - 1
- end
- end
- -- initialize main
- m = peripheral.wrap("back")
- modem = peripheral.wrap("left")
- m.setBackgroundColor(colors.green)
- m.setTextColor(colors.blue)
- m.setTextScale(1)
- m.clear()
- write(m,31,2,"Event logger")
- events = { }
- current = nil
- modem.open(5000)
- -- initialize menu
- menu = window.create(m,1,4,9,27)
- menu.setBackgroundColor(colors.white)
- menu.setTextColor(colors.black)
- menu.clear()
- menu.setBackgroundColor(colors.gray)
- write(menu,2,2," All ")
- write(menu,2,4,"Energy ")
- write(menu,2,6," Items ")
- write(menu,2,8,"Turtle ")
- write(menu,2,10,"Command")
- write(menu,2,12,"Screen ")
- -- initialize eventLog
- eventLog = window.create(m,10,4,63,27)
- eventLog.setTextColor(colors.white)
- clearEventLog()
- -- initialize time
- http.request("http://www.timeapi.org/utc/in+one+hours")
- hour = 0
- minute = 0
- sec = 0
- count = 0
- displayEvents()
- while true do
- event = { os.pullEvent() }
- if event[1] == "http_success" then
- count = 0
- timeHandle = event[3]
- time = timeHandle.readLine()
- hour = tonumber(time:sub(12, 13))
- minute = tonumber(time:sub(15, 16))
- sec = tonumber(time:sub(18, 19))
- os.startTimer(60-sec)
- m.setTextColor(colors.white)
- m.setBackgroundColor(colors.green)
- write(m,65,1,string.format("%02d:%02d",hour,minute))
- event[3]:close()
- elseif event[1] == "http_failure" then
- http.request("http://www.timeapi.org/utc/in+one+hours")
- elseif event[1] == "timer" then
- count = count + 1
- if count > 14 then
- http.request("http://www.timeapi.org/utc/in+one+hours")
- else
- os.startTimer(60)
- end
- if minute == 59 then
- if hour == 23 then
- hour = 0
- minute = 0
- else
- minute = 0
- hour = hour + 1
- end
- else
- minute = minute + 1
- end
- m.setBackgroundColor(colors.green)
- write(m,65,1,string.format("%02d:%02d",hour,minute))
- elseif event[1] == "monitor_touch" then
- x = tonumber(event[3])
- y = tonumber(event[4])
- if x < 10 and (y == 5 or y == 7 or y == 9 or y == 11 or y == 13 or y == 15) then
- if y == 5 then
- displayEvents()
- elseif y == 7 then
- displayEvents("energy")
- elseif y == 9 then
- displayEvents("item")
- elseif y == 11 then
- displayEvents("turtle")
- elseif y == 13 then
- displayEvents("command")
- elseif y == 15 then
- displayEvents("screen")
- end
- end
- elseif event[1] == "modem_message" then
- object = textutils.unserialize(event[5])
- if object.type == "event" then
- event = object.event
- if event.category ~= nil and event.object ~= nil and event.event ~= nil then
- event["time"] = string.format("%02d:%02d",hour,minute)
- table.insert(events,event)
- displayEvents(current)
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement