GladdeSnaak

Untitled

May 11th, 2021 (edited)
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.50 KB | None | 0 0
  1.  
  2. function putNumber (number)
  3. local round = 0
  4. local texts = ""
  5.  
  6. if number >= 1000000000000000000 then
  7. round = (number / 1000000000000000000)
  8. texts = string.sub(round, 0, 5) .. " ERF"
  9. else
  10. if number >= 1000000000000000 then
  11. round = (number / 1000000000000000)
  12. texts = string.sub(round, 0, 5) .. " PRF"
  13. else
  14. if number >= 1000000000000 then
  15. round = (number / 1000000000000)
  16. texts = string.sub(round, 0, 5) .. " TRF"
  17. else
  18. if number >= 1000000000 then
  19. round = (number / 1000000000)
  20. texts = string.sub(round, 0, 5) .. " GRF"
  21. else
  22. if number >= 1000000 then
  23. round = (number / 1000000)
  24. texts = string.sub(round, 0, 5) .. " MRF"
  25. else
  26. if number >= 1000 then
  27. round = (number / 1000)
  28. texts = string.sub(round, 0, 5) .. " kRF"
  29. else
  30. texts = string.sub(number, 0, 5) .. " RF"
  31. end
  32. end
  33. end
  34. end
  35. end
  36. end
  37.  
  38. return texts
  39. end
  40.  
  41.  
  42.  
  43.  
  44. -- Initialize our interface!
  45. -- Find all of our peripherals
  46. monitor = peripheral.wrap("top")
  47. battery = peripheral.find("InductionMatrix")
  48.  
  49. -- Check and bind monitor
  50. if monitor == nil then
  51. error("ER: No screen found to display!")
  52. else
  53. monitor.clear()
  54. term.redirect(monitor)
  55. term.setCursorPos(1, 1)
  56. term.setBackgroundColor(colors.black)
  57. end
  58.  
  59. -- Check if we have a battery
  60. if battery == nil then
  61. error("ER: No battery connected to computer")
  62. end
  63.  
  64. -- Draw our static fill volume box
  65. term.setTextColor(colors.white)
  66. term.setCursorPos(2, 2)
  67. print("+------+")
  68. term.setCursorPos(2, 11)
  69. print("+------+")
  70. for i = 3, 10 do
  71. term.setCursorPos(2, i)
  72. print("|")
  73. term.setCursorPos(9, i)
  74. print("|")
  75. end
  76.  
  77. -- Draw our static interface text
  78. term.setCursorPos(11, 2);
  79. print("Max RF:")
  80. term.setCursorPos(11, 3);
  81. print("Max Thru:")
  82.  
  83. term.setCursorPos(11, 5);
  84. print("Cur In:")
  85. term.setCursorPos(11, 6);
  86. print("Cur Out:")
  87. term.setCursorPos(11, 7);
  88. print("Cur Bal:")
  89.  
  90. term.setCursorPos(11, 9);
  91. print("Stored:")
  92. term.setCursorPos(11, 10);
  93. print("Filled:")
  94. term.setCursorPos(11, 11);
  95. print("Critical:")
  96.  
  97.  
  98. -- Entering our infinite loop of checking the battery
  99. -- This will refresh all information every 2 seconds
  100. alarmIsRinging = false
  101. alarmIsActive = false
  102. alarmCounter = 0
  103.  
  104. while true do
  105.  
  106. -- Get our fixed battery values
  107. batteryMaxCharge = battery.getMaxEnergy()
  108. batteryMaxInOuts = battery.getTransferCap()
  109. putValue(2, putNumber(batteryMaxCharge), colors.lightBlue)
  110. putValue(3, putNumber(batteryMaxInOuts), colors.lightBlue)
  111.  
  112. -- Get our input/output/balance battery values
  113. batteryCurrentIn = battery.getLastInput()
  114. batteryCurrentOut = battery.getLastOutput()
  115. putValue(5, putNumber(batteryCurrentIn), colors.lightBlue)
  116. putValue(6, putNumber(batteryCurrentOut), colors.lightBlue)
  117.  
  118. batteryCurrentBalance = batteryCurrentIn - batteryCurrentOut
  119. batteryCurrentColor = (batteryCurrentBalance >= 0) and colors.green or colors.red
  120. batteryCurrentSign = (batteryCurrentBalance >= 0) and "+" or ""
  121. putValue(7, batteryCurrentSign .. putNumber(batteryCurrentBalance), batteryCurrentColor)
  122.  
  123. -- Get our statistical values
  124. batteryCurrentCharge = battery.getStored()
  125. putValue(9, putNumber(batteryCurrentCharge), colors.lightBlue)
  126.  
  127. batteryCurrentColor = colors.red
  128. batteryCurrentPercentage = ((batteryCurrentCharge / batteryMaxCharge) * 100)
  129. if batteryCurrentPercentage > 30 then batteryCurrentColor = colors.orange end
  130. if batteryCurrentPercentage > 60 then batteryCurrentColor = colors.green end
  131. putValue(10, string.sub(putNumber(batteryCurrentPercentage), 0, 4) .. "%", batteryCurrentColor)
  132.  
  133. batteryCurrentCritical = "Yes"
  134. batteryCurrentColor = colors.red
  135. if batteryCurrentPercentage > 15 then
  136. batteryCurrentCritical = "No"
  137. batteryCurrentColor = colors.green
  138. end
  139. putValue(11, batteryCurrentCritical, batteryCurrentColor)
  140.  
  141. -- Draw the current charge graph
  142. batteryCurrentColor = colors.red
  143. if batteryCurrentPercentage > 30 then term.setTextColor(colors.orange) end
  144. if batteryCurrentPercentage > 60 then term.setTextColor(colors.green) end
  145. if batteryCurrentPercentage >= 100 then term.setTextColor(colors.lightBlue) end
  146.  
  147. for i = 3, 10 do
  148. term.setCursorPos(3, i)
  149. print(" ")
  150. end
  151.  
  152. iterator = 0
  153. for i = 3, 10 do
  154. local compare = (12.5 * iterator)
  155. if (batteryCurrentPercentage >= compare) then
  156. term.setCursorPos(3, (13 - i))
  157. local filler = ""
  158. for i = 1, 6 do
  159. local inhere = (compare + (i*2))
  160. if batteryCurrentPercentage >= inhere then
  161. filler = filler .. "#"
  162. else
  163. if batteryCurrentPercentage >= (inhere - 1) then
  164. filler = filler .. "="
  165. else
  166. filler = filler .. "_"
  167. end
  168. end
  169. end
  170. print(filler)
  171. end
  172.  
  173. iterator = iterator + 1
  174. end
  175.  
  176. -- Hey, ring the alarm!
  177. if batteryCurrentPercentage > 10 then
  178. alarmIsRinging = false
  179. alarmIsActive = false
  180. end
  181.  
  182. if batteryCurrentPercentage < 10 and alarmIsActive == false then
  183. alarmIsRinging = true
  184. alarmIsActive = true
  185. alarmCounter = 0
  186. redstone.setOutput("left", true)
  187. end
  188.  
  189. if alarmIsRinging == true then
  190. alarmCounter = alarmCounter + 1
  191. if alarmCounter >= 10 then
  192. redstone.setOutput("left", false)
  193. alarmIsRinging = false
  194. end
  195. end
  196.  
  197. -- Wait 2s until next iteration
  198. os.sleep(2)
  199.  
  200. end
  201.  
  202.  
Add Comment
Please, Sign In to add comment