Advertisement
eternalclickbait

Untitled

Nov 15th, 2019
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. --Reactor and turbine control script by EternalClickbait
  2. --Reactor, turbine and monitor must be connected with wired modems to the computer
  3.  
  4. local reactors = {}
  5. local turbines = {}
  6. local monitors = {}
  7.  
  8. --The maximum temperature for the reactor
  9. local reactorMaxTemp = 200
  10. --The maximum energy in our turbine's buffer. Max is 1M (1,000,000)
  11. local turbineMaxEnergy = 500000
  12.  
  13. --Prints a message to all monitors/windows
  14. function log(message)
  15. print(message)
  16. for _, side in ipairs(monitors) do
  17. peripheral.wrap(side).write(message)
  18. end
  19. end
  20.  
  21. --Sets the scales on all monitors for easily visible text
  22. function setMonitorScales(scale)
  23. for _, side in ipairs(monitors) do
  24. local m = peripheral.wrap(side)
  25. --Get the normalized scale for the monitor (1 = 1 block)
  26. local x,y = m.getSize()
  27. local avg = (((x/7) + (y/5))/2)
  28. local s = tonumber(scale) * tonumber(avg)
  29. m.write(avg)
  30. m.write("\n")
  31. m.write(scale)
  32. m.write("\n")
  33. m.write(s)
  34. m.setTextScale(s)
  35. end
  36. end
  37.  
  38. --Clears all monitors/windows
  39. function clear()
  40. term.clear()
  41. for _, side in ipairs(monitors) do
  42. peripheral.wrap(side).clear()
  43. peripheral.wrap(side).setCursorPos(1,1)--Reset the cursor position
  44. end
  45. term.setCursorPos(1,1)
  46. end
  47.  
  48. --Updates the list of reactors, turbines and monitor
  49. function updatePeripherals()
  50. local peripherals = peripheral.getNames() --Get a list of all the peripherals
  51. log("Peripherals:")
  52. for _, pSide in ipairs(peripherals) do
  53. local pType = peripheral.getType(pSide)
  54. local pFunctions = peripheral.wrap(pSide)
  55.  
  56. if(pType == "BigReactors-Reactor") then --If we found a reactor
  57. table.insert(reactors, pSide)
  58. elseif (pType == "BigReactors-Turbine") then
  59. table.insert(turbines, pSide)
  60. elseif (pType == "monitor") then
  61. table.insert(monitors, pSide)
  62. end
  63. end
  64. end
  65.  
  66. --Lists all of the peripherals connected
  67. function listPeripherals()
  68. log("Reactors:")
  69. for i, pSide in ipairs(reactors) do
  70. log("\t" ..i.. ":\t" ..pSide)
  71. end
  72.  
  73. log("Turbines:")
  74. for i, pSide in ipairs(turbines) do
  75. log("\t" ..i.. ":\t" ..pSide)
  76. end
  77.  
  78. log("Monitors:")
  79. for i, pSide in ipairs(monitors) do
  80. log("\t" ..i.. ":\t" ..pSide)
  81. end
  82. end
  83.  
  84.  
  85. --Updates all info on screen
  86. function update()
  87. --Clear the window(s)
  88. clear()
  89. end
  90.  
  91. log ("Turbine max energy: " ..turbineMaxEnergy)
  92. log ("Reactor max temp:" ..reactorMaxTemp)
  93.  
  94. updatePeripherals()
  95. listPeripherals()
  96. sleep(2)
  97. local i = 0.5
  98. while true do
  99. update()
  100. setMonitorScales(i)
  101. log("Current scale: " ..i)
  102. i = i +0.1
  103. sleep(2)
  104. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement