SHOW:
|
|
- or go back to the newest paste.
| 1 | local tArgs = {...}
| |
| 2 | local face = 0 | |
| 3 | local r = 1 | |
| 4 | local tturned = 0 | |
| 5 | rednet.open("left")
| |
| 6 | local cx,cy,cz = gps.locate(2,false) | |
| 7 | - | if #tArgs ~= 3 and #tArgs ~= 4 then |
| 7 | + | if #tArgs ~= 3 then |
| 8 | print("Incorrect usage of Function.")
| |
| 9 | - | --print("goto <x> <y> <z> (<Heading>)")
|
| 9 | + | --print("goto <x> <y> <z>")
|
| 10 | else | |
| 11 | local gx = tonumber(tArgs[1]) | |
| 12 | local gy = tonumber(tArgs[2]) | |
| 13 | local gz = tonumber(tArgs[3]) | |
| 14 | - | local enddirlet = tArgs[4] |
| 14 | + | |
| 15 | local y | |
| 16 | local z | |
| 17 | ||
| 18 | function tturnup() | |
| 19 | - | if enddirlet == "n" or enddirlet == "north" then |
| 19 | + | |
| 20 | - | enddir = 4 |
| 20 | + | |
| 21 | os.reboot() | |
| 22 | - | if enddirlet == "s" or enddirlet == "south" then |
| 22 | + | |
| 23 | - | enddir = 2 |
| 23 | + | |
| 24 | ||
| 25 | - | if enddirlet == "e" or enddirlet == "east" then |
| 25 | + | |
| 26 | - | enddir = 1 |
| 26 | + | |
| 27 | --write(gx) write(" ") write(gy) write(" ") print(gz)
| |
| 28 | - | if enddirlet == "w" or enddirlet == "west" then |
| 28 | + | |
| 29 | - | enddir = 3 |
| 29 | + | |
| 30 | if face >= 5 then | |
| 31 | face = 1 | |
| 32 | elseif face <= 0 then | |
| 33 | face = 4 | |
| 34 | end | |
| 35 | end | |
| 36 | function get_Face() | |
| 37 | while turtle.forward() == false do | |
| 38 | if turtle.up() == false then | |
| 39 | --turtle.digUp() | |
| 40 | end | |
| 41 | end | |
| 42 | ||
| 43 | nx,ny,nz = gps.locate(3,false) | |
| 44 | if nx > cx then | |
| 45 | face = 1 | |
| 46 | end | |
| 47 | if nx < cx then | |
| 48 | face = 3 | |
| 49 | end | |
| 50 | if nz > cz then | |
| 51 | face = 2 | |
| 52 | end | |
| 53 | if nz < cz then | |
| 54 | face = 4 | |
| 55 | end | |
| 56 | end | |
| 57 | function calc() | |
| 58 | x = nx - gx | |
| 59 | y = ny - gy | |
| 60 | z = nz - gz | |
| 61 | end | |
| 62 | function setDir(dir) | |
| 63 | while dir ~= face do | |
| 64 | c_face() | |
| 65 | if face >= dir then | |
| 66 | turtle.turnLeft() | |
| 67 | face = face - 1 | |
| 68 | tturnup() | |
| 69 | end | |
| 70 | if face < dir then | |
| 71 | turtle.turnRight() | |
| 72 | face = face + 1 | |
| 73 | tturnup() | |
| 74 | end | |
| 75 | c_face() | |
| 76 | end | |
| 77 | end | |
| 78 | function f() | |
| 79 | while not turtle.forward() do | |
| 80 | tturned = 0 | |
| 81 | if not turtle.up() then | |
| 82 | --turtle.digUp() | |
| 83 | end | |
| 84 | y = y + 1 | |
| 85 | end | |
| 86 | end | |
| 87 | function go() | |
| 88 | if x < 0 then | |
| 89 | setDir(1) | |
| 90 | while x ~= 0 do | |
| 91 | f() | |
| 92 | x = x + 1 | |
| 93 | end | |
| 94 | end | |
| 95 | if x > 0 then | |
| 96 | setDir(3) | |
| 97 | while x ~= 0 do | |
| 98 | f() | |
| 99 | x = x - 1 | |
| 100 | end | |
| 101 | end | |
| 102 | if z < 0 then | |
| 103 | setDir(2) | |
| 104 | while z ~= 0 do | |
| 105 | f() | |
| 106 | z = z + 1 | |
| 107 | end | |
| 108 | end | |
| 109 | if z > 0 then | |
| 110 | setDir(4) | |
| 111 | while z ~= 0 do | |
| 112 | f() | |
| 113 | z = z - 1 | |
| 114 | end | |
| 115 | end | |
| 116 | while y < 0 do | |
| 117 | if turtle.up() ~= true then | |
| 118 | --turtle.digUp() | |
| 119 | end | |
| 120 | y = y + 1 | |
| 121 | end | |
| 122 | while y > 0 do | |
| 123 | if turtle.down() ~= true then | |
| 124 | --turtle.digDown() | |
| 125 | end | |
| 126 | y = y - 1 | |
| 127 | end | |
| 128 | end | |
| 129 | ||
| 130 | ||
| 131 | ||
| 132 | tonumber(gx) | |
| 133 | tonumber(gy) | |
| 134 | tonumber(gz) | |
| 135 | PL() | |
| 136 | get_Face() | |
| 137 | calc() | |
| 138 | go() | |
| 139 | ||
| 140 | end | |
| 141 |