Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ LanteaCraft & SGCraft ]]--
- --[[ DiscoveryDialer 2 ]]--
- --[[ by Dog ]]--
- --[[ aka ]]--
- --[[ HydrantHunter ]]--
- --[[ pastebin: yg67N4UT ]]--
- if not os.getComputerLabel() then
- os.setComputerLabel("CC#" .. tostring(os.getComputerID()))
- end
- local gate = peripheral.find("stargate")
- if not gate then
- lcGate = true
- gate = peripheral.find("StargateBase")
- if gate then
- if not gate.isValid() then gate = false end
- end
- end
- if not gate then error("No stargate found!", 0) end
- local thisGate = lcGate and gate.getStargateAddressString() or gate.localAddress()
- local nineChevs = #thisGate == 9
- local symbols = { 'A', 'B', 'C', 'D', 'E' ,'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '+' }
- local startChevron = { [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1, [6] = 1, [7] = 1, [8] = 1, [9] = 1 }
- local newAddress = nineChevs and 'AAAAAAAAA' or 'AAAAAAA'
- local numDials, numGates, numErrors = 0, 0, 0
- local gateStatus, continueDialing = false, true
- local conTimer
- local function hangUp()
- if lcGate then
- --local onHook = pcall(gate.disengageStargate)
- pcall(gate.disengageStargate)
- local numChevrons = gate.getActivatedChevrons()
- if numChevrons > 0 then
- for i = 1, numChevrons + 1 do --# had to add the + 1 so quitting would work correctly
- --onHook = pcall(gate.deactivateChevron)
- --if not onHook then break end
- pcall(gate.deactivateChevron)
- end
- end
- else
- gate.disconnect()
- end
- end
- local function gateWatch()
- local event, timerName
- while continueDialing do
- event, timerName = os.pullEvent()
- if event == "connect" then
- return true
- elseif event == "timer" and timerName == conTimer then
- hangUp()
- return false
- end
- end
- end
- local function gateDialer()
- local checkAddress
- while continueDialing do
- print("Dialing " .. newAddress)
- if lcGate then
- for i = 1, #newAddress do
- --[[
- if continueDialing then
- checkAddress = pcall(gate.selectGlyph, newAddress:sub(i, i))
- else
- return
- end
- if checkAddress then
- if continueDialing then
- checkAddress = pcall(gate.activateChevron)
- else
- return
- end
- if checkAddress then
- os.pullEvent("engageGlyph")
- else
- hangUp()
- break
- end
- else
- hangUp()
- break
- end
- ]]--
- if continueDialing then
- pcall(gate.selectGlyph, newAddress:sub(i, i))
- pcall(gate.activateChevron)
- os.pullEvent("engageGlyph")
- else
- return
- end
- end
- if continueDialing then
- --checkAddress = pcall(gate.engageStargate)
- pcall(gate.engageStargate)
- conTimer = os.startTimer(2)
- else
- return
- end
- else
- checkAddress = gate.dial(newAddress)
- end
- if continueDialing then
- if checkAddress then
- numDials = numDials + 1
- gateStatus = lcGate and gateWatch() or true
- --if lcGate then gateStatus = gateWatch() else gateStatus = true end
- break
- else
- if lcGate then
- --print("Unable to dial")
- --numErrors = numErrors + 1
- --if numErrors >= 10 then continueDialing = false return end
- --sleep(2)
- numDials = numDials + 1
- gateStatus = gateWatch()
- else
- numDials = numDials + 1
- gateStatus = false
- break
- end
- end
- else
- return
- end
- end
- --if gateStatus and (lcGate or (not lcGate and gate.stargateState() == "Connected")) then
- if gateStatus then
- print("Found gate at " .. newAddress)
- numGates = numGates + 1
- local file = fs.open("gateList", fs.exists("gateList") and "a" or "w")
- file.writeLine(newAddress)
- file.close()
- gateStatus = false
- if lcGate then
- pcall(gate.disengageStargate)
- os.pullEvent("disconnect")
- else
- gate.disconnect()
- end
- --sleep(2)
- end
- end
- local function gateScanner()
- for chevronONE = startChevron[1], #symbols do
- for chevronTWO = startChevron[2], #symbols do
- for chevronTHREE = startChevron[3], #symbols do
- for chevronFOUR = startChevron[4], #symbols do
- for chevronFIVE = startChevron[5], #symbols do
- for chevronSIX = startChevron[6], #symbols do
- for chevronSEVEN = startChevron[7], #symbols do
- if nineChevs then
- for chevronEIGHT = startChevron[8], #symbols do
- for chevronNINE = startChevron[9], #symbols do
- newAddress = symbols[chevronONE] .. symbols[chevronTWO] .. symbols[chevronTHREE] .. symbols[chevronFOUR] .. symbols[chevronFIVE] .. symbols[chevronSIX] .. symbols[chevronSEVEN] .. symbols[chevronEIGHT] .. symbols[chevronNINE]
- if newAddress ~= thisGate then
- print("Temporal buffer...")
- sleep(1)
- local file = fs.open(".discoverySession", "w")
- file.writeLine(newAddress)
- file.close()
- gateDialer()
- else
- print("Skipping my gate...")
- end
- end
- end
- else
- newAddress = symbols[chevronONE] .. symbols[chevronTWO] .. symbols[chevronTHREE] .. symbols[chevronFOUR] .. symbols[chevronFIVE] .. symbols[chevronSIX] .. symbols[chevronSEVEN]
- if newAddress ~= thisGate then
- print("Temporal buffer...")
- sleep(1)
- local file = fs.open(".discoverySession", "w")
- file.writeLine(newAddress)
- file.close()
- gateDialer()
- else
- print("Skipping my gate...")
- end
- end
- end
- end
- end
- end
- end
- end
- end
- end
- local function quit()
- while true do
- local _, char = os.pullEvent("char")
- if string.lower(char) == "q" then
- continueDialing = false
- hangUp()
- return
- end
- end
- end
- if fs.exists("warSession") then
- fs.move("warSession", ".discoverySession")
- end
- if fs.exists(".discoverySession") then
- local file = fs.open(".discoverySession", "r")
- newAddress = file.readLine()
- file.close()
- for i = 1, nineChevs and 9 or 7 do
- for j = 1, #symbols do
- if newAddress:sub(i, i) == symbols[j] then
- startChevron[i] = j
- break
- end
- end
- end
- end
- parallel.waitForAny(gateScanner, quit)
- print("\n")
- print("Dialed " .. tostring(numDials) .. " addresses in " .. tostring(numDials + numErrors) .. " tries\n")
- print("Had " .. tostring(numErrors) .. " errors\n")
- print("Found " .. tostring(numGates) .. " gates\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement