Advertisement
eternalclickbait

Untitled

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