Guest User

CC:Tweaked x StargateJourney

a guest
Aug 6th, 2025
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. -- Define the name of the stargate this computer is connected to
  2. local stargateName = "<Stargate>" --Placeholder
  3.  
  4. -- Define API address
  5. local API = "192.168.1.41/sg-command"
  6. local status = "192.168.1.41/sg-status"
  7.  
  8. -- Locate the Stargate interface peripheral
  9. local interface = peripheral.find("advanced_crystal_interface") or peripheral.find("crystal_interface") or peripheral.find("basic_interface")
  10.  
  11. -- List all Stargates and address
  12. local Gates = { --Placeholders
  13. home = {27,25,4,25,10,28,3,0},
  14. farms = {26,6,14,31,33,11,29,0}
  15. }
  16.  
  17.  
  18. -- Check if the interface exists
  19. if interface == nil then
  20. print("No Stargate interface found.")
  21. end
  22.  
  23. -- Check if the interface is connected to the stargate
  24. if interface.isStargateConnected() then
  25. print("Stargate is connected.")
  26. else
  27. print("Stargate is not connected.")
  28. end
  29.  
  30. -- Function to rotate the gate to a specific symbol
  31. local function rotateToSymbol(symbol, direction)
  32. local current = interface.getCurrentSymbol()
  33. while current ~= symbol do
  34. if direction == "clockwise" then
  35. interface.rotateClockwise(symbol)
  36. else
  37. interface.rotateAntiClockwise(symbol)
  38. end
  39. os.sleep(0.1)
  40. current = interface.getCurrentSymbol()
  41. end
  42. end
  43.  
  44. -- Function to dial a Stargate by address (table of 8–9 numbers)
  45. local function dialStargate(address)
  46. if #address < 8 or #address > 9 then
  47. error("Invalid address length. Must be 8 or 9 symbols.")
  48.  
  49. end
  50.  
  51. print("Beginning dialing sequence...")
  52.  
  53. -- Start with clockwise rotation
  54. local direction = "clockwise"
  55.  
  56. for i, symbol in ipairs(address) do
  57. print("Dialing symbol " .. i .. ": " .. symbol)
  58. rotateToSymbol(symbol, direction)
  59. if interface.getCurrentSymbol() == symbol then
  60. interface.openChevron()
  61. os.sleep(1)
  62. interface.encodeChevron()
  63. end
  64.  
  65. os.sleep(0.2)
  66. -- Alternate direction after each symbol
  67. direction = (direction == "clockwise") and "antiClockwise" or "clockwise"
  68. end
  69. end
  70.  
  71. -- Function to close wormhole
  72. local function closeStargate()
  73. if interface.isStargateConnected() then
  74. print("Closing Stargate")
  75. interface.disconnectStargate()
  76. end
  77.  
  78. if interface.isStargateConnected() == false then
  79. print("Stargate Closed")
  80. end
  81. end
  82.  
  83. local function openIris()
  84. if interface.getIris() then
  85. interface.openIris()
  86. -- Wait until iris is fully open
  87. while interface.getIrisProgressPercentage() ~= 0 do
  88. os.sleep(0.1)
  89. end
  90. print("Iris is fully open.")
  91. return true
  92. else
  93. print("No iris installed.")
  94. return false
  95. end
  96. end
  97.  
  98. local function closeIris()
  99. if interface.getIris() then
  100. interface.closeIris()
  101. -- Wait until iris is fully closed
  102. while interface.getIrisProgressPercentage() ~= 100 do
  103. os.sleep(0.1)
  104. end
  105. print("Iris is fully closed.")
  106. return true
  107. else
  108. print("No iris installed.")
  109. return false
  110. end
  111. end
  112.  
  113. -- main loop
  114. term.write("pulling latest command from API")
  115. local last_action, last_from, last_to = nil, nil, nil
  116.  
  117. while true do
  118. local response = http.get(API)
  119. if response then
  120. local body = response.readAll()
  121. response.close()
  122. local data = textutils.unserializeJSON(body)
  123.  
  124. if data and data.action and data.from == stargateName then
  125. -- Compare only relevant fields, handling missing "to"
  126. local is_new = data.action ~= last_action or data.from ~= last_from or data.to ~= last_to
  127.  
  128. if is_new then
  129. local gate = data.to and Gates[data.to] or nil
  130.  
  131. if data.action == "open" and gate then
  132. dialStargate(gate)
  133. end
  134. if data.action == "close" then
  135. closeStargate()
  136. end
  137. if data.action == "iris-open" then
  138. openIris()
  139. end
  140. if data.action == "iris-close" then
  141. closeIris()
  142. end
  143.  
  144. -- Update last command fields
  145. last_action = data.action
  146. last_from = data.from
  147. last_to = data.to
  148. end
  149. end
  150. end
  151. os.sleep(1)
  152. end
  153.  
Advertisement
Add Comment
Please, Sign In to add comment