SHOW:
|
|
- or go back to the newest paste.
| 1 | --Script by Savage_Me55iah of CraftAu.com.au-- | |
| 2 | - | --Version 1.6-- |
| 2 | + | --Version 1.7-- |
| 3 | - | --Needs corresponding "Savage Monitor v1.6" script-- |
| 3 | + | --Needs corresponding "Savage Monitor v1.7" script-- |
| 4 | ||
| 5 | tArgs = { ... }
| |
| 6 | adjust = tArgs[1] or false | |
| 7 | ||
| 8 | local variables = {
| |
| 9 | ["status"] = true, | |
| 10 | ["timer"] = 2, | |
| 11 | ["save"] = "variables", | |
| 12 | ["side"] = "left", | |
| 13 | ["rednet"] = true, | |
| 14 | ["rednet_color"] = colors.white, | |
| 15 | ["reversal"] = false, | |
| 16 | ["nuke"] = false, | |
| 17 | ["time_on"] = 80, | |
| 18 | ["time_off"] = 110 | |
| 19 | } | |
| 20 | ||
| 21 | local sides2 = {["front"] = true, ["back"] = true, ["left"] = true, ["right"] = true, ["top"] = true, ["bottom"] = true}
| |
| 22 | ||
| 23 | local colors2 = {["white"] = colors.white, ["orange"] = colors.orange, ["magenta"] = colors.magenta, ["lightblue"] = colors.lightBlue, ["yellow"] = colors.yellow, ["lime"] = colors.lime, ["pink"] = colors.pink, ["gray"] = colors.gray, ["lightgray"] = colors.lightGray, ["cyan"] = colors.cyan, ["purple"] = colors.purple, ["blue"] = colors.blue, ["brown"] = colors.brown, ["green"] = colors.green, ["red"] = colors.red, ["black"] = colors.black}
| |
| 24 | ||
| 25 | color_from_decimal = {[1] = "white", [2] = "orange", [4] = "magenta", [8] = "lightBlue", [16] = "yellow", [32] = "lime", [64] = "pink", [128] = "gray", [256] = "lightGray", [512] = "cyan", [1024] = "purple",[2048] = "blue", [4096] = "brown", [8192] = "green", [16384] = "red", [32768] = "black"}
| |
| 26 | ||
| 27 | ||
| 28 | function find_peripheral(t, e) | |
| 29 | e = e or nil | |
| 30 | sides = {[1] = "front", [2] = "back", [3] = "left", [4] = "right", [5] = "top", [6] = "bottom"}
| |
| 31 | peripheral_found = false | |
| 32 | for num=1, 6 do | |
| 33 | type = peripheral.getType(sides[num]) | |
| 34 | if type == t then | |
| 35 | if e == "wireless" then | |
| 36 | if peripheral.call(sides[num], "isWireless") then | |
| 37 | return sides[num] | |
| 38 | end | |
| 39 | elseif e == "remote" then | |
| 40 | if not peripheral.call(sides[num], "isWireless") then return sides[num] end | |
| 41 | elseif e == nil then | |
| 42 | return sides[num] | |
| 43 | end | |
| 44 | end | |
| 45 | end | |
| 46 | if peripheral_found ~= true then | |
| 47 | error("No " .. t .. " attached to the computer", 0)
| |
| 48 | end | |
| 49 | end | |
| 50 | ||
| 51 | id2 = os.getComputerID() | |
| 52 | label = os.getComputerLabel() or false | |
| 53 | if label == false then | |
| 54 | print("Please Type label here: ")
| |
| 55 | os.setComputerLabel(tostring(read())) | |
| 56 | end | |
| 57 | ||
| 58 | rednet.open(find_peripheral("modem", "wireless"))
| |
| 59 | ||
| 60 | function load() | |
| 61 | fileHandle = fs.open (variables["save"], 'r') | |
| 62 | variables = textutils.unserialize (fileHandle.readAll()) | |
| 63 | fileHandle.close() | |
| 64 | end | |
| 65 | ||
| 66 | function save() | |
| 67 | fileHandle = fs.open (variables["save"], 'w') | |
| 68 | fileHandle.write (textutils.serialize (variables)) | |
| 69 | fileHandle.close() | |
| 70 | end | |
| 71 | ||
| 72 | function switch(command) | |
| 73 | if command then | |
| 74 | if variables["rednet"] then | |
| 75 | rs.setBundledOutput(variables["side"], variables["rednet_color"]) | |
| 76 | else | |
| 77 | redstone.setOutput(variables["side"], true) | |
| 78 | end | |
| 79 | else | |
| 80 | if variables["rednet"] then | |
| 81 | rs.setBundledOutput(variables["side"], 0) | |
| 82 | else | |
| 83 | redstone.setOutput(variables["side"], false) | |
| 84 | end | |
| 85 | end | |
| 86 | end | |
| 87 | ||
| 88 | function nuke(command, command2) | |
| 89 | if command or not command2 then | |
| 90 | switch(false) | |
| 91 | term_draw(false) | |
| 92 | os.startTimer(tonumber(variables["time_off"])) | |
| 93 | on = false | |
| 94 | elseif not command and command2 then | |
| 95 | switch(true) | |
| 96 | os.startTimer(tonumber(variables["time_on"])) | |
| 97 | term_draw(true) | |
| 98 | on = true | |
| 99 | end | |
| 100 | end | |
| 101 | ||
| 102 | ||
| 103 | if adjust ~= false or not fs.exists(variables["save"]) then | |
| 104 | print("SETTINGS: ")
| |
| 105 | repeat | |
| 106 | print("Output Side?: front/back/left/right/top/bottom")
| |
| 107 | text = tostring(read()) | |
| 108 | text = text:lower() | |
| 109 | until sides2[text] | |
| 110 | variables["side"] = text | |
| 111 | repeat | |
| 112 | print("Rednet/Bundled cables?: true/false: ")
| |
| 113 | text2 = tostring(read()) | |
| 114 | text2 = text2:lower() | |
| 115 | until text2 == "true" or text2 == "false" | |
| 116 | if text2 == "true" then | |
| 117 | variables["rednet"] = true else | |
| 118 | variables["rednet"] = false | |
| 119 | end | |
| 120 | if variables["rednet"] then | |
| 121 | repeat | |
| 122 | print("Rednet Color?: ")
| |
| 123 | text = tostring(read()) | |
| 124 | text = text:lower() | |
| 125 | until colors2[text] ~= nil | |
| 126 | variables["rednet_color"] = colors2[text] | |
| 127 | end | |
| 128 | repeat | |
| 129 | print("Reversal (for machines that turn off with redstone signal): true/false: ")
| |
| 130 | text2 = tostring(read()) | |
| 131 | text2 = text2:lower() | |
| 132 | until text2 == "true" or text2 == "false" | |
| 133 | if text2 == "true" then | |
| 134 | variables["reversal"] = true else | |
| 135 | variables["reversal"] = false end | |
| 136 | repeat | |
| 137 | print("Alternating redstone signal for IC2 reactors?: true/false: ")
| |
| 138 | text2 = tostring(read()) | |
| 139 | text2 = text2:lower() | |
| 140 | until text2 == "true" or text2 == "false" | |
| 141 | if text2 == "true" then | |
| 142 | variables["nuke"] = true | |
| 143 | -- repeat | |
| 144 | print("How long turned on?: seconds: ")
| |
| 145 | time = tonumber(read()) | |
| 146 | -- until type(time) == "number" | |
| 147 | variables["time_on"] = time | |
| 148 | -- repeat | |
| 149 | print("How long turned off? (cooldown): seconds: ")
| |
| 150 | time = tonumber(read()) | |
| 151 | -- until type(time) == "number" | |
| 152 | variables["time_off"] = time | |
| 153 | else | |
| 154 | variables["nuke"] = false | |
| 155 | end | |
| 156 | save() | |
| 157 | else | |
| 158 | load() | |
| 159 | end | |
| 160 | ||
| 161 | function change_colors(command, color_1, color_2) | |
| 162 | command.setTextColor(color_1 or colors.white) | |
| 163 | command.setBackgroundColor(color_2 or colors.black) | |
| 164 | end | |
| 165 | ||
| 166 | function term_write(text, command, xpos, ypos) | |
| 167 | term.setCursorPos(xpos, ypos) | |
| 168 | if term.isColor() then | |
| 169 | if command then change_colors(term, colors.black, colors.green) else change_colors(term, colors.black, colors.red) end | |
| 170 | else | |
| 171 | if command then change_colors(term, colors.black, colors.white) else change_colors(term) end | |
| 172 | end | |
| 173 | term.write(text) | |
| 174 | change_colors(term) | |
| 175 | end | |
| 176 | ||
| 177 | function term_draw(command) | |
| 178 | term.clear() | |
| 179 | term_write(" " .. label .. ":" .. id2 .. " ", true, 2, 2)
| |
| 180 | term_write(" Status ", variables["status"], 2, 4)
| |
| 181 | term_write(" Nuclear Reactor ", variables["nuke"], 2, 6)
| |
| 182 | if not variables["nuke"] then | |
| 183 | term_write(" Cooldown ", false, 2, 8)
| |
| 184 | term_write(" Reactor Active ", false, 2, 10)
| |
| 185 | else | |
| 186 | if command then | |
| 187 | term_write(" Cooldown: " .. variables["time_off"] .. " ", false, 2, 8)
| |
| 188 | term_write(" Reactor Active: " .. variables["time_on"] .. " ", true, 2, 10)
| |
| 189 | else | |
| 190 | term_write(" Cooldown: " .. variables["time_off"] .. " ", true, 2, 8)
| |
| 191 | term_write(" Reactor Active: " .. variables["time_on"] .. " ", false, 2, 10)
| |
| 192 | end | |
| 193 | end | |
| 194 | term_write(" Rednet ", variables["rednet"], 2, 12)
| |
| 195 | term_write(" Reverse ", variables["reversal"], 2, 14)
| |
| 196 | term.setCursorPos(1, 16) | |
| 197 | end | |
| 198 | ||
| 199 | os.startTimer(0.1) | |
| 200 | term_draw(false) | |
| 201 | on = true | |
| 202 | ||
| 203 | while true do | |
| 204 | ||
| 205 | while event == "redstone" or event == nil do event, id, text = os.pullEvent() end | |
| 206 | if event == "rednet_message" then | |
| 207 | if variables["reversal"] then | |
| 208 | if text == "activate" then | |
| 209 | variables["status"] = false | |
| 210 | else | |
| 211 | variables["status"] = true | |
| 212 | end | |
| 213 | else | |
| 214 | if text == "activate" then | |
| 215 | variables["status"] = true | |
| 216 | else | |
| 217 | variables["status"] = false | |
| 218 | end | |
| 219 | end | |
| 220 | if variables["nuke"] and variables["status"] then os.startTimer(variables["time_off"]) end | |
| 221 | end | |
| 222 | if not variables["nuke"] then | |
| 223 | switch(variables["status"]) | |
| 224 | term_draw() | |
| 225 | else | |
| 226 | if event == "timer" then | |
| 227 | nuke(on, variables["status"]) | |
| 228 | term_draw(on) | |
| 229 | end | |
| 230 | end | |
| 231 | save() | |
| 232 | event = nil | |
| 233 | end |