Advertisement
infiniteblock

Untitled

Nov 15th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.49 KB | None | 0 0
  1. function putValue (line, text, color)
  2. local align = 30 - string.len(text)
  3. term.setCursorPos(align, line)
  4. term.setTextColor(color)
  5. print(text)
  6. end
  7.  
  8. function putNumber (number)
  9. local round = 0
  10. local texts = ""
  11.  
  12. if number >= 1000000000000000000 then
  13. round = (number / 1000000000000000000)
  14. texts = string.sub(round, 0, 5) .. " ERF"
  15. else
  16. if number >= 1000000000000000 then
  17. round = (number / 1000000000000000)
  18. texts = string.sub(round, 0, 5) .. " PRF"
  19. else
  20. if number >= 1000000000000 then
  21. round = (number / 1000000000000)
  22. texts = string.sub(round, 0, 5) .. " TRF"
  23. else
  24. if number >= 1000000000 then
  25. round = (number / 10000000000)
  26. texts = string.sub(round, 0, 5) .. " GRF"
  27. else
  28. if number >= 1000000 then
  29. round = (number / 10000000)
  30. texts = string.sub(round, 0, 5) .. " MRF"
  31. else
  32. if number >= 1000 then
  33. round = (number / 1000)
  34. texts = string.sub(round, 0, 5) .. " kRF"
  35. else
  36. texts = string.sub(number, 0, 5) .. " RF"
  37. end
  38. end
  39. end
  40. end
  41. end
  42. end
  43.  
  44. return texts
  45. end
  46. local Uri = ""
  47. monitor = peripheral.find("monitor")
  48. projector = peripheral.find("warpdriveForceFieldProjector")
  49. if projector.name() == "" then -- if navdata wasnt loaded
  50. print("Enter Shield Name:")
  51. local input = read()
  52. local n=input
  53. projector.name(n)
  54. end
  55. -- Check and bind monitor
  56. if monitor == nil then
  57. error("ER: No screen found to display!")
  58. else
  59. monitor.clear()
  60. term.redirect(monitor)
  61. term.setCursorPos(1, 1)
  62. term.setBackgroundColor(colors.black)
  63. term.setTextColor(colors.red)
  64. print(" Shield Information")
  65. end
  66.  
  67. -- Check if we have a projector
  68. if projector == nil then
  69. error("ER: No projector connected to computer")
  70. end
  71.  
  72. -- Draw our static fill volume box
  73. term.setTextColor(colors.white)
  74. term.setCursorPos(2, 2)
  75. print("+------+")
  76. term.setCursorPos(2, 11)
  77. print("+------+")
  78. for i = 3, 10 do
  79. term.setCursorPos(2, i)
  80. print("|")
  81. term.setCursorPos(9, i)
  82. print("|")
  83. end
  84.  
  85. -- Draw our static interface text
  86. term.setCursorPos(11, 2);
  87. print("Shield:")
  88. term.setCursorPos(11, 3);
  89. print("Tier:")
  90.  
  91. term.setCursorPos(11, 5);
  92. print("Valid:")
  93. term.setCursorPos(11, 6);
  94. print("Controls:")
  95. --term.setCursorPos(11, 7);
  96. --print("Enable Disable")
  97. term.setCursorPos(11, 9);
  98. print("Stored:")
  99. term.setCursorPos(11, 10);
  100. print("Filled:")
  101. term.setCursorPos(11, 11);
  102. print("Critical:")
  103.  
  104.  
  105. -- Entering our infinite loop of checking the projector
  106. -- This will refresh all information every 2 seconds
  107. alarmIsRinging = false
  108. alarmIsActive = false
  109. alarmCounter = 0
  110. isAssemblyValid = projector.getAssemblyStatus()
  111. energyStored, energyMax, energyUnits = projector.getEnergyStatus()
  112. --isEnabled = projector.enable()
  113. tier = projector.getTier()
  114. name = projector.name()
  115. if tier == 1 then
  116. tier1 = "Basic"
  117. elseif tier == 2 then
  118. tier1 = "Advanced"
  119. else
  120. tier1 = "Superior"
  121. end
  122. while true do
  123. on = redstone.getAnalogInput("front")
  124. if on > 6 then
  125. if isEnabled == true then
  126. --putValue(6, "Skipping", colors.green)
  127. else
  128. projector.enable(true)
  129. isEnabled = true
  130. putValue(6," Enabled!", colors.green)
  131. http.post(Uri,"{\"content\":\"```yaml\\nShield: "..name.." \\nTier: "..tier1.." \\nEnergy: "..putNumber(energyStored).." \\nStatus: Enabled```\"}",{['content-type']="application/json"})
  132. end
  133. elseif on < 5 then
  134. if isEnabled == false then
  135. else
  136. projector.enable(false)
  137. isEnabled = false
  138. putValue(6,"Disabled!", colors.red)
  139. http.post(Uri,"{\"content\":\"```yaml\\nShield: "..name.." \\nTier: "..tier1.." \\nEnergy: "..putNumber(energyStored).." \\nStatus: Disabled```\"}",{['content-type']="application/json"})
  140. end
  141. -- Get our input/output/balance projector values
  142. if not isAssemblyValid then
  143. projectorCurrentIn = "Invalid"
  144. putValue(5, projectorCurrentIn, colors.red)
  145. else
  146. projectorCurrentIn = "Valid"
  147. putValue(5, projectorCurrentIn, colors.green)
  148. end
  149. putValue(3, tier1, colors.green)
  150. putValue(2, name, colors.green)
  151. -- Get our statistical values
  152. projectorCurrentCharge = energyStored
  153. putValue(9, putNumber(energyStored), colors.lightBlue)
  154.  
  155. projectorCurrentColor = colors.red
  156. projectorCurrentPercentage = ((energyStored / energyMax) * 100)
  157. if projectorCurrentPercentage > 30 then projectorCurrentColor = colors.orange end
  158. if projectorCurrentPercentage > 60 then projectorCurrentColor = colors.green end
  159. putValue(10, string.sub(putNumber(projectorCurrentPercentage), 0, 4) .. "%", projectorCurrentColor)
  160.  
  161. projectorCurrentCritical = "Yes"
  162. projectorCurrentColor = colors.red
  163. if projectorCurrentPercentage > 15 then
  164. projectorCurrentCritical = "No"
  165. projectorCurrentColor = colors.green
  166. end
  167. putValue(11, projectorCurrentCritical, projectorCurrentColor)
  168.  
  169. -- Draw the current charge graph
  170. projectorCurrentColor = colors.red
  171. if projectorCurrentPercentage > 30 then term.setTextColor(colors.orange) end
  172. if projectorCurrentPercentage > 60 then term.setTextColor(colors.green) end
  173. if projectorCurrentPercentage >= 100 then term.setTextColor(colors.green) end
  174.  
  175. for i = 3, 10 do
  176. term.setCursorPos(3, i)
  177. print(" ")
  178. end
  179.  
  180. iterator = 0
  181. for i = 3, 10 do
  182. local compare = (12.5 * iterator)
  183. if (projectorCurrentPercentage >= compare) then
  184. term.setCursorPos(3, (13 - i))
  185. local filler = ""
  186. for i = 1, 6 do
  187. local inhere = (compare + (i*2))
  188. if projectorCurrentPercentage >= inhere then
  189. filler = filler .. "#"
  190. else
  191. if projectorCurrentPercentage >= (inhere - 1) then
  192. filler = filler .. "="
  193. else
  194. filler = filler .. "_"
  195. end
  196. end
  197. end
  198. print(filler)
  199. end
  200.  
  201. iterator = iterator + 1
  202. end
  203.  
  204. -- Hey, ring the alarm!
  205. if projectorCurrentPercentage > 10 then
  206. alarmIsRinging = false
  207. alarmIsActive = false
  208. end
  209.  
  210. if projectorCurrentPercentage < 10 and alarmIsActive == false then
  211. alarmIsRinging = true
  212. alarmIsActive = true
  213. alarmCounter = 0
  214. redstone.setOutput("left", true)
  215. end
  216.  
  217. if alarmIsRinging == true then
  218. alarmCounter = alarmCounter + 1
  219. if alarmCounter >= 10 then
  220. redstone.setOutput("left", false)
  221. alarmIsRinging = false
  222. end
  223. end
  224.  
  225. -- Wait 2s until next iteration
  226. os.sleep(2)
  227.  
  228. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement