Advertisement
jaklsfjlsak

Dest 自动驾驶

Apr 13th, 2025
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.09 KB | None | 0 0
  1. local core = peripheral.find("warpdriveShipCore")
  2.     -- Get the current position
  3.     local currentX, currentY, currentZ = core.getLocalPosition()
  4. core.enable(true)
  5. core.command("IDLE", false)
  6.    
  7. local    targetX =
  8. local    targetY =
  9. local    targetZ =
  10.  
  11. -- Make sure the temp file exists --
  12. if fs.exists("temp") then
  13. else
  14.     fs.open("temp", "w")
  15.     local h = fs.open("temp", "w")
  16.     h.close()
  17. end
  18. ------------------------------------
  19.  
  20. local h = fs.open("temp", "r")
  21. if h.readAll() == "t" then
  22.     h.close()
  23.  
  24. -- Calculate the required movement
  25. local LatMove = targetX - currentX
  26. local VerMove = targetY - currentY
  27. local ForMove = targetZ - currentZ
  28.  
  29. -- Check if both targetX and currentX are negative and their sum is positive
  30. if targetX < 0 and currentX < 0 and (targetX - currentX) > 0 then
  31.     -- Flip the sign of the sum to make it negative
  32.     local flip = (targetX - currentX) * -1
  33.     LatMove = flip
  34. end
  35.  
  36. -- Check if both targetZ and currentZ are negative and their sum is positive
  37. if targetZ < 0 and currentZ < 0 and (targetZ - currentZ) > 0 then
  38.     -- Flip the sign of the sum to make it negative
  39.     local flip = (targetZ - currentZ) * -1
  40.     ForMove = flip
  41. end
  42.  
  43.  
  44.     print("Calculated Movement")
  45.     print(ForMove, VerMove, LatMove)
  46.     core.movement(ForMove, VerMove, LatMove)
  47.    
  48.     print("")
  49.  
  50.     print("Continually jumping...")
  51.     core.enable(true)
  52.     core.command("IDLE", false)
  53.     sleep(1)
  54.     core.command("MANUAL", true)
  55.     print("Press `space` to stop jumping")
  56.  
  57.     local event, key = os.pullEvent("key")
  58.     if key == keys.space then
  59.         local h = fs.open("temp", "w")
  60.         h.writeLine("f")
  61.         h.close()
  62.         print("Movement stopped for next jump")
  63.     end
  64. else
  65.     h.close()
  66.  
  67.  
  68.     -- Input the target coordinates
  69. --    print("Please input target X coordinate: ")
  70. --    targetX = tonumber(read())
  71. --    print("Please input target Y coordinate: ")
  72. --    targetY = tonumber(read())
  73. --    print("Please input target Z coordinate: ")
  74. --    targetZ = tonumber(read())
  75.  
  76. -- Calculate the required movement
  77. local ForMove = targetX - currentX
  78. local VerMove = targetY - currentY
  79. local LatMove = targetZ - currentZ
  80.  
  81. -- Check if both targetX and currentX are negative and their sum is positive
  82. if targetX < 0 and currentX < 0 and (targetX - currentX) > 0 then
  83.     -- Flip the sign of the sum to make it negative
  84.     local flip = (targetX + currentX) * -1
  85.     LatMove = flip
  86. end
  87.  
  88. -- Check if both targetZ and currentZ are negative and their sum is positive
  89. if targetZ < 0 and currentZ < 0 and (targetZ - currentZ) > 0 then
  90.     -- Flip the sign of the sum to make it negative
  91.     local flip = (targetZ + currentZ) * -1
  92.     ForMove = flip
  93. end
  94.  
  95.     print("Calculated Movement")
  96.     print(ForMove, VerMove, LatMove)
  97.     core.movement(ForMove, VerMove, LatMove)
  98.    
  99.     print("")
  100.    
  101.     print("Starting continual jumping")
  102.     print("Press `Space` after a jump to stop jumping")
  103.  
  104.     core.command("MANUAL", true)
  105.     print("Starting Auto-pilot")
  106.  
  107.     local h = fs.open("temp", "w")
  108.     h.write("t")
  109.     h.close()
  110. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement