Advertisement
eternalclickbait

Untitled

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