Advertisement
jaklsfjlsak

智能修复语音制导318-25

Mar 18th, 2025 (edited)
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.67 KB | None | 0 0
  1. local ship = peripheral.find("warpdriveShipCore")
  2. local miningLaser = peripheral.find("warpdriveMiningLaser")
  3. local chat = peripheral.find("warpdriveVirtualAssistant")
  4.  
  5. -- Define chat name
  6. chat.name("[name")
  7.  
  8. local ship_front, ship_right, ship_up = ship.dim_positive()
  9. local ship_back, ship_left, ship_down = ship.dim_negative()
  10. local ship_isInHyper = ship.isInHyperspace()
  11. local ship_movement = { ship.movement() }
  12. local ship_rotationSteps = ship.rotationSteps()
  13.  
  14. print("Post Way Point in Chat to Jump Ship and Aligning the Mining Laser")
  15.  
  16. while true do
  17.     sleep(0.08)
  18.    
  19.     local state, CMD = chat.pullLastCommand()
  20.    
  21.     -- Convert the command to lowercase safely and avoid overwriting the string library.
  22.     local cmdText = string.lower(CMD or "")
  23.  
  24.    
  25.     -- Adjust the pattern to allow preceding text (if any) before the coordinates.
  26.     local x_value, y_value, z_value = cmdText:match("*x:(%d+),%s*y:(%d+),%s*z:(%d+)")
  27.    
  28.     if state then
  29.         if not (x_value and y_value and z_value) then
  30.             print("Error: Coordinates not found in command.")
  31.         else
  32.             local lastLx = tonumber(x_value)
  33.             local lastLy = tonumber(y_value)  -- if needed for future use
  34.             local lastLz = tonumber(z_value)
  35.            
  36.             print("Jumping to X:" .. lastLx .. ", Y:" .. lastLy .. ", Z:" .. lastLz)
  37.            
  38.             local rx, ry, rz = ship.getOrientation()
  39.             local minForwardBack = math.abs(ship_front + ship_back + 1)
  40.             local minLeftRight = math.abs(ship_left + ship_right + 1)
  41.             local mx, my, mz = miningLaser.getLocalPosition()
  42.            
  43.             local dx = lastLx - mx
  44.             local dz = lastLz - mz
  45.            
  46.             local forwardBackMov = 0
  47.             local leftRightMov = 0
  48.            
  49.             -- Determine movement based on ship's orientation.
  50.             if rx == 1 then
  51.                 forwardBackMov = dx
  52.                 leftRightMov = dz
  53.             elseif rx == -1 then
  54.                 forwardBackMov = -dx
  55.                 leftRightMov = -dz
  56.             elseif rz == 1 then
  57.                 forwardBackMov = dz
  58.                 leftRightMov = -dx
  59.             elseif rz == -1 then
  60.                 forwardBackMov = -dz
  61.                 leftRightMov = dx
  62.             end
  63.            
  64.             if math.abs(forwardBackMov) < minForwardBack and math.abs(leftRightMov) < minLeftRight then
  65.                 print("The movement is too small!")
  66.             else
  67.                 ship.movement(forwardBackMov, 0, leftRightMov)
  68.                 ship.rotationSteps(0)
  69.                 ship.command("MANUAL", true)
  70.             end
  71.         end
  72.     end
  73. end
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement