Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local oldPull = os.pullEvent
- os.pullEvent = os.pullEventRaw
- local silos = {}
- local argv = {...}
- local selected = 1
- local color = {"silver"}
- for i,v in pairs(colors) do
- if i ~= "combine" and i ~= "subtract" and i ~= "test" and i ~= "lightGray" then
- table.insert(color, i)
- end
- end
- print("Detecting silos...")
- for i,side in ipairs(rs.getSides()) do
- if argv[1] == "--debug" then
- print("Checking: "..side)
- end
- if peripheral.getType(side) == "cable" then
- if argv[1] == "--debug" then
- print("Found a peripheral cable.")
- end
- for i2, color in ipairs(color) do
- if argv[1] == "--debug" then
- print("Checking: "..side..":"..color)
- end
- if peripheral.getType(side..":"..color) == "ICBMLauncher" then
- print("Silo found on side:"..side..":"..color)
- table.insert(silos, {side..":"..color, peripheral.wrap(side..":"..color)})
- end
- end
- elseif peripheral.getType(side) == "ICBMLauncher" then
- print("Silo found on side:"..side)
- table.insert(silos, {side, peripheral.wrap(side)})
- end
- end
- if #silos == 0 then
- print("No silos detected.")
- print("Please place a launcher control panel next to the computer.")
- os.sleep(2)
- return
- elseif #silos == 1 then
- print("Found 1 silo.")
- else
- print("Found "..#silos.." silos.")
- end
- os.sleep(0.75)
- local function getPW()
- if fs.exists("launchCode") then
- term.clear()
- term.setCursorPos(5, 8)
- write("Please enter a launch code.")
- local handle = fs.open("launchCode", "r")
- local code = handle.readAll()
- handle.close()
- local userPW = read()
- term.clear()
- term.setCursorPos(1,1)
- return (code == userPW)
- else
- return true
- end
- end
- local function printColored(...)
- for i=1, arg["n"] do
- if type(arg[i]) == "string" then
- write(arg[i])
- elseif type(arg[i]) == "number" then
- if term.isColor() then
- term.setTextColor(arg[i])
- end
- end
- end
- print("")
- term.setTextColor(colors.white)
- end
- local function doCountdown(length)
- for i=length, 1, -1 do
- term.clear()
- term.setCursorPos(12,9)
- write("Launching in: "..i.." seconds...")
- term.setCursorPos(3,10)
- write("Press any key (except escape) to abort launch.")
- local timer = os.startTimer(1)
- while true do
- local event, id = os.pullEvent()
- if event == "key" then
- if id ~= 1 then
- term.setCursorPos(17,11)
- write("Aborting launch!")
- os.sleep(0.5)
- return false
- end
- elseif event == "timer" then
- if id == timer then
- break
- end
- end
- end
- end
- return true
- end
- while true do
- term.clear()
- term.setCursorPos(1,1)
- printColored(colors.white, "Silo ", colors.lime, tostring(selected), colors.white, " selected.")
- print("")
- print("Details: ")
- print("")
- printColored("Frequency: ", colors.lime, tostring(silos[selected][2].getFrequency()))
- local targetX, targetY, targetZ = silos[selected][2].getTarget()
- print("Targeted: ")
- printColored("X: ", colors.lime, tostring(targetX))
- printColored("Y: ", colors.lime, tostring(targetY))
- printColored("Z: ", colors.lime, tostring(targetZ))
- print("")
- print("Options: ")
- printColored("1. ", colors.lime, "Select Silo")
- printColored("2. ", colors.orange, "Set Silo Target")
- printColored("3. ", colors.orange, "Set Silo Frequency")
- printColored("4. ", colors.red, "Launch")
- printColored("5. ", colors.red, "Launch All")
- printColored("6. ", colors.orange, "Set All Silo Frequencies")
- printColored("7. ", colors.orange, "Set All Silo Targets")
- local event, key = os.pullEvent("key")
- if key == 2 then
- term.clear()
- term.setCursorPos(1,1)
- print("Detected silos:")
- for i,v in ipairs(silos) do
- print(i..". Silo on: "..v[1].." side")
- end
- local x, y = term.getCursorPos()
- while true do
- term.setCursorPos(x,y)
- term.clearLine()
- write("Selection> ")
- local data = tonumber(read())
- if data then
- if silos[data] then
- selected = data
- break
- end
- end
- end
- elseif key == 3 then
- local x, y, z = 0
- while true do
- term.setCursorPos(1,7)
- term.clearLine()
- write("X: ")
- local selX = read()
- if tonumber(selX) then
- x = tonumber(selX)
- break
- end
- end
- while true do
- term.setCursorPos(1,8)
- term.clearLine()
- write("Y: ")
- local selY = read()
- if tonumber(selY) then
- y = tonumber(selY)
- break
- end
- end
- while true do
- term.setCursorPos(1,9)
- term.clearLine()
- write("Z: ")
- local selZ = read()
- if tonumber(selZ) then
- z = tonumber(selZ)
- break
- end
- end
- silos[selected][2].setTarget(x,y,z)
- elseif key == 4 then
- while true do
- term.setCursorPos(1,5)
- term.clearLine()
- write("Frequency: ")
- local selFreq = read()
- if tonumber(selFreq) then
- silos[selected][2].setFrequency(tonumber(selFreq))
- break
- end
- end
- elseif key == 5 then
- if getPW() then
- if doCountdown(10) then
- silos[selected][2].launch()
- end
- else
- term.clear()
- term.setCursorPos(12,9)
- print("Incorrect code!")
- os.sleep(2)
- end
- elseif key == 6 then
- if getPW() then
- if doCountdown(10) then
- for i,v in ipairs(silos) do
- v[2].launch()
- os.sleep(3)
- end
- end
- else
- term.clear()
- term.setCursorPos(12,9)
- print("Incorrect code!")
- os.sleep(2)
- end
- elseif key == 7 then
- while true do
- term.setCursorPos(1,5)
- term.clearLine()
- write("Frequency: ")
- local selFreq = read()
- if tonumber(selFreq) then
- for i,v in ipairs(silos) do
- v[2].setFrequency(tonumber(selFreq))
- end
- break
- end
- end
- elseif key == 8 then
- local x, y, z = 0
- while true do
- term.setCursorPos(1,7)
- term.clearLine()
- write("X: ")
- local selX = read()
- if tonumber(selX) then
- x = tonumber(selX)
- break
- end
- end
- while true do
- term.setCursorPos(1,8)
- term.clearLine()
- write("Y: ")
- local selY = read()
- if tonumber(selY) then
- y = tonumber(selY)
- break
- end
- end
- while true do
- term.setCursorPos(1,9)
- term.clearLine()
- write("Z: ")
- local selZ = read()
- if tonumber(selZ) then
- z = tonumber(selZ)
- break
- end
- end
- for i,v in ipairs(silos) do
- v[2].setTarget(x,y,z)
- end
- end
- end
- os.pullEvent = oldPull
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement