Advertisement
Dsemagames

Reactor

Jul 27th, 2015
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.04 KB | None | 0 0
  1. print("running...")
  2.  
  3. cap = peripheral.find("tile_blockcapacitorbank_name")
  4. mon = peripheral.wrap("right")
  5. --mon = peripheral.find("monitor")
  6. rea = peripheral.find("BigReactors-Reactor")
  7.  
  8. local numCapacitors = 2
  9. local enciendeA = 50
  10. local apagaA = 95
  11.  
  12. local energia = 0
  13. local energiaGuardada = 0
  14. local energiaMax = 0
  15. local energiaGuardadaPorCiento = 0
  16. local produccionRF = 0
  17. local usoFuel = 0
  18. local tempCore = 0
  19. local reactorOnline = false
  20.  
  21. function enciende()
  22.  rea.setActive(true)
  23. end
  24.  
  25. function apaga()
  26.  rea.setActive(false)
  27. end
  28.  
  29. function comma_value(cantidad)
  30.  local formateo = cantidad
  31.  local swap = false
  32.  if formateo < 0 then
  33.   formateo = formateo*-1
  34.   swap = true
  35.  end
  36.  while true do
  37.   formateo, k = string.gsub(formateo, "^(%d+)(%d%d%d)",'%1%2')
  38.   if k == 0 then
  39.    break
  40.   end
  41.  end
  42.  if swap then
  43.  formateo = "-"..formateo
  44.  end
  45.  return formateo
  46. end
  47.  
  48. function muestraEnergia()
  49.  mon.clear()
  50.  mon.setCursorPos(1,1)
  51.  mon.write("Usa de Energia: ")
  52.  if energia < 0 then
  53.   mon.setTextColor(colors.red)
  54.  else
  55.   mon.setTextColor(colors.lime)
  56.  end
  57.  mon.write(comma_value(math.floor(energia)).."RF/T")
  58.  mon.setTextColor(colors.white)
  59.  mon.setCursorPos(1,2)
  60.  mon.write("Energia Almacenada: ")
  61.  if energiaGuardadaPorCiento < 55 then
  62.   mon.setTextColor(colors.red)
  63.  elseif energiaGuardadaPorCiento >= 55 and energiaGuardadaPorCiento <= 85 then
  64.   mon.setTextColor(colors.yellow)
  65.  else
  66.   mon.setTextColor(colors.lime)
  67.  end
  68.  mon.write(energiaGuardadaPorCiento.."%")
  69.  mon.setTextColor(colors.white)
  70.  mon.setCursorPos(1,3)
  71.  mon.write("Este Reactor esta: ")
  72.  if reactorOnline then
  73.   mon.setTextColor(colors.lime)
  74.   mon.write("ENCENDIDO")
  75.  else
  76.   mon.setTextColor(colors.red)
  77.   mon.write("APAGADO")
  78.  end
  79.  mon.setTextColor(colors.white)
  80.  mon.setCursorPos(1,4)
  81.  mon.write("Generacion de RedstoneFluix: ")
  82.  mon.setTextColor(colors.lime)
  83.  mon.write(comma_value(math.floor(produccionRF)).."RF/T")
  84.  mon.setTextColor(colors.white)
  85.  mon.setCursorPos(1,5)
  86.  mon.write("Temperatura interna: "..math.floor(tempCore).."c")
  87.  mon.setCursorPos(1,6)
  88.  mon.write("Uso de Combustible: "..usoFuel.."MB/T")
  89. end
  90.  
  91. function compruebaEnergia()
  92.  local energiaTemporal = 0
  93.  energiaGuardada = cap.getEnergyStored()
  94.  energiaMax = cap.getMaxEnergyStored()
  95.  energiaGuardadaPorCiento = math.floor((energiaGuardada/energiaMax)*100)
  96.  produccionRF = rea.getEnergyProducedLastTick()
  97.  usoFuel = rea.getFuelConsumedLastTick()
  98.  usoFuel = math.floor(usoFuel*100)
  99.  usoFuel = usoFuel/100
  100.  tempCore = rea.getFuelTemperature()
  101.  reactorOnline = rea.getActive()
  102.  energiaTemporal = cap.getEnergyStored()
  103.  sleep(0.1)
  104.  energia = (cap.getEnergyStored()-energiaTemporal)/2
  105.  energia = energia*numCapacitors
  106. end
  107.  
  108. function autoReactor()
  109.  rea.setAllControlRodLevels(0)
  110.  if energiaGuardadaPorCiento < enciendeA then
  111.   if not reactorOnline then
  112.    enciende()
  113.   end
  114.  end
  115.  if energiaGuardadaPorCiento > apagaA then
  116.   apaga()
  117.  end
  118. end
  119.  
  120. function muestraInfo()
  121.  compruebaEnergia()
  122.  muestraEnergia()
  123.  autoReactor()
  124. end
  125.  
  126. while true do
  127.  muestraInfo()
  128.  sleep(5)
  129. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement