Advertisement
LostRanger

StargateJourney_CC_dial (non working test)

May 1st, 2024 (edited)
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.68 KB | Gaming | 0 0
  1. ---orginal code by Povstalec
  2.  
  3.  
  4. interface = peripheral.find("crystal_interface")
  5. drive = peripheral.find("drive")
  6. monitor = peripheral.find("monitor")
  7.  
  8. function dial_automatic(address) -- dialing for pegasus or universe stargate
  9.     local addressLength = #address
  10.     local start = interface.getChevronsEngaged() + 1
  11.  
  12.     for chevron = start,addressLength,1
  13.     do        
  14.         local symbol = address[chevron]
  15.         interface.engageSymbol(symbol)  
  16.     end
  17. end
  18.  
  19. function dial_manual(address)
  20.     local addressLength = #address
  21.     local start = interface.getChevronsEngaged() + 1
  22.  
  23.     for chevron = start,addressLength,1
  24.     do
  25.         --This is a loop that will go through all the
  26.         --symbols in an address
  27.        
  28.         local symbol = address[chevron]
  29.        
  30.         if chevron % 2 == 0 then
  31.             interface.rotateClockwise(symbol)
  32.         else
  33.             interface.rotateAntiClockwise(symbol)
  34.         end
  35.         --Here we're basically making sure the gate ring
  36.         --rotates clockwise when the number of chevrons
  37.         --engaged is even and counter-clockwise when odd
  38.        
  39.         while(not interface.isCurrentSymbol(symbol))
  40.         do
  41.             sleep(0)
  42.         end
  43.         sleep(1)
  44.         --We want to wait 1 second before we
  45.         --engage the chevron
  46.         interface.openChevron() --This opens the chevron
  47.         sleep(1)
  48.         interface.closeChevron() -- and this closes it
  49.         sleep(1)        
  50.     end
  51. end
  52.  
  53. -- MAIN DIALING CODE
  54. function dial(address)
  55.     sg_type = interface.getStargateType()
  56.     if sg_type == "sgjourney:universe_stargate" or sg_type == "sgjourney:pegasus_stargate" then
  57.         dial_automatic(address)
  58.     else
  59.         dial_manual(address)
  60.     end
  61. end
  62.  
  63.  
  64. -- Disk saving system
  65.  
  66. function save_address(address,label)
  67.     if drive then
  68.         local file = fs.open("disk/data.txt", "w")
  69.         file.write(address)
  70.         file.close()
  71.         drive.setDiskLabel(label)
  72.     else
  73.         print("Error: No disk detected. Please insert a diskette and try again.")
  74.     end
  75. end
  76. drive = peripheral.find("drive")
  77. function read_disk()
  78.     if drive.hasData() then
  79.         local file = fs.open("disk/data.txt", "r")
  80.         local address = file.readAll()
  81.         local label = drive.getDiskLabel()
  82.         file.close()
  83.         print(address)
  84.          -- Hier wird die Funktion auf das disk-Objekt angewendet
  85.         return address, label
  86.     else
  87.         print("Error: No disk detected. Please insert a diskette and try again.")
  88.         return nil, nil
  89.     end
  90. end
  91.  
  92. function add_address()
  93.     print("Please enter the address:")
  94.     local address = io.read()
  95.     print("Please enter the label:")
  96.     local label = io.read()
  97.  
  98.     save_address(address, label)
  99. end
  100.  
  101. function address_encode(address)
  102.     local arr_address = {}
  103.     for part in address:gmatch("[^-]+") do
  104.         if part ~= nil then
  105.             num = tonumber(part)
  106.             table.insert(arr_address, tonumber(num))
  107.         end
  108.     end
  109.     table.insert(arr_address, 0)
  110.     return arr_address
  111. end
  112.  
  113. --MONITOR
  114. function draw_monitor()
  115.     monitor.clear()
  116.     monitor.setCursorPos(1, 1)
  117.     if interface.isStargateConnected() then
  118.         monitor.setTextColor(colors.green)
  119.         monitor.write("CONNECTED")
  120.     elseif interface.isStargateDialingOut() then
  121.         monitor.setTextColor(colors.yellow)
  122.         monitor.write("DIALING")
  123.     elseif interface.isWormholeOpen() then
  124.         monitor.setTextColor(colors.red)
  125.         monitor.write("CONECTING")
  126.     else
  127.         monitor.setTextColor(colors.white)
  128.         monitor.write("IDLE")
  129.     end  
  130.     monitor.setCursorPos(1, 2)
  131.     monitor.write(interface.getOpenTime())
  132.     monitor.setCursorPos(1, 3)
  133.     --if interface.isStargateConnected() then
  134.     --    monitor.write(interface.getConnectedAddress())
  135.     --else
  136.     --    monitor.write("")
  137.     --end
  138.     monitor.setCursorPos(1, 4)
  139.     monitor.setTextColor(colors.blue)
  140.     monitor.write(interface.getStargateEnergy())
  141.     --monitor.setCursorPos(1, 5)
  142.     --monitor.write(interface.getLocalAddress())
  143. end
  144.  
  145. -- MAINLOOP
  146.  
  147. while true do
  148.     draw_monitor()
  149.  
  150.     local redstoneInput_bottom = redstone.getInput("bottom")
  151.     local redstoneInput_top = redstone.getInput("top")
  152.     if redstoneInput_top then
  153.         if interface.isStargateConnected() == false then
  154.             address, label = read_disk()
  155.             if address ~= nil then
  156.                 encoded_address = address_encode(address)
  157.                 dial(encoded_address)
  158.             end
  159.         else
  160.            interface.disconnectStargate()
  161.         end
  162.     elseif redstoneInput_bottom then
  163.         add_address()
  164.     end
  165.    
  166.     os.sleep(1)
  167. end
  168.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement