Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local addresses = {
- {input = "MSA", output = "-22-2-11-6-30-33-17-12-", here = true},
- {input = "nether", output = "-1-35-6-31-15-28-32-", here = false},
- {input = "end", output = "-18-24-8-16-7-35-30-", here = false},
- {input = "abydos", output = "-1-17-2-34-26-9-33-", here = false},
- {input = "chulak", output = "-1-9-14-21-17-3-29-", here = false},
- {input = "cavum_tenebrae", output = "-1-34-12-18-7-31-6-", here = false},
- {input = "lantea", output = "-18-20-1-15-14-7-19-", here = false},
- }
- -- Function to list addresses
- function listAddresses()
- print("Available addresses:")
- for _, address in ipairs(addresses) do
- print("- " .. address.input .. ": " .. address.output)
- if address.here then
- print(" -- you are here!")
- end
- end
- end
- -- Function to find the address and return it
- function findAddress(userInput)
- local lowerInput = userInput:lower() -- Convert input to lowercase for case-insensitivity
- for _, address in ipairs(addresses) do
- if lowerInput == address.input:lower() then
- return address
- end
- end
- return nil
- end
- -- Function to print the address
- function printAddress(address)
- if address then
- print("Address for " .. address.input .. ": " .. address.output)
- if address.here then
- print(" -- you are here!")
- end
- else
- print("Unknown address. Type 'list' to see available addresses,")
- print("or type 'help' to list all commands.")
- end
- end
- -- Function to dial the address
- function dialAddress(address)
- if not interface.isStargateConnected() then
- if type(address) == "table" then
- print("Dialling address: " .. address.input .. " (" .. address.output .. ")")
- local addressArray = {}
- for symbol in address.output:gmatch("-([^%-]+)") do
- table.insert(addressArray, tonumber(symbol))
- end
- local start = interface.getChevronsEngaged() + 1
- for _, symbol in ipairs(addressArray) do
- interface.engageSymbol(symbol)
- end
- print("Dialling complete.")
- else
- print("Unable to dial. Invalid address.")
- end
- else
- print("Stargate is already connected. Cannot dial address.")
- end
- end
- -- Function to list commands
- function listCommands(isMain)
- print("Available commands:")
- print("- quit/exit")
- if not isMain then
- print(" -- Exits the dialler")
- else
- print(" -- Returns to the command line.")
- end
- print("- help/commands")
- print(" -- Prints this menu.")
- print("- list/addresses")
- print(" -- Prints all addresses.")
- print("- clear")
- print(" -- Clears the screen.")
- if isMain or interface then
- print("- dialler")
- print(" -- Opens the dialler.")
- end
- if not isMain then
- print("- close")
- print(" -- Closes the wormhole")
- end
- end
- -- Function to handle the dialler
- function dialler()
- print("Welcome to the Stargate dialler!")
- print("Enter an address manually or choose one from the list:")
- print("Type 'list' to see available addresses.")
- while true do
- local userInput = read():lower()
- if userInput == "quit" or userInput == "exit" or userInput == "close" then
- main() -- Return to main menu
- elseif userInput == "commands" or userInput == "help" then
- listCommands(false) -- Show commands without dialler-specific options
- elseif userInput == "list" or userInput == "addresses" then
- listAddresses()
- elseif userInput == "clear" then
- term.clear()
- else
- local address = findAddress(userInput)
- if address then
- dialAddress(address)
- else
- -- Assume userInput is a manual address entry
- local manualAddress = stringToNumberArray(userInput)
- print("Dialling manually entered address: " .. table.concat(manualAddress, "-"))
- dialAddress(manualAddress)
- end
- end
- end
- end
- -- Main function to handle menu
- function main()
- interface = peripheral.find("advanced_crystal_interface")
- print("Stargate address book v2:")
- print("Type 'list' to see available addresses.")
- print("Type 'help' to see available commands.")
- if interface then
- print("Dialler available. Type 'dialler' to open")
- end
- while true do
- local userInput = read():lower()
- if userInput == "quit" or userInput == "exit" then
- return
- elseif userInput == "commands" or userInput == "help" then
- listCommands(true) -- Show commands with main-specific options
- elseif userInput == "list" or userInput == "addresses" then
- listAddresses()
- elseif userInput == "clear" then
- term.clear()
- elseif userInput == "dialler" then
- if not interface then
- print("Interface not found")
- print("Dialler not available")
- print("Please connect interface to use the dialler")
- else
- dialler()
- end
- else
- local address = findAddress(userInput)
- printAddress(address)
- end
- end
- end
- main() -- Start the program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement