Advertisement
eternalclickbait

Untitled

Nov 15th, 2019
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 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+y)/2
  28. local s = tonumber(scale) * tonumber(avg)
  29. m.setTextScale(s)
  30. end
  31. end
  32.  
  33. --Clears all monitors/windows
  34. function clear()
  35. term.clear()
  36. for _, side in ipairs(monitors) do
  37. peripheral.wrap(side).clear()
  38. peripheral.wrap(side).setCursorPos(1,1)--Reset the cursor position
  39. end
  40. term.setCursorPos(1,1)
  41. end
  42.  
  43. --Updates the list of reactors, turbines and monitor
  44. function updatePeripherals()
  45. local peripherals = peripheral.getNames() --Get a list of all the peripherals
  46. log("Peripherals:")
  47. for _, pSide in ipairs(peripherals) do
  48. local pType = peripheral.getType(pSide)
  49. local pFunctions = peripheral.wrap(pSide)
  50.  
  51. if(pType == "BigReactors-Reactor") then --If we found a reactor
  52. table.insert(reactors, pSide)
  53. elseif (pType == "BigReactors-Turbine") then
  54. table.insert(turbines, pSide)
  55. elseif (pType == "monitor") then
  56. table.insert(monitors, pSide)
  57. end
  58. end
  59. end
  60.  
  61. --Lists all of the peripherals connected
  62. function listPeripherals()
  63. log("Reactors:")
  64. for i, pSide in ipairs(reactors) do
  65. log("\t" ..i.. ":\t" ..pSide)
  66. end
  67.  
  68. log("Turbines:")
  69. for i, pSide in ipairs(turbines) do
  70. log("\t" ..i.. ":\t" ..pSide)
  71. end
  72.  
  73. log("Monitors:")
  74. for i, pSide in ipairs(monitors) do
  75. log("\t" ..i.. ":\t" ..pSide)
  76. end
  77. end
  78.  
  79.  
  80. --Updates all info on screen
  81. function update()
  82. --Clear the window(s)
  83. clear()
  84. end
  85.  
  86. log ("Turbine max energy: " ..turbineMaxEnergy)
  87. log ("Reactor max temp:" ..reactorMaxTemp)
  88.  
  89. updatePeripherals()
  90. listPeripherals()
  91. sleep(2)
  92. local i = 0.5
  93. while true do
  94. update()
  95. setMonitorScales(i)
  96. log("Current scale: " ..i)
  97. i = i +0.1
  98. sleep(2)
  99. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement