SHARE
TWEET

startup

a guest Nov 15th, 2019 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. term.setCursorPos(11, 9);
  97. print("Stored:")
  98. term.setCursorPos(11, 10);
  99. print("Filled:")
  100. term.setCursorPos(11, 11);
  101. print("Critical:")
  102.  
  103.  
  104. -- Entering our infinite loop of checking the battery
  105. -- This will refresh all information every 2 seconds
  106. alarmIsRinging = false
  107. alarmIsActive = false
  108. alarmCounter = 0
  109. isAssemblyValid = battery.getAssemblyStatus()
  110. energyStored, energyMax, energyUnits = battery.getEnergyStatus()
  111. --isEnabled = battery.enable()
  112. tier = battery.getTier()
  113. name = battery.name()
  114. while true do
  115.     on = redstone.getAnalogInput("right")
  116.     if on > 6 then
  117.     term.setCursorPos(11, 7);
  118.     term.setTextColor(colors.green)
  119.     if isEnabled == true then
  120.     --putValue(6, "Skipping", colors.green)
  121.     else
  122.     battery.enable(true)
  123.     isEnabled = true
  124.     end
  125.     putValue(6,"  Enabled!", colors.green)
  126.     elseif on < 5 then
  127.     term.setCursorPos(11, 7);
  128.     term.setTextColor(colors.red)
  129.     battery.enable(false)
  130.     putValue(6,"Disabled!", colors.red)
  131.     end
  132.   -- Get our input/output/balance battery values
  133.   if not isAssemblyValid then
  134.   batteryCurrentIn = "Invalid"
  135.   putValue(5, batteryCurrentIn, colors.red)
  136.   else
  137.   batteryCurrentIn = "Valid"
  138.   putValue(5, batteryCurrentIn, colors.green)
  139.   end
  140.   --batteryCurrentOut = battery.getOutput()
  141.  -- putValue(5, batteryCurrentIn, colors.lightBlue)
  142. --  putValue(6, putNumber(batteryCurrentOut), colors.lightBlue)
  143.  
  144. --  batteryCurrentBalance = batteryCurrentIn - batteryCurrentOut
  145. --  batteryCurrentColor = (batteryCurrentBalance >= 0) and colors.green or colors.red
  146. --  batteryCurrentSign = (batteryCurrentBalance >= 0) and "+" or ""
  147.   if tier == 1 then
  148.   tier1 = "Basic"
  149.   elseif tier == 2 then
  150.   tier1 = "Advanced"
  151.   else
  152.   tier1 = "Superior"
  153.   end
  154.   putValue(3, tier1, colors.green)
  155.   putValue(2, name, colors.green)
  156.   -- Get our statistical values
  157.   batteryCurrentCharge = energyStored
  158.   putValue(9, putNumber(energyStored), colors.lightBlue)
  159.  
  160.   batteryCurrentColor = colors.red
  161.   batteryCurrentPercentage = ((energyStored / energyMax) * 100)
  162.   if batteryCurrentPercentage > 30 then batteryCurrentColor = colors.orange end
  163.   if batteryCurrentPercentage > 60 then batteryCurrentColor = colors.green end
  164.   putValue(10, string.sub(putNumber(batteryCurrentPercentage), 0, 4) .. "%", batteryCurrentColor)
  165.  
  166.   batteryCurrentCritical = "Yes"
  167.   batteryCurrentColor = colors.red
  168.   if batteryCurrentPercentage > 15 then
  169.     batteryCurrentCritical = "No"
  170.     batteryCurrentColor = colors.green
  171.   end
  172.   putValue(11, batteryCurrentCritical, batteryCurrentColor)
  173.  
  174.   -- Draw the current charge graph
  175.   batteryCurrentColor = colors.red
  176.   if batteryCurrentPercentage > 30 then term.setTextColor(colors.orange) end
  177.   if batteryCurrentPercentage > 60 then term.setTextColor(colors.green) end
  178.   if batteryCurrentPercentage >= 100 then term.setTextColor(colors.green) end
  179.  
  180.   for i = 3, 10 do
  181.     term.setCursorPos(3, i)
  182.     print("      ")
  183.   end
  184.  
  185.   iterator = 0
  186.   for i = 3, 10 do
  187.     local compare = (12.5 * iterator)
  188.     if (batteryCurrentPercentage >= compare) then
  189.       term.setCursorPos(3, (13 - i))
  190.       local filler = ""
  191.       for i = 1, 6 do
  192.         local inhere = (compare + (i*2))
  193.         if batteryCurrentPercentage >= inhere then
  194.           filler = filler .. "#"
  195.         else
  196.           if batteryCurrentPercentage >= (inhere - 1) then
  197.             filler = filler .. "="
  198.           else
  199.             filler = filler .. "_"
  200.           end
  201.         end
  202.       end
  203.       print(filler)
  204.     end
  205.  
  206.     iterator = iterator + 1
  207.   end
  208.  
  209.   -- Hey, ring the alarm!
  210.   if batteryCurrentPercentage > 10 then
  211.     alarmIsRinging = false
  212.     alarmIsActive = false
  213.   end
  214.  
  215.   if batteryCurrentPercentage < 10 and alarmIsActive == false then
  216.     alarmIsRinging = true
  217.     alarmIsActive = true
  218.     alarmCounter = 0
  219.     redstone.setOutput("left", true)
  220.   end
  221.  
  222.   if alarmIsRinging == true then
  223.     alarmCounter = alarmCounter + 1
  224.     if alarmCounter >= 10 then
  225.       redstone.setOutput("left", false)
  226.       alarmIsRinging = false
  227.     end
  228.   end
  229.  
  230.   -- Wait 2s until next iteration
  231.   os.sleep(2)
  232.  
  233. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top