Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ship = peripheral.find("warpdriveShipCore")
- local miningLaser = peripheral.find("warpdriveMiningLaser")
- local chat = peripheral.find("warpdriveVirtualAssistant")
- -- Define chat name
- chat.name("[name")
- local ship_front, ship_right, ship_up = ship.dim_positive()
- local ship_back, ship_left, ship_down = ship.dim_negative()
- local ship_isInHyper = ship.isInHyperspace()
- local ship_movement = { ship.movement() }
- local ship_rotationSteps = ship.rotationSteps()
- print("Post Way Point in Chat to Jump Ship and Aligning the Mining Laser")
- while true do
- sleep(0.08)
- local state, CMD = chat.pullLastCommand()
- -- Convert the command to lowercase safely and avoid overwriting the string library.
- local cmdText = string.lower(CMD or "")
- -- Adjust the pattern to allow preceding text (if any) before the coordinates.
- local x_value, y_value, z_value = cmdText:match("*x:(%d+),%s*y:(%d+),%s*z:(%d+)")
- if state then
- if not (x_value and y_value and z_value) then
- print("Error: Coordinates not found in command.")
- else
- local lastLx = tonumber(x_value)
- local lastLy = tonumber(y_value) -- if needed for future use
- local lastLz = tonumber(z_value)
- print("Jumping to X:" .. lastLx .. ", Y:" .. lastLy .. ", Z:" .. lastLz)
- local rx, ry, rz = ship.getOrientation()
- local minForwardBack = math.abs(ship_front + ship_back + 1)
- local minLeftRight = math.abs(ship_left + ship_right + 1)
- local mx, my, mz = miningLaser.getLocalPosition()
- local dx = lastLx - mx
- local dz = lastLz - mz
- local forwardBackMov = 0
- local leftRightMov = 0
- -- Determine movement based on ship's orientation.
- if rx == 1 then
- forwardBackMov = dx
- leftRightMov = dz
- elseif rx == -1 then
- forwardBackMov = -dx
- leftRightMov = -dz
- elseif rz == 1 then
- forwardBackMov = dz
- leftRightMov = -dx
- elseif rz == -1 then
- forwardBackMov = -dz
- leftRightMov = dx
- end
- if math.abs(forwardBackMov) < minForwardBack and math.abs(leftRightMov) < minLeftRight then
- print("The movement is too small!")
- else
- ship.movement(forwardBackMov, 0, leftRightMov)
- ship.rotationSteps(0)
- ship.command("MANUAL", true)
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement