BeastmodeJD

Untitled

Sep 14th, 2025 (edited)
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.43 KB | Gaming | 0 0
  1. local mon = peripheral.find("monitor") or error("No monitor found", 0)
  2. local modem = peripheral.find("modem") or error("No modem found", 0)
  3. local modemChan = 12
  4. local last = nil
  5. local monY = 2
  6. local logFile = nil
  7. local logDir = "/mine-logs/"
  8.  
  9. function resetMon()
  10.     local topLine
  11.     if (last == nil) then
  12.         topLine = "Open on "..modemChan.." | Last Completion: NONE"
  13.     else
  14.         topLine = "Open on "..modemChan.." | Last Completion: "..textutils.formatTime(last)
  15.     end
  16.     mon.clear()
  17.     mon.setTextScale(0.5)
  18.     mon.setTextColor(colors.cyan)
  19.     mon.setCursorPos(1,1)
  20.     mon.write(topLine)
  21.     mon.setTextColor(colors.white)
  22.     mon.setCursorPos(1,2)
  23.     monY = 2
  24. end
  25.  
  26. function mwrite(mess, tc, skipLog)
  27.     if (tc == nil) then
  28.         tc = colors.white
  29.     end
  30.  
  31.     if (skipLog == nil) then
  32.         skipLog = false
  33.     end
  34.    
  35.     mon.setCursorPos(1, monY)
  36.     mon.setTextColor(tc)
  37.     mon.write(mess)
  38.     print(mess)
  39.     monY = monY + 1
  40.  
  41.     if not skipLog then
  42.         mineLog(mess)
  43.     end
  44. end
  45.  
  46. function startLog()
  47.     if not fs.exists(logDir) then
  48.         fs.makeDir(logDir)
  49.     end
  50.     local logs = fs.list(logDir)
  51.     local logCount = #logs
  52.     local filename = (logCount + 1)..".txt"
  53.     local filePath = logDir .. filename
  54.     logFile = fs.open(filePath, "w")
  55.     mwrite("Logging to: "..filePath, colors.red, true)
  56.     logFile.writeLine("### START OF LOG ###")
  57.     logFile.writeLine(textutils.formatTime(os.time("utc")))
  58. end
  59.  
  60. function mineLog(mess)
  61.     if logFile == nil then
  62.         startLog()
  63.     end
  64.     logFile.writeLine(mess)
  65.     logFile.flush()
  66. end
  67.  
  68. function completeLog()
  69.     mineLog(textutils.formatTime(os.time("utc")))
  70.     mineLog("### END OF LOG ###")
  71.     logFile.close()
  72.     logFile = nil
  73. end
  74.  
  75. print("App running...")
  76. modem.open(12)
  77. while true do
  78.     resetMon()
  79.     startLog()
  80.     mwrite("Waiting for message...")
  81.     local e, s, c, rc, m, d
  82.     repeat e, s, c, rc, m, d = os.pullEvent("modem_message")
  83.     until c == 12 and m == "s"
  84.        
  85.     resetMon()
  86.     mwrite("Mine running...")
  87.     local q = false
  88.     while not q do
  89.         repeat e, s, c, rc, m, d = os.pullEvent("modem_message")
  90.         until c == 12
  91.        
  92.         if (rc == 0 and m == "d") then
  93.             break
  94.         else
  95.             mwrite(m, colors.orange)
  96.         end
  97.     end
  98.     last = os.time("utc")
  99.     resetMon()
  100.     mwrite("Mine completed!")
  101.     completeLog()
  102. end
Advertisement
Add Comment
Please, Sign In to add comment