Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---orginal code by Povstalec
- interface = peripheral.find("crystal_interface")
- drive = peripheral.find("drive")
- monitor = peripheral.find("monitor")
- function dial_automatic(address) -- dialing for pegasus or universe stargate
- local addressLength = #address
- local start = interface.getChevronsEngaged() + 1
- for chevron = start,addressLength,1
- do
- local symbol = address[chevron]
- interface.engageSymbol(symbol)
- end
- end
- function dial_manual(address)
- local addressLength = #address
- local start = interface.getChevronsEngaged() + 1
- for chevron = start,addressLength,1
- do
- --This is a loop that will go through all the
- --symbols in an address
- local symbol = address[chevron]
- if chevron % 2 == 0 then
- interface.rotateClockwise(symbol)
- else
- interface.rotateAntiClockwise(symbol)
- end
- --Here we're basically making sure the gate ring
- --rotates clockwise when the number of chevrons
- --engaged is even and counter-clockwise when odd
- while(not interface.isCurrentSymbol(symbol))
- do
- sleep(0)
- end
- sleep(1)
- --We want to wait 1 second before we
- --engage the chevron
- interface.openChevron() --This opens the chevron
- sleep(1)
- interface.closeChevron() -- and this closes it
- sleep(1)
- end
- end
- -- MAIN DIALING CODE
- function dial(address)
- sg_type = interface.getStargateType()
- if sg_type == "sgjourney:universe_stargate" or sg_type == "sgjourney:pegasus_stargate" then
- dial_automatic(address)
- else
- dial_manual(address)
- end
- end
- -- Disk saving system
- function save_address(address,label)
- if drive then
- local file = fs.open("disk/data.txt", "w")
- file.write(address)
- file.close()
- drive.setDiskLabel(label)
- else
- print("Error: No disk detected. Please insert a diskette and try again.")
- end
- end
- drive = peripheral.find("drive")
- function read_disk()
- if drive.hasData() then
- local file = fs.open("disk/data.txt", "r")
- local address = file.readAll()
- local label = drive.getDiskLabel()
- file.close()
- print(address)
- -- Hier wird die Funktion auf das disk-Objekt angewendet
- return address, label
- else
- print("Error: No disk detected. Please insert a diskette and try again.")
- return nil, nil
- end
- end
- function add_address()
- print("Please enter the address:")
- local address = io.read()
- print("Please enter the label:")
- local label = io.read()
- save_address(address, label)
- end
- function address_encode(address)
- local arr_address = {}
- for part in address:gmatch("[^-]+") do
- if part ~= nil then
- num = tonumber(part)
- table.insert(arr_address, tonumber(num))
- end
- end
- table.insert(arr_address, 0)
- return arr_address
- end
- --MONITOR
- function draw_monitor()
- monitor.clear()
- monitor.setCursorPos(1, 1)
- if interface.isStargateConnected() then
- monitor.setTextColor(colors.green)
- monitor.write("CONNECTED")
- elseif interface.isStargateDialingOut() then
- monitor.setTextColor(colors.yellow)
- monitor.write("DIALING")
- elseif interface.isWormholeOpen() then
- monitor.setTextColor(colors.red)
- monitor.write("CONECTING")
- else
- monitor.setTextColor(colors.white)
- monitor.write("IDLE")
- end
- monitor.setCursorPos(1, 2)
- monitor.write(interface.getOpenTime())
- monitor.setCursorPos(1, 3)
- --if interface.isStargateConnected() then
- -- monitor.write(interface.getConnectedAddress())
- --else
- -- monitor.write("")
- --end
- monitor.setCursorPos(1, 4)
- monitor.setTextColor(colors.blue)
- monitor.write(interface.getStargateEnergy())
- --monitor.setCursorPos(1, 5)
- --monitor.write(interface.getLocalAddress())
- end
- -- MAINLOOP
- while true do
- draw_monitor()
- local redstoneInput_bottom = redstone.getInput("bottom")
- local redstoneInput_top = redstone.getInput("top")
- if redstoneInput_top then
- if interface.isStargateConnected() == false then
- address, label = read_disk()
- if address ~= nil then
- encoded_address = address_encode(address)
- dial(encoded_address)
- end
- else
- interface.disconnectStargate()
- end
- elseif redstoneInput_bottom then
- add_address()
- end
- os.sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement