Advertisement
Guest User

test

a guest
Nov 15th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.94 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. local Uri = "https://discordapp.com/api/webhooks/645012594536742922/mkGG2V7yuFzpfs50GxoM4QLKz6U0NB6YoVumbjrY4LKHpB9m0zXnLWl1ntM-9_O4Ua2R"
  53.  
  54. monitor = peripheral.wrap("right")
  55. battery = peripheral.find("warpdriveForceFieldProjector")
  56. if battery.name() == "" then -- if navdata wasnt loaded
  57.   print("Enter Shield Name:")
  58.   local input = read()
  59.   local n=input
  60.   battery.name(n)
  61.   end
  62. -- Check and bind monitor
  63. if monitor == nil then
  64.   error("ER: No screen found to display!")
  65. else
  66.   monitor.clear()
  67.   term.redirect(monitor)
  68.   term.setCursorPos(1, 1)
  69.   term.setBackgroundColor(colors.black)
  70.   print("     Shield Information")
  71. end
  72.  
  73. -- Check if we have a battery
  74. if battery == nil then
  75.   error("ER: No battery connected to computer")
  76. end
  77.  
  78. -- Draw our static fill volume box
  79. term.setTextColor(colors.white)
  80. term.setCursorPos(2, 2)
  81. print("+------+")
  82. term.setCursorPos(2, 11)
  83. print("+------+")
  84. for i = 3, 10 do
  85.   term.setCursorPos(2, i)
  86.   print("|")
  87.   term.setCursorPos(9, i)
  88.   print("|")
  89. end
  90.  
  91. -- Draw our static interface text
  92. term.setCursorPos(11, 2);
  93. print("Shield:")
  94. term.setCursorPos(11, 3);
  95. print("Tier:")
  96.  
  97. term.setCursorPos(11, 5);
  98. print("Valid:")
  99. term.setCursorPos(11, 6);
  100. print("Controls:")
  101. --term.setCursorPos(11, 7);
  102. --print("Enable Disable")
  103. term.setCursorPos(11, 9);
  104. print("Stored:")
  105. term.setCursorPos(11, 10);
  106. print("Filled:")
  107. term.setCursorPos(11, 11);
  108. print("Critical:")
  109.  
  110.  
  111. -- Entering our infinite loop of checking the battery
  112. -- This will refresh all information every 2 seconds
  113. alarmIsRinging = false
  114. alarmIsActive = false
  115. alarmCounter = 0
  116. isAssemblyValid = battery.getAssemblyStatus()
  117. energyStored, energyMax, energyUnits = battery.getEnergyStatus()
  118. --isEnabled = battery.enable()
  119. tier = battery.getTier()
  120. name = battery.name()
  121. while true do
  122.     on = redstone.getAnalogInput("front")
  123.     if on > 6 then
  124.     if isEnabled == true then
  125.     --putValue(6, "Skipping", colors.green)
  126.     else
  127.     battery.enable(true)
  128.     isEnabled = true
  129.         putValue(6,"  Enabled!", colors.green)
  130.     http.post(Uri,"{\"content\":\"```yaml\\nShield: "..name.." \\nTier: "..tier1.." \\nEnergy: "..putNumber(energyStored).." \\nStatus: Enabled```\"}",{['content-type']="application/json"})
  131.     end
  132.     elseif on < 5 then
  133.     if isEnabled == false then
  134.     else
  135.     battery.enable(false)
  136.     isEnabled = false
  137.     putValue(6,"Disabled!", colors.red)
  138.     http.post(Uri,"{\"content\":\"```yaml\\nShield: "..name.." \\nTier: "..tier1.." \\nEnergy: "..putNumber(energyStored).." \\nStatus: Disabled```\"}",{['content-type']="application/json"})
  139.     end
  140.   -- Get our input/output/balance battery values
  141.   if not isAssemblyValid then
  142.   batteryCurrentIn = "Invalid"
  143.   putValue(5, batteryCurrentIn, colors.red)
  144.   else
  145.   batteryCurrentIn = "Valid"
  146.   putValue(5, batteryCurrentIn, colors.green)
  147.   end
  148.   --batteryCurrentOut = battery.getOutput()
  149.  -- putValue(5, batteryCurrentIn, colors.lightBlue)
  150. --  putValue(6, putNumber(batteryCurrentOut), colors.lightBlue)
  151.  
  152. --  batteryCurrentBalance = batteryCurrentIn - batteryCurrentOut
  153. --  batteryCurrentColor = (batteryCurrentBalance >= 0) and colors.green or colors.red
  154. --  batteryCurrentSign = (batteryCurrentBalance >= 0) and "+" or ""
  155.   if tier == 1 then
  156.   tier1 = "Basic"
  157.   elseif tier == 2 then
  158.   tier1 = "Advanced"
  159.   else
  160.   tier1 = "Superior"
  161.   end
  162.   putValue(3, tier1, colors.green)
  163.   putValue(2, name, colors.green)
  164.   -- Get our statistical values
  165.   batteryCurrentCharge = energyStored
  166.   putValue(9, putNumber(energyStored), colors.lightBlue)
  167.  
  168.   batteryCurrentColor = colors.red
  169.   batteryCurrentPercentage = ((energyStored / energyMax) * 100)
  170.   if batteryCurrentPercentage > 30 then batteryCurrentColor = colors.orange end
  171.   if batteryCurrentPercentage > 60 then batteryCurrentColor = colors.green end
  172.   putValue(10, string.sub(putNumber(batteryCurrentPercentage), 0, 4) .. "%", batteryCurrentColor)
  173.  
  174.   batteryCurrentCritical = "Yes"
  175.   batteryCurrentColor = colors.red
  176.   if batteryCurrentPercentage > 15 then
  177.     batteryCurrentCritical = "No"
  178.     batteryCurrentColor = colors.green
  179.   end
  180.   putValue(11, batteryCurrentCritical, batteryCurrentColor)
  181.  
  182.   -- Draw the current charge graph
  183.   batteryCurrentColor = colors.red
  184.   if batteryCurrentPercentage > 30 then term.setTextColor(colors.orange) end
  185.   if batteryCurrentPercentage > 60 then term.setTextColor(colors.green) end
  186.   if batteryCurrentPercentage >= 100 then term.setTextColor(colors.green) end
  187.  
  188.   for i = 3, 10 do
  189.     term.setCursorPos(3, i)
  190.     print("      ")
  191.   end
  192.  
  193.   iterator = 0
  194.   for i = 3, 10 do
  195.     local compare = (12.5 * iterator)
  196.     if (batteryCurrentPercentage >= compare) then
  197.       term.setCursorPos(3, (13 - i))
  198.       local filler = ""
  199.       for i = 1, 6 do
  200.         local inhere = (compare + (i*2))
  201.         if batteryCurrentPercentage >= inhere then
  202.           filler = filler .. "#"
  203.         else
  204.           if batteryCurrentPercentage >= (inhere - 1) then
  205.             filler = filler .. "="
  206.           else
  207.             filler = filler .. "_"
  208.           end
  209.         end
  210.       end
  211.       print(filler)
  212.     end
  213.  
  214.     iterator = iterator + 1
  215.   end
  216.  
  217.   -- Hey, ring the alarm!
  218.   if batteryCurrentPercentage > 10 then
  219.     alarmIsRinging = false
  220.     alarmIsActive = false
  221.   end
  222.  
  223.   if batteryCurrentPercentage < 10 and alarmIsActive == false then
  224.     alarmIsRinging = true
  225.     alarmIsActive = true
  226.     alarmCounter = 0
  227.     redstone.setOutput("left", true)
  228.   end
  229.  
  230.   if alarmIsRinging == true then
  231.     alarmCounter = alarmCounter + 1
  232.     if alarmCounter >= 10 then
  233.       redstone.setOutput("left", false)
  234.       alarmIsRinging = false
  235.     end
  236.   end
  237.  
  238.   -- Wait 2s until next iteration
  239.   os.sleep(2)
  240.  
  241. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement