SHOW:
|
|
- or go back to the newest paste.
| 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 | - | local Uri = "https://discordapp.com/api/webhooks/5021878473195531/8YysYRjRLRHH_bHvfz-68YxbIVCxx39y8i_EghpKFL4rJd6DeYrTJUs9SSSZx9687MvU" |
| 46 | + | local Uri = "https://discor" |
| 47 | monitor = peripheral.find("monitor")
| |
| 48 | projector = peripheral.find("warpdriveForceFieldProjector")
| |
| 49 | if projector.name() == "" then -- if navdata wasnt loaded | |
| 50 | print("Enter Shield Name:")
| |
| 51 | local input = read() | |
| 52 | local n=input | |
| 53 | projector.name(n) | |
| 54 | end | |
| 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 | term.setTextColor(colors.red) | |
| 64 | print(" Shield Information")
| |
| 65 | end | |
| 66 | ||
| 67 | -- Check if we have a projector | |
| 68 | if projector == nil then | |
| 69 | error("ER: No projector connected to computer")
| |
| 70 | end | |
| 71 | ||
| 72 | -- Draw our static fill volume box | |
| 73 | term.setTextColor(colors.white) | |
| 74 | term.setCursorPos(2, 2) | |
| 75 | print("+------+")
| |
| 76 | term.setCursorPos(2, 11) | |
| 77 | print("+------+")
| |
| 78 | for i = 3, 10 do | |
| 79 | term.setCursorPos(2, i) | |
| 80 | print("|")
| |
| 81 | term.setCursorPos(9, i) | |
| 82 | print("|")
| |
| 83 | end | |
| 84 | ||
| 85 | -- Draw our static interface text | |
| 86 | term.setCursorPos(11, 2); | |
| 87 | print("Shield:")
| |
| 88 | term.setCursorPos(11, 3); | |
| 89 | print("Tier:")
| |
| 90 | ||
| 91 | term.setCursorPos(11, 5); | |
| 92 | print("Valid:")
| |
| 93 | term.setCursorPos(11, 6); | |
| 94 | print("Controls:")
| |
| 95 | --term.setCursorPos(11, 7); | |
| 96 | --print("Enable Disable")
| |
| 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 projector | |
| 106 | -- This will refresh all information every 2 seconds | |
| 107 | alarmIsRinging = false | |
| 108 | alarmIsActive = false | |
| 109 | alarmCounter = 0 | |
| 110 | isAssemblyValid = projector.getAssemblyStatus() | |
| 111 | energyStored, energyMax, energyUnits = projector.getEnergyStatus() | |
| 112 | --isEnabled = projector.enable() | |
| 113 | tier = projector.getTier() | |
| 114 | name = projector.name() | |
| 115 | if tier == 1 then | |
| 116 | tier1 = "Basic" | |
| 117 | elseif tier == 2 then | |
| 118 | tier1 = "Advanced" | |
| 119 | else | |
| 120 | tier1 = "Superior" | |
| 121 | end | |
| 122 | while true do | |
| 123 | - | on = redstone.getAnalogInput("front")
|
| 123 | + | on = redstone.getAnalogInput("right")
|
| 124 | if on > 6 then | |
| 125 | if isEnabled == true then | |
| 126 | --putValue(6, "Skipping", colors.green) | |
| 127 | else | |
| 128 | projector.enable(true) | |
| 129 | isEnabled = true | |
| 130 | putValue(6," Enabled!", colors.green) | |
| 131 | http.post(Uri,"{\"content\":\"```yaml\\nShield: "..name.." \\nTier: "..tier1.." \\nEnergy: "..putNumber(energyStored).." \\nStatus: Enabled```\"}",{['content-type']="application/json"})
| |
| 132 | end | |
| 133 | elseif on < 5 then | |
| 134 | if isEnabled == false then | |
| 135 | else | |
| 136 | projector.enable(false) | |
| 137 | isEnabled = false | |
| 138 | putValue(6,"Disabled!", colors.red) | |
| 139 | http.post(Uri,"{\"content\":\"```yaml\\nShield: "..name.." \\nTier: "..tier1.." \\nEnergy: "..putNumber(energyStored).." \\nStatus: Disabled```\"}",{['content-type']="application/json"})
| |
| 140 | end | |
| 141 | end | |
| 142 | -- Get our input/output/balance projector values | |
| 143 | if not isAssemblyValid then | |
| 144 | projectorCurrentIn = "Invalid" | |
| 145 | putValue(5, projectorCurrentIn, colors.red) | |
| 146 | else | |
| 147 | projectorCurrentIn = "Valid" | |
| 148 | putValue(5, projectorCurrentIn, colors.green) | |
| 149 | end | |
| 150 | putValue(3, tier1, colors.green) | |
| 151 | putValue(2, name, colors.green) | |
| 152 | -- Get our statistical values | |
| 153 | projectorCurrentCharge = energyStored | |
| 154 | putValue(9, putNumber(energyStored), colors.lightBlue) | |
| 155 | ||
| 156 | projectorCurrentColor = colors.red | |
| 157 | projectorCurrentPercentage = ((energyStored / energyMax) * 100) | |
| 158 | if projectorCurrentPercentage > 30 then projectorCurrentColor = colors.orange end | |
| 159 | if projectorCurrentPercentage > 60 then projectorCurrentColor = colors.green end | |
| 160 | putValue(10, string.sub(putNumber(projectorCurrentPercentage), 0, 4) .. "%", projectorCurrentColor) | |
| 161 | ||
| 162 | projectorCurrentCritical = "Yes" | |
| 163 | projectorCurrentColor = colors.red | |
| 164 | if projectorCurrentPercentage > 15 then | |
| 165 | projectorCurrentCritical = "No" | |
| 166 | projectorCurrentColor = colors.green | |
| 167 | end | |
| 168 | putValue(11, projectorCurrentCritical, projectorCurrentColor) | |
| 169 | ||
| 170 | -- Draw the current charge graph | |
| 171 | projectorCurrentColor = colors.red | |
| 172 | if projectorCurrentPercentage > 30 then term.setTextColor(colors.orange) end | |
| 173 | if projectorCurrentPercentage > 60 then term.setTextColor(colors.green) end | |
| 174 | if projectorCurrentPercentage >= 100 then term.setTextColor(colors.green) end | |
| 175 | ||
| 176 | for i = 3, 10 do | |
| 177 | term.setCursorPos(3, i) | |
| 178 | print(" ")
| |
| 179 | end | |
| 180 | ||
| 181 | iterator = 0 | |
| 182 | for i = 3, 10 do | |
| 183 | local compare = (12.5 * iterator) | |
| 184 | if (projectorCurrentPercentage >= compare) then | |
| 185 | term.setCursorPos(3, (13 - i)) | |
| 186 | local filler = "" | |
| 187 | for i = 1, 6 do | |
| 188 | local inhere = (compare + (i*2)) | |
| 189 | if projectorCurrentPercentage >= inhere then | |
| 190 | filler = filler .. "#" | |
| 191 | else | |
| 192 | if projectorCurrentPercentage >= (inhere - 1) then | |
| 193 | filler = filler .. "=" | |
| 194 | else | |
| 195 | filler = filler .. "_" | |
| 196 | end | |
| 197 | end | |
| 198 | end | |
| 199 | print(filler) | |
| 200 | end | |
| 201 | ||
| 202 | iterator = iterator + 1 | |
| 203 | end | |
| 204 | ||
| 205 | -- Hey, ring the alarm! | |
| 206 | if projectorCurrentPercentage > 10 then | |
| 207 | alarmIsRinging = false | |
| 208 | alarmIsActive = false | |
| 209 | end | |
| 210 | ||
| 211 | if projectorCurrentPercentage < 10 and alarmIsActive == false then | |
| 212 | alarmIsRinging = true | |
| 213 | alarmIsActive = true | |
| 214 | alarmCounter = 0 | |
| 215 | redstone.setOutput("left", true)
| |
| 216 | end | |
| 217 | ||
| 218 | if alarmIsRinging == true then | |
| 219 | alarmCounter = alarmCounter + 1 | |
| 220 | if alarmCounter >= 10 then | |
| 221 | redstone.setOutput("left", false)
| |
| 222 | alarmIsRinging = false | |
| 223 | end | |
| 224 | end | |
| 225 | ||
| 226 | -- Wait 2s until next iteration | |
| 227 | os.sleep(2) | |
| 228 | ||
| 229 | end |