SoulofSorrow

Reaktorprogramm (ohne Turbinen) von Thor_s_Crafter --

Mar 13th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Reaktorprogramm (ohne Turbinen) --
  2. -- von Thor_s_Crafter --
  3.  
  4. local rodLevel = 0
  5. local enPer = 0
  6. local enPerR = 0
  7. local fuel = 0
  8. local fuelPer = 0
  9. local enOut = 0
  10. local fuelCons = 0
  11. local isOn = false
  12. local mon
  13. local enCell
  14. local reactor
  15.  
  16.  
  17. function initPeripherals()
  18.     local perList = peripheral.getNames()
  19.     for i=1,#perList,1 do
  20.         if peripheral.getType(perList[i]) == "monitor" then
  21.             mon = peripheral.wrap(perList[i])
  22.         end
  23.         if peripheral.getType(perList[i]) == "tile_blockcapacitorbank_name" or peripheral.getType(perList[i]) == "tile_thermalexpansion_cell_basic_name" or peripheral.getType(perList[i]) == "tile_thermalexpansion_cell_hardened_name" or peripheral.getType(perList[i]) == "tile_thermalexpansion_cell_reinforced_name" or peripheral.getType(perList[i]) == "tile_thermalexpansion_cell_resonant_name" then
  24.             enCell = peripheral.wrap(perList[i])
  25.         end
  26.         if peripheral.getType(perList[i]) == "BigReactors-Reactor" then
  27.             reactor = peripheral.wrap(perList[i])
  28.             --print("Reaktor gefunden!")
  29.         end
  30.     end
  31. end
  32.  
  33. function getEnergy()
  34.     local en = enCell.getEnergyStored()
  35.     local enMax = enCell.getMaxEnergyStored()
  36.     return math.floor(en/enMax*100)
  37. end
  38.  
  39. function getReactorData()
  40.     rodLevel = reactor.getControlRodLevel(1)
  41.     enPer = getEnergy()
  42.     enPerR = reactor.getEnergyStored()
  43.     fuel = reactor.getFuelAmount()
  44.     local fuelMax = reactor.getFuelAmountMax()
  45.     fuelPer = math.floor(fuel/fuelMax*100)
  46.     enOut = reactor.getEnergyProducedLastTick()
  47.     fuelCons = reactor.getFuelConsumedLastTick()
  48.     isOn = reactor.getActive()
  49. end
  50.  
  51. function displayData()
  52.     term.clear()
  53.     term.setCursorPos(1,1)
  54.     getReactorData()
  55.     print("RodLevel: "..rodLevel)
  56.     print("Energie: "..enPer.."%")
  57.     print("Energie (Reaktor): "..enPerR.."RF")
  58.     print("Fuel: "..fuel.."mb")
  59.     print("Fuel: "..fuelPer.."%")
  60.     print("Energie-Produktion: "..enOut.."RF/t")
  61.     print("Verbrauch: "..fuelCons.."mb/t")
  62.     write("Reaktor an: ")
  63.   if isOn == true then print("ja")
  64.   else print("nein") end
  65.     --sleep(1)
  66. end
  67.  
  68. function displayDataOnScreen()
  69.     --mon.clear()
  70.     mon.setCursorPos(1,1)
  71.     mon.write("Energie: "..enPer.."%   ")
  72.     mon.setCursorPos(1,2)
  73.     mon.write("Energie (Reaktor): "..enPerR.."RF   ")
  74.     mon.setCursorPos(1,4)
  75.     mon.write("Reaktor an: ")
  76.    if isOn == true then mon.write("ja    ")
  77.    else mon.write("nein   ") end
  78.    mon.setCursorPos(1,5)
  79.     mon.write("Fuel: "..fuel.."mb   ")
  80.     mon.setCursorPos(1,6)
  81.     mon.write("in Prozent: "..fuelPer.."%")
  82.     mon.setCursorPos(1,8)
  83.     mon.write("Energie-Produktion: "..math.floor(enOut).."RF/t    ")
  84.     mon.setCursorPos(1,9)
  85.     mon.write("Verbrauch: ")
  86.     local fuelCons2 = tostring(fuelCons)
  87.     local fuelCons3 = string.sub(fuelCons2,0,4)
  88.     mon.write(fuelCons3)
  89.     mon.write("mb/t    ")
  90.  
  91. end
  92.  
  93. initPeripherals()
  94. mon.setBackgroundColor(colors.blue)
  95. mon.clear()
  96. while true do
  97.     getReactorData()
  98.     displayData()
  99.     displayDataOnScreen()
  100.     if fuelPer <= 30 then
  101.         reactor.setActive(false)
  102.     else
  103.         if enPer <= 50 then
  104.             reactor.setActive(true)
  105.         elseif enPer > 90 then
  106.             reactor.setActive(false)
  107.         end
  108.     end
  109.     sleep(1)
  110. end
Add Comment
Please, Sign In to add comment