Advertisement
Batword

Nuclear Information Console

May 9th, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.14 KB | None | 0 0
  1. rednet.open("back") -- Set Modem poition
  2. mon = peripheral.wrap("top")  --set Monitor Position
  3. mon.setBackgroundColor(colors.black)
  4. temp = 1
  5. reactor = "Querying"
  6. maxHeat = 1
  7. output = "Querying"
  8. timeLeft = "Querying"
  9. tempPercent = "Querying"
  10. adjustTemp = 5000
  11. x,y = mon.getSize()
  12. rednet.broadcast("ping")
  13. reactorCom = 148  --enter reactor computer ID
  14. maxStorageL = "1"
  15. energyL = "1"
  16. nir = 147 -- enter Nuclear information reader ID
  17.  
  18.  
  19.  
  20. function display()
  21.   mon.setTextColor(colours.black)
  22.   if reactor == "false" then
  23.     mon.setBackgroundColor(colors.green)
  24.     rectr = "OFF"
  25.   elseif reactor == "true" then
  26.     mon.setBackgroundColor(colors.lime)
  27.     rectr = "ON"
  28.   else
  29.     rectr = "QRY"
  30.     mon.setBackgroundColor(colors.gray)
  31.   end
  32.   p = 1
  33.   for i = 1,3 do
  34.     mon.setCursorPos(x-5, p)
  35.     mon.write("     ")
  36.     p = p + 1
  37.   end
  38.     p = 0
  39.     mon.setCursorPos(x-4, 2)
  40.     mon.write(rectr)
  41.     mon.setBackgroundColor(colours.black)
  42.     mon.setTextColor(colors.lime)
  43.     mon.setCursorPos(x/3+1, y-2)
  44.     mon.write("Reactor Temp: "..tempPercent.."%")
  45.     mon.setCursorPos(1, y-1)
  46.     mon.write("0%")
  47.     mon.setCursorPos(x/2, y-1)
  48.     mon.write("50%")
  49.     mon.setCursorPos(x-3, y-1)
  50.     mon.write("100%")
  51.     if tempPercent == "Querying" --[[or tempPercent == 0 ]] then
  52.       mon.setCursorPos(1, y)
  53.       mon.write("Temprature Unknown... Querying")
  54.     elseif tempPercent/2 < 1 then
  55.       mon.setCursorPos(1, y)
  56.       mon.setBackgroundColor(colors.lime)
  57.       mon.write(" ")
  58.       mon.setBackgroundColor(colors.black)
  59.       else
  60.       for i = 1, tempPercent, 2 do
  61.         p = p + 1
  62.         mon.setCursorPos(p,y)
  63.         if p < x/4 then
  64.         mon.setBackgroundColor(colors.lime)
  65.         mon.write(" ")
  66.         mon.setBackgroundColor(colors.black)
  67.         elseif p < x/2 then
  68.         mon.setBackgroundColor(colors.green)
  69.         mon.write(" ")
  70.         mon.setBackgroundColor(colors.black)
  71.         elseif p < x/4*3 then
  72.         mon.setBackgroundColor(colors.orange)
  73.         mon.write(" ")
  74.         mon.setBackgroundColor(colors.black)
  75.         elseif p <= x then
  76.         mon.setBackgroundColor(colors.red)
  77.         mon.write(" ")
  78.         mon.setBackgroundColor(colors.black)
  79.         end
  80.       end
  81.       p = 0
  82.   end
  83. end
  84.  
  85.  
  86. local result
  87. result = fs.exists("shutTemp")
  88. if result == true then
  89.   file = io.open("shutTemp", "r")
  90.   shutTemp = file:read()
  91.   file:close()
  92. elseif result == false then
  93.   shutTemp = 1000
  94. end
  95.  
  96. local result
  97. result = fs.exists("rctrStatus")
  98. if result == true then
  99.   file = io.open("rctrStatus", "r")
  100.   reactor = file:read()
  101.   file:close()
  102.   if reactor == "true" then
  103.     rednet.send(reactorCom, "on")
  104.   elseif reactor == "false" then
  105.     rednet.send(reactorCom, "off")
  106.   end
  107. elseif result == false then
  108.   rednet.send(reactorCom, "off")
  109. end
  110. while true do
  111.   display()
  112.   event, param1, param2, param3 = os.pullEvent()
  113.   if event == "rednet_message" then
  114.     if param2 == "heat" then
  115.       rednet.send(nir, "ping")
  116.       a,b = rednet.receive(.5)
  117.       temp = b
  118.     elseif param2  == "reactorPoweredB" then
  119.       rednet.send(nir, "ping")
  120.       a,b = rednet.receive(.5)
  121.       reactor = tostring(b)
  122.       file = fs.open("rctrStatus", "w")
  123.       file.write(b)
  124.       file:close()
  125.     elseif param2  == "maxHeat" then
  126.       rednet.send(nir, "ping")
  127.       a,b = rednet.receive(.5)
  128.       maxHeat = b
  129.     elseif param2 == "output" then
  130.       rednet.send(nir, "ping")
  131.       a,b = rednet.receive(.5)
  132.       output = b
  133.     elseif param2 == "timeLeft" then
  134.       rednet.send(nir, "ping")
  135.       a,b = rednet.receive(.5)
  136.       timeLeft = b --*0.00277778
  137.     elseif param2 == "energyL" then
  138.       rednet.send(nir, "ping")
  139.       a,b = rednet.receive(.5)
  140.       energyL = b
  141.       energyL = tonumber(energyL)
  142.       if energyL > 100000000 then
  143.         energyL = 100000000
  144.       end
  145.     elseif param2 == "maxStorageL" then
  146.       rednet.send(nir, "ping")
  147.       a,b = rednet.receive(.5)
  148.       maxStorageL = b
  149.     elseif param2 == "isSteam" then
  150.       rednet.send(nir, "ping")
  151.       a,b = rednet.receive(.5)
  152.       isSteam = b      
  153.     end
  154.     mon.clear()
  155.     mon.setCursorPos(1,1)
  156.     mon.setTextColor(colors.lime)
  157.     if reactor == "true" then
  158.       mon.write("Reactor: ")
  159.       mon.setTextColor(colors.lime)
  160.       mon.write("ON")
  161.       mon.setTextColor(colors.lime)
  162.     elseif reactor == "false" then
  163.       mon.write("Reactor: ")
  164.       mon.setTextColor(colors.green)
  165.       mon.write("OFF")
  166.       mon.setTextColor(colors.lime)
  167.     else
  168.       mon.write("Reactor: "..reactor)
  169.     end
  170.     mon.setCursorPos(1,3)
  171.     tempPercent = temp / maxHeat
  172.     tempPercent = tempPercent*100
  173.     tempPercent = math.floor(tempPercent)
  174.     mon.write("Reactor Temp: "..temp.."c")
  175.     mon.setCursorPos(1,5)
  176.     mon.write("EU Output: "..output)
  177.     mon.setCursorPos(1,7)
  178.     mon.write("Fuel: "..timeLeft)
  179.     mon.setCursorPos(1,9)
  180.     mon.write("Shutdown Temp: "..shutTemp)
  181.     mon.setCursorPos(21, 1)
  182.     mfsuE = tonumber(energyL)
  183.     mfsuEL = tonumber(maxStorageL)
  184.     if mfsuE == mfsuEL then
  185.       mon.write("AESU: 100%")
  186.     else
  187.       mfsuPercent = mfsuE / mfsuEL
  188.       mfsuPercent = mfsuPercent*100
  189.       mfsuPercent = math.floor(mfsuPercent)
  190.       mon.write("AESU: "..mfsuPercent.."%")
  191.     end
  192.     mon.setCursorPos(21, 3)
  193.     mon.write("EU: "..mfsuE)
  194.   elseif event == "monitor_touch" then
  195.     if param2 > x-6 and param3 < 4 then
  196.       if reactor == "false" then
  197.         rednet.send(reactorCom, "on")
  198.       elseif reactor == "true" then
  199.         rednet.send(reactorCom, "off")
  200.       end
  201.       j,k = rednet.receive()
  202.       if j == reactorCom and k == "false" then
  203.         for i = 1,4 do
  204.         mon.setBackgroundColor(colors.red)
  205.         mon.clear()
  206.         mon.setTextScale(4)
  207.         mon.setTextColor(colors.black)
  208.         mon.setCursorPos(1, 2)
  209.         mon.write("OVERHEATING!")
  210.         os.sleep(.5)
  211.         mon.clear()
  212.         mon.setTextColor(colors.red)
  213.         mon.setBackgroundColor(colors.black)
  214.         mon.setCursorPos(1, 2)
  215.         mon.write("OVERHEATING!")
  216.         os.sleep(.5)
  217.         end
  218.       end
  219.       mon.setTextScale(1)
  220.       mon.setBackgroundColor(colors.black)
  221.       mon.setTextColor(colors.lime)
  222.       rednet.broadcast("ping")
  223.     elseif param3 == y then --and param2 * 2 * 100 < 7500 then
  224.       adjustTemp = param2 * 2 * 100
  225.         mon.setCursorPos(param2, param3)
  226.         mon.setBackgroundColor(1)
  227.         mon.write(" ")
  228.         mon.setBackgroundColor(colors.black)
  229.       rednet.send(reactorCom, "maxTemp")
  230.       id, message = rednet.receive()
  231.       if id == reactorCom then
  232.         adjustTemp = tostring(adjustTemp)
  233.         rednet.send(reactorCom, adjustTemp)
  234.         id, message = rednet.receive()
  235.         if message == "true" and id == reactorCom then
  236.           shutTemp = adjustTemp
  237.           file = fs.open("shutTemp", "w")
  238.           file.write(shutTemp)
  239.           file:close()
  240.         elseif message == "false" and id == reactorCom then
  241.           mon.setCursorPos(1,y)
  242.           for i = 1,x do
  243.             mon.write(" ")
  244.           end
  245.           mon.setCursorPos(1,y)
  246.           mon.write("Max Temp Failed To Update!")
  247.         end
  248.       end
  249.     end
  250.   end
  251. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement