Zinne91

Untitled

Dec 25th, 2020
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. -- <<< Settings >>> --
  2.  
  3. local sleepTime = 0 -- Time to sleep (values greater than 0.5 will save energy consumed by the computer)
  4. local maxRate = 90 -- Maximum injectionrate to heat up
  5. local wantedRate = 20 -- Wanted injectionrate for the fuel
  6. local minRate = 10 -- Minimum injectionrate cool down (NOT LOWER THAN 1 OR YOUR REACTOR WILL TURN OFF!)
  7. local enableGui = false -- Enable the Gui on the screen (true or false)
  8.  
  9. -- <<< Code >>> --
  10.  
  11. components = require("component")
  12. event = require("event")
  13.  
  14. r = components.proxy(components.list("reactor_logic_adapter")())
  15.  
  16. energyGenerated = 0
  17. screenScale = 4
  18.  
  19. r.setInjectionRate(wantedRate)
  20. maxCaseHeat = r.getMaxCaseHeat()
  21. maxPlasmaHeat = r.getMaxPlasmaHeat()
  22.  
  23. rate = wantedRate
  24. caseHeat = tonumber(r.getCaseHeat())
  25. plasmaHeat = tonumber(r.getPlasmaHeat())
  26. hasFuel = r.hasFuel()
  27. isIgnited = r.isIgnited()
  28.  
  29. function overheated()
  30. if r.getCaseHeat() > maxCaseHeat then
  31. return true
  32. elseif r.getPlasmaHeat() > maxPlasmaHeat then
  33. return true
  34. else
  35. return false
  36. end
  37. end
  38.  
  39. function round(x, dezimals)
  40. local multi = 10^(dezimals or 0)
  41. return ((x * multi) + 0.5 - (x * multi + 0.5) % 1) / multi
  42. end
  43.  
  44. function regulation()
  45.  
  46. local percent = round((((plasmaHeat/maxPlasmaHeat) * 100) + ((caseHeat/maxCaseHeat) * 100)) / 2, 1)
  47. local newRate = wantedRate
  48.  
  49. if percent > 100.2 then
  50. if rate > wantedRate then
  51. rate = wantedRate
  52. end
  53. newRate = rate - 1
  54. elseif percent < 99.8 then
  55. if rate < wantedRate then
  56. rate = wantedRate
  57. end
  58. newRate = rate + 1
  59. end
  60.  
  61. if newRate < minRate then
  62. newRate = minRate
  63. elseif newRate > maxRate then
  64. newRate = maxRate
  65. end
  66.  
  67. r.setInjectionRate(newRate)
  68. end
  69.  
  70. local run = true
  71.  
  72. while run do
  73.  
  74. rate = tonumber(r.getInjectionRate())
  75. caseHeat = tonumber(r.getCaseHeat())
  76. plasmaHeat = tonumber(r.getPlasmaHeat())
  77. energyGenerated = tonumber(r.getEnergy()) * 0.4
  78.  
  79. regulation()
  80.  
  81. if enableGui then
  82. gui()
  83. end
  84.  
  85. local e = event.pull(sleepTime, "key_down")
  86. if e then
  87. run = false
  88. end
  89. end
Advertisement
Add Comment
Please, Sign In to add comment