Advertisement
Reavik

RobsomLogDysplay

Jan 12th, 2023 (edited)
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.67 KB | None | 0 0
  1.  
  2. --by: Player_rs, Reavik, zResckBR
  3.  
  4. local modem = peripheral.wrap("back")
  5. modem.open(100)
  6.  
  7. local monitor = peripheral.wrap("left")
  8. local pos = 1
  9. print("Positivo e Operando")
  10.  
  11. monitor.clear()
  12. --editado
  13. function ler()
  14.     if not fs.exists("RobsomLog/log.lua") then
  15.         monitor.setTextScale(0.5)
  16.         monitor.setTextColour(32)
  17.         monitor.setCursorPos(1,pos+1)
  18.         monitor.write("Arquivo de log não encontrado, criando log.lua")
  19.  
  20.         fs.makeDir("RobsomLog/log.lua")
  21.         local f fs.open("RobsomLog/log.lua", "w")
  22.         f.write("{\"Positivo e operante\"}")
  23.         f.close()
  24.     end
  25.     -----------------------------------------
  26. local f = fs.open("RobsomLog/log.lua", "r")
  27. local data = textutils.unserialize(f.readAll())
  28.         for i = 1, #data do    monitor.setBackgroundColour(32768)
  29.             monitor.setTextScale(0.5)
  30.             monitor.setTextColour(32)
  31.             monitor.setCursorPos(1,pos+1)
  32.             pos = pos+1
  33.             monitor.write(data[i])
  34.         end
  35.     f.close()
  36. end
  37. ler()
  38. function escrever(resposta)
  39.     local time = os.date('*t')
  40.     local f = fs.open("RobsomLog/log.lua", "r")
  41.     local data = textutils.unserialize(f.readAll())
  42.     f.close()
  43.     local a = fs.open("RobsomLog/log.lua", "w")
  44.  
  45.     for _, v in pairs({"day", "month", "year", "hour", "min", "sec"}) do
  46.         if time[v] < 10 then
  47.             time[v] = "0"..time[v]
  48.         end
  49.     end
  50.     if #data >= 79 then
  51.         table.remove(data, 1)
  52.         table.insert(data, string.format("[%s/%s/%s-%s:%s:%s]: %s", time.day, time.month, time.year, time.hour, time.min, time.sec, message))
  53.         a.write(textutils.serialize(data))
  54.     else
  55.         table.insert(data, string.format("[%s/%s/%s-%s:%s:%s]: %s", time.day, time.month, time.year, time.hour, time.min, time.sec, resposta))
  56.         a.write(textutils.serialize(data))
  57.     end
  58.     a.close()
  59. end
  60.  
  61.     while true do
  62.         local e, p,channel, replyChannel, message, distance = os.pullEvent("modem_message")
  63.  
  64.         if message ~= new then
  65.         escrever(message)
  66.         local time = os.date('*t')
  67.         for _, v in pairs({"day", "month", "year", "hour", "min", "sec"}) do
  68.             if time[v] < 10 then
  69.                 time[v] = "0"..time[v]
  70.             end
  71.         end
  72.         monitor.setBackgroundColour(32768)
  73.         monitor.setTextScale(0.5)
  74.         monitor.setTextColour(32)
  75.         monitor.setCursorPos(1,pos+1)
  76.         pos = pos+1
  77.         monitor.write(string.format("[%s/%s/%s-%s:%s:%s]: %s", time.day, time.month, time.year, time.hour, time.min, time.sec, message))
  78.         if pos >= 79 then
  79.             monitor.scroll(1)
  80.             pos = 78
  81.         end
  82.     end
  83. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement