Advertisement
Muzze77

Monitor V1

Aug 26th, 2016
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.56 KB | None | 0 0
  1. shell.run("clear")
  2. rednet.open("left")
  3. mon = peripheral.wrap("back")
  4. mod = peripheral.wrap("left")
  5. mon.setTextScale(1)
  6. mon.setTextColor(colors.white)
  7. mon.setBackgroundColor(colors.black)
  8. mon.clear()
  9. gx, gy = mon.getSize()
  10.  
  11.  
  12. function mcbut (cx,cy,text,tcol,bcol)
  13.      mon.setCursorPos(cx,cy)
  14.      mon.setBackgroundColor(bcol)
  15.      mon.setTextColor(tcol)
  16.      mon.write(text)
  17.      mon.setTextColor(colors.white)
  18.      mon.setBackgroundColor(colors.black)
  19. end
  20.  
  21.  
  22. function startscreen()
  23. shell.run("clear")
  24. mcbut(4,4,"Light ",colors.white, colors.black)
  25. mcbut(26,4,globTab["Light"]["Status"],colors.white,globTab.Light.Color)
  26. mcbut(4,6,"Mass Fabricator",colors.white, colors.black)
  27. mcbut(24,4,"|",colors.white,colors.black)
  28. mcbut(24,6,"|",colors.white,colors.black)
  29. mcbut(26,6,globTab["Mass"]["Status"],colors.white,globTab.Mass.Color)
  30. mcbut(4,8,"UU-Matter in Mass",colors.white,colors.black)
  31. mcbut(24,6,":",colors.white,colors.black)
  32. end
  33.  
  34. function loadSave()
  35. if fs.exists("save") == false then
  36. globTab = {}
  37. globTab["Light"] = {["Status"] = "On ",["Color"] = colors.green}
  38. globTab["Mass"] = {["Status"] = "Get", ["Color"] = colors.green}
  39. save()
  40. else
  41. fileR = fs.open("save","r")
  42. globTab = textutils.unserialize(fileR.readLine(1))
  43. fileR.close()
  44. end
  45.  
  46. if globTab.Light.Status == "Off" then
  47.     rs.setOutput("top",false)
  48. elseif globTab.Light.Status == "On " then
  49.     rs.setOutput("top",true)
  50. end
  51.  
  52.  
  53. end
  54.  
  55. function save()
  56. shell.run("delete save")
  57. fileS = fs.open("save", "w")
  58. fileS.writeLine(textutils.serialize(globTab))
  59. fileS.close()
  60. end
  61.  
  62.  
  63. function screens()
  64. evt,side, x, y = os.pullEvent("monitor_touch")
  65.  
  66. if y == 4 then
  67.   if globTab.Light.Status == "Off" then
  68.      globTab.Light.Status = "On "
  69.      globTab.Light.Color = colors.green
  70.      rs.setOutput("top",true)
  71.      mcbut(26,4,globTab.Light.Status,colors.white, globTab.Light.Color)
  72.  
  73.    
  74.   elseif globTab.Light.Status == "On " then
  75.     globTab.Light.Status = "Off"
  76.     globTab.Light.Color = colors.red
  77.     rs.setOutput("top",false)
  78.     mcbut(26,4,globTab.Light.Status,colors.white,globTab.Light.Color)
  79.  
  80.   end
  81. end
  82. if y == 6 then
  83.        globTab.Mass.Status = "Cls"
  84.        globTab.Mass.Color = colors.red
  85.        smsg = {["Type"] = "RS",["Info"] = "Mass"}
  86.        rednet.broadcast(textutils.serialize(smsg))
  87.        mcbut(26,6,"Cls",colors.white, globTab.Mass.Color)
  88.        sleep(3)
  89.        globTab.Mass.Status = "Get"
  90.        globTab.Mass.Color = colors.green
  91.        mcbut(26,6,"Cls",colors.white,globTab.Mass.Color)
  92.  
  93.        
  94.  
  95. end
  96. save()
  97. sleep(0.2)
  98. end
  99.  
  100.  
  101. function gets()
  102. ID,msg = rednet.receive()
  103. if ID == 897 or ID == 905 or ID == 903 then
  104. tabler = textutils.unserialize(msg)
  105. print(tabler.Type)
  106. if tabler["Type"] == "Info" then
  107.    if tabler["Machine"] == "Mass"then
  108.       setText = tabler["Info"]
  109.       term.clearLine(8)
  110.       mcbut(4,8,"UU-Matter",colors.white, colors.black)
  111.       mcbut(24,8,"|",colors.white,colors.black)
  112.       mcbut(26,8,math.floor(setText) .. "  ",colors.white,colors.black)  
  113.    end
  114. elseif tabler["Type"] == "En" then
  115.  
  116. machines = textutils.unserialize(tabler.Info)
  117.     for ic = 1 , gy, 1 do
  118.     mcbut(32,ic + 2,"                                                                ",colors.yellow,colors.black)
  119.     end
  120.  
  121.     for p = 1 , table.maxn(machines),1 do
  122.     strmsg = machines[p].Name .. ": " .. machines[p].Stored .. "/" .. machines[p].Capacity .. " | ".. machines[p].Location
  123.     mcbut(32,p + 2,strmsg ,colors.yellow,colors.black)
  124.     end
  125.  
  126. end
  127.  
  128.  
  129.  
  130. end
  131. end
  132.  
  133. while true do
  134. loadSave()
  135. shell.run("clear")
  136.   startscreen()
  137.   parallel.waitForAny(screens, gets)
  138. sleep(0.2)
  139. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement