SHARE
TWEET

Untitled

a guest Aug 25th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local component = require("component")
  2. local keyboard = require("keyboard")
  3. local event = require("event")
  4. local gpu = component.gpu
  5. local reactor = component.br_reactor
  6.  
  7. -- defninitions
  8. reactor["stats"] = {}
  9. local running = true
  10. local maxRF = 75
  11. local minRF = 25
  12. local currentRF = 0
  13.  
  14. local maxRFStorage = 10000000
  15.  
  16.  
  17. -- functions
  18. function toint(n)
  19.     local s = tostring(n)
  20.     local i, j = s:find('%.')
  21.     if i then
  22.         return tonumber(s:sub(1, i-1))
  23.     else
  24.         return n
  25.     end
  26. end
  27.  
  28. function getInfoFromReactor()
  29.   local reactorEnergyStats = reactor.getEnergyStats()
  30.   local reactorFuelStats = reactor.getFuelStats()
  31.   reactorRodsLevel = reactor.getControlRodsLevels()
  32.  
  33.   -- reactor.stats["tick"] = toint(math.ceil(reactorEnergyStats["energyProducedLastTick"]))
  34.   reactor.stats["stored"] = toint(reactorEnergyStats["energyStored"])
  35.   -- reactor.stats["rods"] = toint(reactorRodsLevel[0])
  36.   -- reactor.stats["fuel"] = round(reactorFuelStats["fuelConsumedLastTick"], 2)
  37.   currentRf = (reactor.stats["stored"] * 100) / maxRFStorage
  38. end
  39.  
  40. function powerOn()
  41.   reactor.setActive(true)
  42. end
  43.  
  44. function powerOff()
  45.   reactor.setActive(false)
  46. end
  47.  
  48. -- helpers
  49. function round(val, decimal)
  50.   if (decimal) then
  51.     return math.floor( (val * 10^decimal) + 0.5) / (10^decimal)
  52.   else
  53.     return math.floor(val+0.5)
  54.   end
  55. end
  56.  
  57. function init()
  58.     powerOn()
  59.     running = true
  60.     getInfoFromReactor()
  61.     print("Initialisation...")
  62. end
  63.  
  64. function showInfos()
  65.     os.execute("clear")
  66.     print("Actualisation des informations tout les 5 seconds")
  67.     if (running) then
  68.         print("Etat du reactor : Marche")
  69.     else
  70.         print("Etat du reactor : Arret")
  71.     end
  72.     print("Energie Actuel : " .. currentRF .. "%")
  73. end
  74.  
  75. function process()
  76.     while event.pull(0.1, "interrupted") == nil do
  77.         print(currentRF)
  78.         if (running and currentRF >= maxRF) then
  79.             powerOff()
  80.             running = false
  81.         end
  82.        
  83.         if (not(running) and currentRF <= minRF) then
  84.             powerOn()
  85.             running = true
  86.         end
  87.         showInfos()
  88.         os.sleep(5)
  89.     end
  90. end
  91.  
  92. function finish()
  93.     powerOff()
  94.     running = false
  95.     print('Finish.')
  96. end
  97.  
  98. init()
  99. process()
  100. finish()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top