SHOW:
|
|
- or go back to the newest paste.
| 1 | local tArgs = {...}
| |
| 2 | trans={}
| |
| 3 | - | trans[1]="north" |
| 3 | + | trans[0]="north" |
| 4 | - | trans[2]="east" |
| 4 | + | trans[1]="west" |
| 5 | - | trans[3]="south" |
| 5 | + | trans[2]="south" |
| 6 | - | trans[0]="west" |
| 6 | + | trans[3]="east" |
| 7 | ||
| 8 | - | if #tArgs ~= 8 then |
| 8 | + | if #tArgs ~= 9 then |
| 9 | print("Not enough Arguments")
| |
| 10 | error() | |
| 11 | end | |
| 12 | ||
| 13 | --[[if tArgs[4] ~= "north" then | |
| 14 | elseif tArgs[4] ~= "east" then | |
| 15 | elseif tArgs[4] ~= "south" then | |
| 16 | elseif tArgs[4] ~= "west" then | |
| 17 | for k,v in pairs(trans) do | |
| 18 | if tArgs[4] == k | |
| 19 | then tArgs[4] = v | |
| 20 | end | |
| 21 | end | |
| 22 | else | |
| 23 | print("Argument 4 must be = north, east, south or west.")
| |
| 24 | error() | |
| 25 | end]]-- | |
| 26 | ||
| 27 | for k,v in pairs(trans) do | |
| 28 | if tArgs[4] == v | |
| 29 | then tArgs[4] = k | |
| 30 | end | |
| 31 | end | |
| 32 | ||
| 33 | - | print(tArgs[4]) |
| 33 | + | local cDir = tonumber(tArgs[4]) |
| 34 | local cX = tonumber(tArgs[1]) | |
| 35 | - | local cDir = tArgs[4] |
| 35 | + | |
| 36 | local cZ = tonumber(tArgs[3]) | |
| 37 | ||
| 38 | function turnRight() | |
| 39 | if cDir == 0 then | |
| 40 | - | print(cDir) |
| 40 | + | cDir = 3 |
| 41 | elseif cDir == 3 then | |
| 42 | - | if cDir == "north" or 1 then |
| 42 | + | cDir = 2 |
| 43 | - | cDir = "east" |
| 43 | + | elseif cDir == 2 then |
| 44 | - | elseif cDir == "east" or 0 then |
| 44 | + | cDir = 1 |
| 45 | - | cDir = "south" |
| 45 | + | elseif cDir == 1 then |
| 46 | - | elseif cDir == "south" or 3 then |
| 46 | + | cDir = 0 |
| 47 | - | cDir = "west" |
| 47 | + | |
| 48 | - | elseif cDir == "west" or 2 then |
| 48 | + | |
| 49 | - | cDir = "north" |
| 49 | + | |
| 50 | end | |
| 51 | turtle.turnRight() | |
| 52 | end | |
| 53 | ||
| 54 | function turnLeft() | |
| 55 | if cDir == 0 then | |
| 56 | cDir = 1 | |
| 57 | elseif cDir == 3 then | |
| 58 | - | if cDir == "north" or 1 then |
| 58 | + | cDir = 0 |
| 59 | - | cDir = "west" |
| 59 | + | elseif cDir == 2 then |
| 60 | - | elseif cDir == "east" or 0 then |
| 60 | + | cDir = 3 |
| 61 | - | cDir = "north" |
| 61 | + | elseif cDir == 1 then |
| 62 | - | elseif cDir == "south" or 3 then |
| 62 | + | cDir = 2 |
| 63 | - | cDir = "east" |
| 63 | + | |
| 64 | - | elseif cDir == "west" or 2 then |
| 64 | + | |
| 65 | - | cDir = "south" |
| 65 | + | |
| 66 | end | |
| 67 | turtle.turnLeft() | |
| 68 | end | |
| 69 | ||
| 70 | function turnTo(dir) | |
| 71 | if cDir ~= dir then | |
| 72 | repeat | |
| 73 | turnRight() | |
| 74 | until cDir == dir | |
| 75 | end | |
| 76 | end | |
| 77 | ||
| 78 | function moveForward() | |
| 79 | if cDir == 0 then | |
| 80 | cZ = cZ-1 | |
| 81 | elseif cDir == 3 then | |
| 82 | - | if cDir == "north" or 1 then |
| 82 | + | |
| 83 | elseif cDir == 2 then | |
| 84 | - | elseif cDir == "east" or 0 then |
| 84 | + | |
| 85 | elseif cDir == 1 then | |
| 86 | - | elseif cDir == "south" or 3 then |
| 86 | + | |
| 87 | else | |
| 88 | - | elseif cDir == "west" or 2 then |
| 88 | + | |
| 89 | return nil | |
| 90 | end | |
| 91 | while not turtle.forward() do | |
| 92 | turtle.dig() | |
| 93 | end | |
| 94 | end | |
| 95 | ||
| 96 | function moveUp() | |
| 97 | cY = cY+1 | |
| 98 | while not turtle.up() do | |
| 99 | turtle.digUp() | |
| 100 | end | |
| 101 | end | |
| 102 | ||
| 103 | function moveDown() | |
| 104 | cY = cY-1 | |
| 105 | while not turtle.down() do | |
| 106 | turtle.digDown() | |
| 107 | end | |
| 108 | end | |
| 109 | ||
| 110 | function moveToX(x) | |
| 111 | if cX < x then | |
| 112 | turnTo(3) | |
| 113 | repeat | |
| 114 | moveForward() | |
| 115 | - | turnTo("east")
|
| 115 | + | |
| 116 | elseif cX > x then | |
| 117 | turnTo(1) | |
| 118 | repeat | |
| 119 | moveForward() | |
| 120 | - | turnTo("west")
|
| 120 | + | |
| 121 | else | |
| 122 | --print("already there")
| |
| 123 | end | |
| 124 | end | |
| 125 | ||
| 126 | function moveToZ(z) | |
| 127 | if cZ < z then | |
| 128 | turnTo(2) | |
| 129 | repeat | |
| 130 | moveForward() | |
| 131 | - | turnTo("south")
|
| 131 | + | |
| 132 | elseif cZ > z then | |
| 133 | turnTo(0) | |
| 134 | repeat | |
| 135 | moveForward() | |
| 136 | - | turnTo("north")
|
| 136 | + | |
| 137 | else | |
| 138 | --print("already there")
| |
| 139 | end | |
| 140 | end | |
| 141 | ||
| 142 | function moveToY(y) | |
| 143 | if cY < y then | |
| 144 | repeat | |
| 145 | moveUp() | |
| 146 | until cY == y | |
| 147 | elseif cY > y then | |
| 148 | repeat | |
| 149 | moveDown() | |
| 150 | until cY == y | |
| 151 | else | |
| 152 | --print("already there")
| |
| 153 | end | |
| 154 | end | |
| 155 | ||
| 156 | function goTo(x,y,z,dir) | |
| 157 | moveToX(x) | |
| 158 | moveToZ(z) | |
| 159 | moveToY(y) | |
| 160 | turnTo(dir) | |
| 161 | end | |
| 162 | ||
| 163 | function returnTo(x,y,z,dir) | |
| 164 | moveToY(y) | |
| 165 | moveToX(x) | |
| 166 | - | goTo(tonumber(tArgs[5]), tonumber(tArgs[6]), tonumber(tArgs[7]), tArgs[8]) |
| 166 | + | |
| 167 | turnTo(dir) | |
| 168 | end | |
| 169 | ||
| 170 | if tArgs[9]=="return" then | |
| 171 | returnTo(tonumber(tArgs[5]), tonumber(tArgs[6]), tonumber(tArgs[7]),tonumber(tArgs[8])) | |
| 172 | elseif tArgs[9]==nil then | |
| 173 | goTo(tonumber(tArgs[5]), tonumber(tArgs[6]), tonumber(tArgs[7]),tonumber(tArgs[8])) | |
| 174 | end |