Advertisement
RLPGhost

Lua Control Reactor

Mar 18th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.25 KB | None | 0 0
  1. local tank = peripheral.wrap("back")
  2. local modem = peripheral.wrap("left")
  3. local wifi = peripheral.wrap("top")
  4. local reactor = peripheral.wrap("BigReactors-Reactor_1")
  5. local turbine = peripheral.wrap("BigReactors-Turbine_1")
  6. local capacitor = peripheral.wrap("tile_blockcapacitorbank_name_1")
  7.  
  8. local cap                -- Tank capacity
  9. local amount             -- Amount liquid in tank
  10. local percentfull        -- Percent liquid in tank
  11.  
  12. local rodLevel = 0
  13. local minRodLevel = 55
  14. local maxRodLevel = 65
  15.  
  16. local enderMonitorRedstone = false
  17.  
  18. local rpmTurbine = 0
  19. local minRpmTurbine = 1700
  20. local maxRpmTurbine = 1800
  21.  
  22.  
  23. local nbSlot = 18
  24.  
  25.  
  26. function getTank(tankPeriph)
  27.     local tableInfo = tankPeriph.getTankInfo("unknown") -- Local to the getTank function.
  28.  
  29.     fluidRaw = nil
  30.     fluidName = nil
  31.     fluidAmount = nil
  32.     fluidCapacity = nil
  33.      
  34.     for k,v in pairs(tableInfo) do
  35.       fluidCapacity = v.capacity
  36.  
  37.       if v.contents then
  38.         for i,w in pairs(v.contents) do
  39.           if i == "rawName" then
  40.             fluidRaw = w
  41.           elseif i == "amount" then
  42.             fluidAmount = w
  43.           elseif i == "name" then
  44.             fluidName = w
  45.           end
  46.         end
  47.       end
  48.     end
  49.  
  50.     return fluidRaw, fluidName, fluidAmount, fluidCapacity -- Returning the values of global variables (which are nil).
  51. end
  52.  
  53.  
  54. --// Programme de controle reacteur
  55.  
  56.  
  57. while true do
  58.  
  59. local fluidRaw, fluidName, fluidAmount, fluidCapacity = getTank(tank)
  60.  
  61. if fluidName then
  62.     -- Get values for tank capacity and amount
  63.     fluidName = string.gsub(fluidName, "^%l", string.upper)
  64.     cap = fluidCapacity / 1000
  65.     amount = fluidAmount
  66. end
  67.  
  68. if amount == nil then
  69.       amount = 0
  70.       percentfull = 0
  71.     else
  72.       -- Use math.floor to convert to integers
  73.       amount = math.floor(amount / 1000)
  74.       percentfull = math.floor(100 * amount / cap)
  75. end
  76.  
  77.    
  78. if percentfull < 40 then
  79.     reactor.setActive(true)
  80.     rodLevel = minRodLevel
  81.     reactor.setAllControlRodLevels(rodLevel)
  82.    
  83. end
  84.  
  85. if percentfull > 60 then
  86.     rodLevel = maxRodLevel
  87.     reactor.setAllControlRodLevels(rodLevel)
  88.    
  89. end
  90.  
  91. if percentfull > 75 then
  92.     reactor.setActive(false)
  93. end
  94.  
  95. enderMonitorRedstone = redstone.getInput("right")
  96.  
  97. if enderMonitorRedstone then
  98.     turbine.setInductorEngaged (true)
  99.     else
  100.     turbine.setInductorEngaged (false)
  101. end
  102.  
  103. rpmTurbine = turbine.getRotorSpeed()
  104.  
  105. if rpmTurbine < minRpmTurbine then
  106.     turbine.setActive(true)
  107. end
  108.  
  109. if rpmTurbine > maxRpmTurbine then
  110.     turbine.setActive(false)
  111. end
  112.  
  113. capacitorEnergy = capacitor.getEnergyStored("unknown") * nbSlot
  114. capacitorEnergyMax = capacitor.getMaxEnergyStored("unknown") * nbSlot
  115. percentcelule = math.floor(100 * capacitorEnergy / capacitorEnergyMax )
  116.  
  117.  
  118. local tableau = {reacteur = reactor.getActive(), barreLevel = reactor.getControlRodLevel(1),conso = reactor.getFuelConsumedLastTick() ,steam = amount , capacity = cap , percent = percentfull, turbine = turbine.getActive() , rpm = rpmTurbine , electroAimant = turbine.getInductorEngaged() , energy = capacitorEnergy, energyMax = capacitorEnergyMax , celpercent = percentcelule , energyProduct = turbine.getEnergyProducedLastTick()}
  119. local sendmsg = textutils.serialize(tableau)
  120.  
  121. wifi.transmit(2,0,sendmsg)
  122.  
  123. sleep(2)
  124.  
  125. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement