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
- local Uri = ""
- monitor = peripheral.find("monitor")
- projector = peripheral.find("warpdriveForceFieldProjector")
- if projector.name() == "" then -- if navdata wasnt loaded
- print("Enter Shield Name:")
- local input = read()
- local n=input
- projector.name(n)
- end
- -- 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)
- term.setTextColor(colors.red)
- print(" Shield Information")
- end
- -- Check if we have a projector
- if projector == nil then
- error("ER: No projector 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 projector
- -- This will refresh all information every 2 seconds
- alarmIsRinging = false
- alarmIsActive = false
- alarmCounter = 0
- isAssemblyValid = projector.getAssemblyStatus()
- energyStored, energyMax, energyUnits = projector.getEnergyStatus()
- --isEnabled = projector.enable()
- tier = projector.getTier()
- name = projector.name()
- if tier == 1 then
- tier1 = "Basic"
- elseif tier == 2 then
- tier1 = "Advanced"
- else
- tier1 = "Superior"
- end
- while true do
- on = redstone.getAnalogInput("front")
- if on > 6 then
- if isEnabled == true then
- --putValue(6, "Skipping", colors.green)
- else
- projector.enable(true)
- isEnabled = true
- putValue(6," Enabled!", colors.green)
- http.post(Uri,"{\"content\":\"```yaml\\nShield: "..name.." \\nTier: "..tier1.." \\nEnergy: "..putNumber(energyStored).." \\nStatus: Enabled```\"}",{['content-type']="application/json"})
- end
- elseif on < 5 then
- if isEnabled == false then
- else
- projector.enable(false)
- isEnabled = false
- putValue(6,"Disabled!", colors.red)
- http.post(Uri,"{\"content\":\"```yaml\\nShield: "..name.." \\nTier: "..tier1.." \\nEnergy: "..putNumber(energyStored).." \\nStatus: Disabled```\"}",{['content-type']="application/json"})
- end
- -- Get our input/output/balance projector values
- if not isAssemblyValid then
- projectorCurrentIn = "Invalid"
- putValue(5, projectorCurrentIn, colors.red)
- else
- projectorCurrentIn = "Valid"
- putValue(5, projectorCurrentIn, colors.green)
- end
- putValue(3, tier1, colors.green)
- putValue(2, name, colors.green)
- -- Get our statistical values
- projectorCurrentCharge = energyStored
- putValue(9, putNumber(energyStored), colors.lightBlue)
- projectorCurrentColor = colors.red
- projectorCurrentPercentage = ((energyStored / energyMax) * 100)
- if projectorCurrentPercentage > 30 then projectorCurrentColor = colors.orange end
- if projectorCurrentPercentage > 60 then projectorCurrentColor = colors.green end
- putValue(10, string.sub(putNumber(projectorCurrentPercentage), 0, 4) .. "%", projectorCurrentColor)
- projectorCurrentCritical = "Yes"
- projectorCurrentColor = colors.red
- if projectorCurrentPercentage > 15 then
- projectorCurrentCritical = "No"
- projectorCurrentColor = colors.green
- end
- putValue(11, projectorCurrentCritical, projectorCurrentColor)
- -- Draw the current charge graph
- projectorCurrentColor = colors.red
- if projectorCurrentPercentage > 30 then term.setTextColor(colors.orange) end
- if projectorCurrentPercentage > 60 then term.setTextColor(colors.green) end
- if projectorCurrentPercentage >= 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 (projectorCurrentPercentage >= compare) then
- term.setCursorPos(3, (13 - i))
- local filler = ""
- for i = 1, 6 do
- local inhere = (compare + (i*2))
- if projectorCurrentPercentage >= inhere then
- filler = filler .. "#"
- else
- if projectorCurrentPercentage >= (inhere - 1) then
- filler = filler .. "="
- else
- filler = filler .. "_"
- end
- end
- end
- print(filler)
- end
- iterator = iterator + 1
- end
- -- Hey, ring the alarm!
- if projectorCurrentPercentage > 10 then
- alarmIsRinging = false
- alarmIsActive = false
- end
- if projectorCurrentPercentage < 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