Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function putValue (line, text, color)
- local align = 30 - string.len(text)
- term.setCursorPos(align, line)
- term.setTextColor(color)
- print(text)
- end
- function putNumber (number)
- local round = 0
- local texts = ""
- if number >= 1000000000000000000 then
- round = (number / 1000000000000000000)
- texts = string.sub(round, 0, 5) .. " ERF"
- else
- if number >= 1000000000000000 then
- round = (number / 1000000000000000)
- texts = string.sub(round, 0, 5) .. " PRF"
- else
- if number >= 1000000000000 then
- round = (number / 1000000000000)
- texts = string.sub(round, 0, 5) .. " TRF"
- else
- if number >= 1000000000 then
- round = (number / 10000000000)
- texts = string.sub(round, 0, 5) .. " GRF"
- else
- if number >= 1000000 then
- round = (number / 10000000)
- texts = string.sub(round, 0, 5) .. " MRF"
- else
- if number >= 1000 then
- round = (number / 1000)
- texts = string.sub(round, 0, 5) .. " kRF"
- else
- texts = string.sub(number, 0, 5) .. " RF"
- end
- end
- end
- end
- end
- end
- return texts
- end
- -- Initialize our interface!
- -- Find all of our peripherals
- local Uri = "https://discordapp.com/api/webhooks/5012594536742922/mkGG2V7yuFzpfs50GxoM4QLKz6U0NB6YoVumbjrY4LKHpB9m0zXnLWl1ntM-9_O4Ua2R"
- monitor = peripheral.wrap("bottom")
- battery = peripheral.find("warpdriveForceFieldProjector")
- -- Check and bind monitor
- if monitor == nil then
- error("ER: No screen found to display!")
- else
- monitor.clear()
- term.redirect(monitor)
- term.setCursorPos(1, 1)
- term.setBackgroundColor(colors.black)
- print(" Shield Information")
- end
- -- Check if we have a battery
- if battery == nil then
- error("ER: No battery connected to computer")
- end
- -- Draw our static fill volume box
- term.setTextColor(colors.white)
- term.setCursorPos(2, 2)
- print("+------+")
- term.setCursorPos(2, 11)
- print("+------+")
- for i = 3, 10 do
- term.setCursorPos(2, i)
- print("|")
- term.setCursorPos(9, i)
- print("|")
- end
- -- Draw our static interface text
- term.setCursorPos(11, 2);
- print("Shield:")
- term.setCursorPos(11, 3);
- print("Tier:")
- term.setCursorPos(11, 5);
- print("Valid:")
- term.setCursorPos(11, 6);
- print("Controls:")
- --term.setCursorPos(11, 7);
- --print("Enable Disable")
- term.setCursorPos(11, 9);
- print("Stored:")
- term.setCursorPos(11, 10);
- print("Filled:")
- term.setCursorPos(11, 11);
- print("Critical:")
- -- Entering our infinite loop of checking the battery
- -- This will refresh all information every 2 seconds
- alarmIsRinging = false
- alarmIsActive = false
- alarmCounter = 0
- isAssemblyValid = battery.getAssemblyStatus()
- energyStored, energyMax, energyUnits = battery.getEnergyStatus()
- --isEnabled = battery.enable()
- tier = battery.getTier()
- name = battery.name()
- while true do
- on = redstone.getAnalogInput("right")
- if on > 6 then
- if isEnabled == true then
- --putValue(6, "Skipping", colors.green)
- else
- battery.enable(true)
- isEnabled = true
- end
- putValue(6," Enabled!", colors.green)
- http.post(uri,"{\"content\":\"```yaml\\nShield Name: "..name.." \\nTier: "..tier.." \\nEnergy: "..energyStored.." \\nStatus: "..isEnabled.."```\"}",{['content-type']="application/json"})
- elseif on < 5 then
- battery.enable(false)
- putValue(6,"Disabled!", colors.red)
- end
- -- Get our input/output/balance battery values
- if not isAssemblyValid then
- batteryCurrentIn = "Invalid"
- putValue(5, batteryCurrentIn, colors.red)
- else
- batteryCurrentIn = "Valid"
- putValue(5, batteryCurrentIn, colors.green)
- end
- --batteryCurrentOut = battery.getOutput()
- -- putValue(5, batteryCurrentIn, colors.lightBlue)
- -- putValue(6, putNumber(batteryCurrentOut), colors.lightBlue)
- -- batteryCurrentBalance = batteryCurrentIn - batteryCurrentOut
- -- batteryCurrentColor = (batteryCurrentBalance >= 0) and colors.green or colors.red
- -- batteryCurrentSign = (batteryCurrentBalance >= 0) and "+" or ""
- if tier == 1 then
- tier1 = "Basic"
- elseif tier == 2 then
- tier1 = "Advanced"
- else
- tier1 = "Superior"
- end
- putValue(3, tier1, colors.green)
- putValue(2, name, colors.green)
- -- Get our statistical values
- batteryCurrentCharge = energyStored
- putValue(9, putNumber(energyStored), colors.lightBlue)
- batteryCurrentColor = colors.red
- batteryCurrentPercentage = ((energyStored / energyMax) * 100)
- if batteryCurrentPercentage > 30 then batteryCurrentColor = colors.orange end
- if batteryCurrentPercentage > 60 then batteryCurrentColor = colors.green end
- putValue(10, string.sub(putNumber(batteryCurrentPercentage), 0, 4) .. "%", batteryCurrentColor)
- batteryCurrentCritical = "Yes"
- batteryCurrentColor = colors.red
- if batteryCurrentPercentage > 15 then
- batteryCurrentCritical = "No"
- batteryCurrentColor = colors.green
- end
- putValue(11, batteryCurrentCritical, batteryCurrentColor)
- -- Draw the current charge graph
- batteryCurrentColor = colors.red
- if batteryCurrentPercentage > 30 then term.setTextColor(colors.orange) end
- if batteryCurrentPercentage > 60 then term.setTextColor(colors.green) end
- if batteryCurrentPercentage >= 100 then term.setTextColor(colors.green) end
- for i = 3, 10 do
- term.setCursorPos(3, i)
- print(" ")
- end
- iterator = 0
- for i = 3, 10 do
- local compare = (12.5 * iterator)
- if (batteryCurrentPercentage >= compare) then
- term.setCursorPos(3, (13 - i))
- local filler = ""
- for i = 1, 6 do
- local inhere = (compare + (i*2))
- if batteryCurrentPercentage >= inhere then
- filler = filler .. "#"
- else
- if batteryCurrentPercentage >= (inhere - 1) then
- filler = filler .. "="
- else
- filler = filler .. "_"
- end
- end
- end
- print(filler)
- end
- iterator = iterator + 1
- end
- -- Hey, ring the alarm!
- if batteryCurrentPercentage > 10 then
- alarmIsRinging = false
- alarmIsActive = false
- end
- if batteryCurrentPercentage < 10 and alarmIsActive == false then
- alarmIsRinging = true
- alarmIsActive = true
- alarmCounter = 0
- redstone.setOutput("left", true)
- end
- if alarmIsRinging == true then
- alarmCounter = alarmCounter + 1
- if alarmCounter >= 10 then
- redstone.setOutput("left", false)
- alarmIsRinging = false
- end
- end
- -- Wait 2s until next iteration
- os.sleep(2)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement