Advertisement
Guest User

startup

a guest
Nov 15th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.93 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.  
  47.  
  48.  
  49.  
  50. -- Initialize our interface!
  51. -- Find all of our peripherals
  52. monitor = peripheral.wrap("bottom")
  53. battery = peripheral.find("warpdriveForceFieldProjector")
  54.  
  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.   print("     Shield Information")
  64. end
  65.  
  66. -- Check if we have a battery
  67. if battery == nil then
  68.   error("ER: No battery connected to computer")
  69. end
  70.  
  71. -- Draw our static fill volume box
  72. term.setTextColor(colors.white)
  73. term.setCursorPos(2, 2)
  74. print("+------+")
  75. term.setCursorPos(2, 11)
  76. print("+------+")
  77. for i = 3, 10 do
  78.   term.setCursorPos(2, i)
  79.   print("|")
  80.   term.setCursorPos(9, i)
  81.   print("|")
  82. end
  83.  
  84. -- Draw our static interface text
  85. term.setCursorPos(11, 2);
  86. print("Shield:")
  87. term.setCursorPos(11, 3);
  88. print("Tier:")
  89.  
  90. term.setCursorPos(11, 5);
  91. print("Valid:")
  92. term.setCursorPos(11, 6);
  93. print("Controls:")
  94. term.setCursorPos(11, 7);
  95. print("Enable Disable")
  96.  
  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 battery
  106. -- This will refresh all information every 2 seconds
  107. alarmIsRinging = false
  108. alarmIsActive = false
  109. alarmCounter = 0
  110. isAssemblyValid = battery.getAssemblyStatus()
  111. energyStored, energyMax, energyUnits = battery.getEnergyStatus()
  112. isEnabled = battery.enable()
  113. tier = battery.getTier()
  114. name = battery.name()
  115. while true do
  116.  
  117.   -- Get our input/output/balance battery values
  118.   if not isAssemblyValid then
  119.   batteryCurrentIn = "Invalid"
  120.   putValue(5, batteryCurrentIn, colors.red)
  121.   --batteryCurrentIn = "Invalid"
  122.   else
  123.   batteryCurrentIn = "Valid"
  124.   putValue(5, batteryCurrentIn, colors.green)
  125.   --batteryCurrentIn = "Valid"
  126.   end
  127.   --batteryCurrentOut = battery.getOutput()
  128.  -- putValue(5, batteryCurrentIn, colors.lightBlue)
  129. --  putValue(6, putNumber(batteryCurrentOut), colors.lightBlue)
  130.  
  131. --  batteryCurrentBalance = batteryCurrentIn - batteryCurrentOut
  132. --  batteryCurrentColor = (batteryCurrentBalance >= 0) and colors.green or colors.red
  133. --  batteryCurrentSign = (batteryCurrentBalance >= 0) and "+" or ""
  134.   if tier == 1 then
  135.   tier1 = "Basic"
  136.   elseif tier == 2 then
  137.   tier1 = "Advanced"
  138.   else
  139.   tier1 = "Superior"
  140.   end
  141.   putValue(3, tier1, colors.green)
  142.   putValue(2, name, colors.green)
  143.   -- Get our statistical values
  144.   batteryCurrentCharge = energyStored
  145.   putValue(9, putNumber(energyStored), colors.lightBlue)
  146.  
  147.   batteryCurrentColor = colors.red
  148.   batteryCurrentPercentage = ((energyStored / energyMax) * 100)
  149.   if batteryCurrentPercentage > 30 then batteryCurrentColor = colors.orange end
  150.   if batteryCurrentPercentage > 60 then batteryCurrentColor = colors.green end
  151.   putValue(10, string.sub(putNumber(batteryCurrentPercentage), 0, 4) .. "%", batteryCurrentColor)
  152.  
  153.   batteryCurrentCritical = "Yes"
  154.   batteryCurrentColor = colors.red
  155.   if batteryCurrentPercentage > 15 then
  156.     batteryCurrentCritical = "No"
  157.     batteryCurrentColor = colors.green
  158.   end
  159.   putValue(11, batteryCurrentCritical, batteryCurrentColor)
  160.  
  161.   -- Draw the current charge graph
  162.   batteryCurrentColor = colors.red
  163.   if batteryCurrentPercentage > 30 then term.setTextColor(colors.orange) end
  164.   if batteryCurrentPercentage > 60 then term.setTextColor(colors.green) end
  165.   if batteryCurrentPercentage >= 100 then term.setTextColor(colors.green) end
  166.  
  167.   for i = 3, 10 do
  168.     term.setCursorPos(3, i)
  169.     print("      ")
  170.   end
  171.  
  172.   iterator = 0
  173.   for i = 3, 10 do
  174.     local compare = (12.5 * iterator)
  175.     if (batteryCurrentPercentage >= compare) then
  176.       term.setCursorPos(3, (13 - i))
  177.       local filler = ""
  178.       for i = 1, 6 do
  179.         local inhere = (compare + (i*2))
  180.         if batteryCurrentPercentage >= inhere then
  181.           filler = filler .. "#"
  182.         else
  183.           if batteryCurrentPercentage >= (inhere - 1) then
  184.             filler = filler .. "="
  185.           else
  186.             filler = filler .. "_"
  187.           end
  188.         end
  189.       end
  190.       print(filler)
  191.     end
  192.  
  193.     iterator = iterator + 1
  194.   end
  195.  
  196.   -- Hey, ring the alarm!
  197.   if batteryCurrentPercentage > 10 then
  198.     alarmIsRinging = false
  199.     alarmIsActive = false
  200.   end
  201.  
  202.   if batteryCurrentPercentage < 10 and alarmIsActive == false then
  203.     alarmIsRinging = true
  204.     alarmIsActive = true
  205.     alarmCounter = 0
  206.     redstone.setOutput("left", true)
  207.   end
  208.  
  209.   if alarmIsRinging == true then
  210.     alarmCounter = alarmCounter + 1
  211.     if alarmCounter >= 10 then
  212.       redstone.setOutput("left", false)
  213.       alarmIsRinging = false
  214.     end
  215.   end
  216.  
  217.   -- Wait 2s until next iteration
  218.   os.sleep(2)
  219.  
  220. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement