Advertisement
Guest User

test

a guest
Aug 14th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.06 KB | None | 0 0
  1. -- # load the touchpoint API
  2. -- os.loadAPI("touchpoint")
  3.  
  4. -- ## Fucntions ##
  5.  
  6. -- check over mil
  7. function formatNum(num)
  8.   if num >= 1000000 then
  9.     num = math.floor((num / 1000000) * 10) / 10
  10.     num = tostring(num) .. " M"
  11.   end
  12.   return num
  13. end
  14.  
  15. -- next line
  16. function nextLine()
  17.   y = y + 1
  18.   screen.setCursorPos(x, y)
  19. end
  20.  
  21. -- ## Pre setup ##
  22.  
  23. -- setup connections
  24. screen = peripheral.find("monitor")
  25. cell = peripheral.find("tile_thermalexpansion_cell_resonant_name")
  26. reactor = peripheral.find("BigReactors-Reactor")
  27.  
  28. -- check connections
  29. print(cell)
  30.  
  31. if cell == nil then
  32.   print("ERROR: please connect an energy cell")
  33. else
  34.   print("found energy cell")
  35. end
  36. print()
  37.  
  38. print(screen)
  39.  
  40. if screen == nil then
  41.   print("ERROR: please connect a monitor")
  42. else
  43.   print("found monitor")
  44.   -- t = touchpoint.new("monitor_0")
  45. end
  46. print()
  47.  
  48. print(reactor)
  49.  
  50. if reactor == nil then
  51.   print("ERROR: please connect a reactor")
  52. else
  53.   print("found reator")
  54. end
  55. print()
  56.  
  57. -- ## Buttons ##
  58. -- t:add("big_button", nil, 2, 2, 3, 3, colors.red, colors.green)
  59. -- t:draw()
  60.  
  61. while true do
  62.  
  63. -- ## Code ##
  64. x, y = 1, 1
  65.  
  66. -- setup monitor
  67. screen.clear()
  68. screen.setTextScale(1)
  69. screen.setCursorPos(x,y)
  70.  
  71. -- get reactor status
  72. status = reactor.getActive()
  73. screen.setTextColor(colors.white)
  74. screen.write("Status: ")
  75. if status == true then
  76.   screen.setTextColor(colors.green)
  77.   screen.write("Active")
  78. else
  79.   screen.setTextColor(colors.red)
  80.   screen.write("Non active")
  81. end
  82. nextLine()
  83.  
  84. -- get production
  85. production = math.floor(reactor.getEnergyProducedLastTick() * 10) / 10
  86. nextLine()
  87. screen.setTextColor(colors.white)
  88. screen.write("RF/tik: ")
  89. screen.setTextColor(colors.green)
  90. screen.write(production)
  91.  
  92. -- get energy amounts
  93. curRfCell = cell.getEnergyStored()
  94. curRfReactor = reactor.getEnergyStored()
  95.  
  96. maxRfCell = cell.getMaxEnergyStored()
  97. maxRfReactor = 10000000
  98.  
  99. -- edit numbers
  100. cur = formatNum(curRfCell + curRfReactor)
  101. max = formatNum(maxRfCell + maxRfReactor)
  102.  
  103. -- print out
  104. print("curent: " .. cur .. " RF")
  105. print("maximum: " .. max .. " RF")
  106.  
  107. -- show on screen
  108. nextLine()
  109. screen.setTextColor(colors.white)
  110. screen.write("Curent: ")
  111. screen.setTextColor(colors.green)
  112. screen.write(cur .. " RF")
  113.  
  114. nextLine()
  115. screen.setTextColor(colors.white)
  116. screen.write("Maximum: ")
  117. screen.setTextColor(colors.green)
  118. screen.write(max .. " RF")
  119.  
  120. -- percent
  121. percent = math.floor((curRfCell / maxRfCell) * 100 * 100) / 100
  122.  
  123. -- print out
  124. print(tostring(percent).."%")
  125.  
  126. -- show on screen
  127. nextLine()
  128. screen.setTextColor(colors.white)
  129. screen.write("Percent: ")
  130. screen.setTextColor(colors.green)
  131. screen.write(percent .. " %")
  132.  
  133. -- fuel
  134. curFuel = reactor.getFuelAmount()
  135. maxFuel = reactor.getFuelAmountMax()
  136.  
  137. percentFuel = math.floor((curFuel / maxFuel) * 100) / 100
  138.  
  139. nextLine()
  140. screen.setTextColor(colors.white)
  141. screen.write("Fuel: ")
  142. screen.setTextColor(colors.green)
  143. screen.write(percentFuel .. " %")
  144.  
  145. -- check numbers
  146. if percent > 90 then
  147.   reactor.setActive(false)
  148. end
  149.  
  150. if percent < 10 then
  151.   reactor.setActive(true)
  152.  
  153. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement