Advertisement
minecrafter0001

stargate address book with dialler

Feb 21st, 2024 (edited)
925
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local addresses = {
  2.     {input = "MSA", output = "-22-2-11-6-30-33-17-12-", here = true},
  3.     {input = "nether", output = "-1-35-6-31-15-28-32-", here = false},
  4.     {input = "end", output = "-18-24-8-16-7-35-30-", here = false},
  5.     {input = "abydos", output = "-1-17-2-34-26-9-33-", here = false},
  6.     {input = "chulak", output = "-1-9-14-21-17-3-29-", here = false},
  7.     {input = "cavum_tenebrae", output = "-1-34-12-18-7-31-6-", here = false},
  8.     {input = "lantea", output = "-18-20-1-15-14-7-19-", here = false},
  9. }
  10.  
  11. -- Function to list addresses
  12. function listAddresses()
  13.     print("Available addresses:")
  14.     for _, address in ipairs(addresses) do
  15.         print("- " .. address.input .. ": " .. address.output)
  16.         if address.here then
  17.             print("  -- you are here!")
  18.         end
  19.     end
  20. end
  21.  
  22. -- Function to find the address and return it
  23. function findAddress(userInput)
  24.     local lowerInput = userInput:lower()  -- Convert input to lowercase for case-insensitivity
  25.     for _, address in ipairs(addresses) do
  26.         if lowerInput == address.input:lower() then
  27.             return address
  28.         end
  29.     end
  30.     return nil
  31. end
  32.  
  33. -- Function to print the address
  34. function printAddress(address)
  35.     if address then
  36.         print("Address for " .. address.input .. ": " .. address.output)
  37.         if address.here then
  38.             print("  -- you are here!")
  39.         end
  40.     else
  41.         print("Unknown address. Type 'list' to see available addresses,")
  42.         print("or type 'help' to list all commands.")
  43.     end
  44. end
  45.  
  46. -- Function to dial the address
  47. function dialAddress(address)
  48.     if not interface.isStargateConnected() then
  49.         if type(address) == "table" then
  50.             print("Dialling address: " .. address.input .. " (" .. address.output .. ")")
  51.             local addressArray = {}
  52.             for symbol in address.output:gmatch("-([^%-]+)") do
  53.                 table.insert(addressArray, tonumber(symbol))
  54.             end
  55.  
  56.             local start = interface.getChevronsEngaged() + 1
  57.  
  58.             for _, symbol in ipairs(addressArray) do
  59.                 interface.engageSymbol(symbol)
  60.             end
  61.  
  62.             print("Dialling complete.")
  63.         else
  64.             print("Unable to dial. Invalid address.")
  65.         end
  66.     else
  67.         print("Stargate is already connected. Cannot dial address.")
  68.     end
  69. end
  70.  
  71. -- Function to list commands
  72. function listCommands(isMain)
  73.     print("Available commands:")
  74.     print("- quit/exit")
  75.     if not isMain then
  76.         print("  -- Exits the dialler")
  77.     else
  78.         print("  -- Returns to the command line.")
  79.     end
  80.     print("- help/commands")
  81.     print("  -- Prints this menu.")
  82.     print("- list/addresses")
  83.     print("  -- Prints all addresses.")
  84.     print("- clear")
  85.     print("  -- Clears the screen.")
  86.     if isMain or interface then
  87.         print("- dialler")
  88.         print("  -- Opens the dialler.")
  89.     end
  90.     if not isMain then
  91.         print("- close")
  92.         print("  -- Closes the wormhole")
  93.     end
  94. end
  95.  
  96. -- Function to handle the dialler
  97. function dialler()
  98.     print("Welcome to the Stargate dialler!")
  99.     print("Enter an address manually or choose one from the list:")
  100.     print("Type 'list' to see available addresses.")
  101.    
  102.     while true do
  103.         local userInput = read():lower()
  104.        
  105.         if userInput == "quit" or userInput == "exit" or userInput == "close" then
  106.             main()  -- Return to main menu
  107.         elseif userInput == "commands" or userInput == "help" then
  108.             listCommands(false)  -- Show commands without dialler-specific options
  109.         elseif userInput == "list" or userInput == "addresses" then
  110.             listAddresses()
  111.         elseif userInput == "clear" then
  112.             term.clear()
  113.         else
  114.             local address = findAddress(userInput)
  115.             if address then
  116.                 dialAddress(address)
  117.             else
  118.                 -- Assume userInput is a manual address entry
  119.                 local manualAddress = stringToNumberArray(userInput)
  120.                 print("Dialling manually entered address: " .. table.concat(manualAddress, "-"))
  121.                 dialAddress(manualAddress)
  122.             end
  123.         end
  124.     end
  125. end
  126.  
  127. -- Main function to handle menu
  128. function main()
  129.     interface = peripheral.find("advanced_crystal_interface")
  130.     print("Stargate address book v2:")
  131.     print("Type 'list' to see available addresses.")
  132.     print("Type 'help' to see available commands.")
  133.    
  134.     if interface then
  135.         print("Dialler available. Type 'dialler' to open")
  136.     end
  137.    
  138.     while true do
  139.         local userInput = read():lower()
  140.        
  141.         if userInput == "quit" or userInput == "exit" then
  142.             return
  143.         elseif userInput == "commands" or userInput == "help" then
  144.             listCommands(true)  -- Show commands with main-specific options
  145.         elseif userInput == "list" or userInput == "addresses" then
  146.             listAddresses()
  147.         elseif userInput == "clear" then
  148.             term.clear()
  149.         elseif userInput == "dialler" then
  150.             if not interface then
  151.                 print("Interface not found")
  152.                 print("Dialler not available")
  153.                 print("Please connect interface to use the dialler")
  154.             else
  155.                 dialler()
  156.             end
  157.         else
  158.             local address = findAddress(userInput)
  159.             printAddress(address)
  160.         end
  161.     end
  162. end
  163.  
  164. main()  -- Start the program
  165.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement