View difference between Paste ID: CbvFb1yL and 9iLmqFxc
SHOW: | | - or go back to the newest paste.
1
local ship = peripheral.find("warpdriveShipController")
2-
local miningLaser = peripheral.find("warpdriveMiningLaser")
2+
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")
14+
print("Post Way Point in Chat to Jump Ship")
15
16
while true do
17
sleep(0.08)
18
local state = 0
19
local CMD = 0
20
  state, CMD = chat.pullLastCommand()
21
    string = string.lower(CMD)
22
 
23
      -- Match and extract X and Z
24
 local x_value, y_value, z_value = string:match(".*x:(%-?%d+),%s*y:(%-?%d+),%s*z:(%-?%d+)")
25
    
26
    if state then
27
        if not (x_value and y_value and z_value) then
28
            print("Error: Coordinates not found in command.")
29
        else
30
            local lastLx = tonumber(x_value)
31
            local lastLy = tonumber(y_value)  -- if needed for future use
32
            local lastLz = tonumber(z_value)
33
            
34
            print("Jumping to X:" .. lastLx .. ", Z:" .. lastLz)
35
            
36
            local rx, ry, rz = ship.getOrientation()
37
            local minForwardBack = math.abs(ship_front + ship_back + 1)
38
            local minLeftRight = math.abs(ship_left + ship_right + 1)
39-
            local mx, my, mz = miningLaser.getLocalPosition()
39+
            local mx, my, mz = ship.getLocalPosition()
40
            
41
            local dx = lastLx - mx
42
            local dz = lastLz - mz
43
            
44
            local forwardBackMov = 0
45
            local leftRightMov = 0
46
            
47
            -- Determine movement based on ship's orientation.
48
            if rx == 1 then
49
                forwardBackMov = dx
50
                leftRightMov = dz
51
            elseif rx == -1 then
52
                forwardBackMov = -dx
53
                leftRightMov = -dz
54
            elseif rz == 1 then
55
                forwardBackMov = dz
56
                leftRightMov = -dx
57
            elseif rz == -1 then
58
                forwardBackMov = -dz
59
                leftRightMov = dx
60
            end
61
            
62
            if math.abs(forwardBackMov) < minForwardBack and math.abs(leftRightMov) < minLeftRight then
63
                print("The movement is too small!")
64
            else
65
                ship.movement(forwardBackMov, 0, leftRightMov)
66
                ship.rotationSteps(0)
67
                ship.command("MANUAL", true)
68
            end
69
        end
70
    end
71
end
72