homerjunior

Energy Monitor 17 Cells

Jun 29th, 2014
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.91 KB | None | 0 0
  1. --[[
  2. Simple Energy storage display for redstone energy cells
  3. and on-demand engine control
  4. The engine control part is optional, don't connect a rednet
  5. cable if you only want to display energy storage.
  6.  
  7. by got_m1lk
  8. --]]
  9.  
  10. --Specify side of wired modem
  11. -- Valid: "left", "right", "front", "back", "top", "bottom"
  12. local modemside = "bottom"
  13.  
  14. --Specify side of rednet cable
  15. local rednetside = "back"
  16.  
  17. --Specify side of monitor
  18. --If the monitor is attached to the modem specify peripheral-ID instead.
  19. local monitorside = "top"
  20.  
  21. --Adjust the textscale if you have a bigger/smaller monitor
  22. --Increments of 0.5
  23. local textsize = 1
  24.  
  25. --Specify at what percentage the engines turn on
  26. local min = 15
  27.  
  28. --Specify at what percentage the engines turn off
  29. local max = 70
  30.  
  31. --Specify the peripheral-IDs of you redstone cells
  32. --Remove/add units from the table to fit it to the amount
  33. -- of cells you are using
  34. local storageUnits = {
  35. {
  36. ["id"] = "redstone_energy_cell_86",
  37. ["name"] = "Cell1"
  38. },
  39. {
  40. ["id"] = "redstone_energy_cell_87",
  41. ["name"] = "Cell2"
  42. },
  43. {
  44. ["id"] = "redstone_energy_cell_88",
  45. ["name"] = "Cell3"
  46. },
  47. {
  48. ["id"] = "redstone_energy_cell_89",
  49. ["name"] = "Cell4"
  50. },
  51. {
  52. ["id"] = "redstone_energy_cell_90",
  53. ["name"] = "Cell5"
  54. },
  55. {
  56. ["id"] = "redstone_energy_cell_91",
  57. ["name"] = "Cell6"
  58. },
  59. {
  60. ["id"] = "redstone_energy_cell_92",
  61. ["name"] = "Cell7"
  62. },
  63. {
  64. ["id"] = "redstone_energy_cell_93",
  65. ["name"] = "Cell8"
  66. },
  67. {
  68. ["id"] = "redstone_energy_cell_94",
  69. ["name"] = "Cell9"
  70. },
  71. {
  72. ["id"] = "redstone_energy_cell_95",
  73. ["name"] = "Cell10"
  74. },
  75. {
  76. ["id"] = "redstone_energy_cell_96",
  77. ["name"] = "Cell11"
  78. },
  79. {
  80. ["id"] = "redstone_energy_cell_97",
  81. ["name"] = "Cell12"
  82. },
  83. {
  84. ["id"] = "redstone_energy_cell_98",
  85. ["name"] = "Cell13"
  86. },
  87. {
  88. ["id"] = "redstone_energy_cell_99",
  89. ["name"] = "Cell14"
  90. },
  91. {
  92. ["id"] = "redstone_energy_cell_100",
  93. ["name"] = "Cell15"
  94. },
  95. {
  96. ["id"] = "redstone_energy_cell_101",
  97. ["name"] = "Cell16"
  98. },
  99. {
  100. ["id"] = "redstone_energy_cell_102",
  101. ["name"] = "Cell17"
  102. },
  103. {
  104. ["id"] = "redstone_energy_cell_103",
  105. ["name"] = "Cell18"
  106. },
  107. {
  108. ["id"] = "redstone_energy_cell_104",
  109. ["name"] = "Cell19"
  110. },
  111. {
  112. ["id"] = "redstone_energy_cell_105",
  113. ["name"] = "Cell20"
  114. },
  115. {
  116. ["id"] = "redstone_energy_cell_106",
  117. ["name"] = "Cell21"
  118. },
  119. {
  120. ["id"] = "redstone_energy_cell_107",
  121. ["name"] = "Cell22"
  122. },
  123. {
  124. ["id"] = "redstone_energy_cell_108",
  125. ["name"] = "Cell23"
  126. },
  127. {
  128. ["id"] = "redstone_energy_cell_109",
  129. ["name"] = "Cell24"
  130. },
  131. {
  132. ["id"] = "redstone_energy_cell_110",
  133. ["name"] = "Cell25"
  134. },
  135. {
  136. ["id"] = "redstone_energy_cell_111",
  137. ["name"] = "Cell26"
  138. },
  139. {
  140. ["id"] = "redstone_energy_cell_112",
  141. ["name"] = "Cell27"
  142. },
  143. {
  144. ["id"] = "redstone_energy_cell_113",
  145. ["name"] = "Cell28"
  146. },
  147. {
  148. ["id"] = "redstone_energy_cell_114",
  149. ["name"] = "Cell29"
  150. }
  151.  
  152. }
  153.  
  154. local mon = peripheral.wrap(monitorside)
  155. local net = peripheral.wrap(modemside)
  156.  
  157.  
  158. mon.clear()
  159. mon.setTextScale(textsize)
  160. mon.setTextColor(512)
  161. mon.setCursorPos(1,2)
  162. mon.write(" Energy Remaining:")
  163. mon.setCursorPos(1,10)
  164. mon.write(" Engine Status:")
  165. mon.setTextColor(2)
  166. rs.setBundledOutput(rednetside,colors.black)
  167.  
  168. while true do
  169.  
  170. capacity = 0
  171. amount = 0
  172.  
  173. for i=#storageUnits,1,-1 do
  174. storageUnit = storageUnits[i]
  175. capacity = capacity + net.callRemote(storageUnit["id"], "getMaxEnergyStored")
  176. amount = amount + net.callRemote(storageUnit["id"], "getEnergyStored")
  177. end
  178.  
  179.  
  180. percentage = tonumber((amount / capacity) *100)
  181. percentage = math.floor(percentage)
  182.  
  183.  
  184. if percentage <= min then
  185. rs.setBundledOutput(rednetside,colors.white)
  186. end
  187.  
  188. if percentage >= max then
  189. rs.setBundledOutput(rednetside,colors.black)
  190. end
  191.  
  192.  
  193. percentage = string.match(tostring(percentage),'[^%.]+')
  194. mon.setCursorPos(8,4)
  195. mon.clearLine()
  196. mon.setTextColor(2)
  197. mon.write(percentage .. "%")
  198. mon.setCursorPos(1,6)
  199. mon.clearLine()
  200. mon.setTextColor(512)
  201. mon.write("Energy: ")
  202. mon.setTextColor(2)
  203. mon.write(string.match(tostring(amount),'[^%.]+') .. " MJ")
  204. mon.setCursorPos(1,7)
  205. mon.clearLine()
  206. mon.setTextColor(512)
  207. mon.write(" Size: ")
  208. mon.setTextColor(2)
  209. mon.write(string.match(tostring(capacity),'[^%.]+') .." MJ")
  210.  
  211. if rs.getBundledInput(rednetside) == colors.black then
  212. mon.setTextColor(colors.red)
  213. mon.setCursorPos(8,11)
  214. mon.write("OFF")
  215. elseif rs.getBundledInput(rednetside) == colors.white then
  216. mon.setTextColor(colors.lime)
  217. mon.setCursorPos(8,11)
  218. mon.write(" ON")
  219. end
  220.  
  221.  
  222. sleep(1)
  223. end
Advertisement
Add Comment
Please, Sign In to add comment