SHOW:
|
|
- or go back to the newest paste.
| 1 | - | updateloop = 0 |
| 1 | + | function gotoapi(gx, gy, gz, enddirlet) |
| 2 | - | udfarmargs = {...}
|
| 2 | + | --local tArgs = {...}
|
| 3 | - | if udfarmargs[1] == "noset" then |
| 3 | + | local face = 0 |
| 4 | - | udopenset = 0 |
| 4 | + | local r = 1 |
| 5 | tru = 1 | |
| 6 | - | while true do |
| 6 | + | local tturned = 0 |
| 7 | - | if fs.exists("Farmnew") then
|
| 7 | + | rednet.open("left")
|
| 8 | - | shell.run("delete","Farmnew")
|
| 8 | + | local cx,cy,cz = gps.locate(2,false) |
| 9 | if (gx and gy and gz) == nil then | |
| 10 | - | shell.run("pastebin","get","ZW6q8wWs","Farmnew")
|
| 10 | + | print("Incorrect usage of Function.")
|
| 11 | - | if fs.exists("Farmnew") then
|
| 11 | + | --print("goto <x> <y> <z> (<Heading>)")
|
| 12 | - | if fs.exists("Farmold") then
|
| 12 | + | |
| 13 | - | shell.run("delete","Farmold")
|
| 13 | + | --local gx = tonumber(tArgs[1]) |
| 14 | - | end |
| 14 | + | --local gy = tonumber(tArgs[2]) |
| 15 | - | if fs.exists("Farm") then
|
| 15 | + | --local gz = tonumber(tArgs[3]) |
| 16 | - | shell.run("rename","Farm","Farmold")
|
| 16 | + | --local enddirlet = tArgs[4] |
| 17 | - | end |
| 17 | + | local x |
| 18 | - | shell.run("rename","Farmnew","Farm")
|
| 18 | + | local y |
| 19 | - | if fs.exists("Farm") then
|
| 19 | + | local z |
| 20 | - | break |
| 20 | + | if enddirlet ~= nil then |
| 21 | - | end |
| 21 | + | if enddirlet == "n" or enddirlet == "north" then |
| 22 | enddir = 4 | |
| 23 | - | if fs.exists("Farm") then
|
| 23 | + | |
| 24 | - | if updateloop > 20 then |
| 24 | + | if enddirlet == "s" or enddirlet == "south" then |
| 25 | - | break |
| 25 | + | enddir = 2 |
| 26 | - | end |
| 26 | + | |
| 27 | if enddirlet == "e" or enddirlet == "east" then | |
| 28 | - | if fs.exists("Farmold") then
|
| 28 | + | enddir = 1 |
| 29 | - | if updateloop > 30 then |
| 29 | + | |
| 30 | - | shell.run("rename","Farmold","Farm")
|
| 30 | + | if enddirlet == "w" or enddirlet == "west" then |
| 31 | - | if fs.exists("Farm") then
|
| 31 | + | enddir = 3 |
| 32 | - | break |
| 32 | + | |
| 33 | - | end |
| 33 | + | |
| 34 | - | end |
| 34 | + | function tturnup() |
| 35 | tturned = tturned + 1 | |
| 36 | - | updateloop = updateloop + 1 |
| 36 | + | if tturned > 10 then |
| 37 | os.reboot() | |
| 38 | - | local stu = fs.open("startup.lua", "w")
|
| 38 | + | |
| 39 | - | stu.write('sleep(5)\nshell.run("farmupdate", "noset")')
|
| 39 | + | |
| 40 | - | stu.close() |
| 40 | + | |
| 41 | - | if udopenset == 0 then |
| 41 | + | function PL() |
| 42 | - | shell.run("Farm", "noset")
|
| 42 | + | --print("Going to:")
|
| 43 | --write(gx) write(" ") write(gy) write(" ") print(gz)
| |
| 44 | - | shell.run("Farm")
|
| 44 | + | end |
| 45 | - | end |
| 45 | + | function c_face() |
| 46 | if face >= 5 then | |
| 47 | face = 1 | |
| 48 | elseif face <= 0 then | |
| 49 | face = 4 | |
| 50 | end | |
| 51 | end | |
| 52 | function get_Face() | |
| 53 | while turtle.forward() == false do | |
| 54 | tturned = 0 | |
| 55 | if turtle.up() == false then | |
| 56 | --turtle.digUp() | |
| 57 | end | |
| 58 | end | |
| 59 | ||
| 60 | nx,ny,nz = gps.locate(3,false) | |
| 61 | if nx > cx then | |
| 62 | face = 1 | |
| 63 | end | |
| 64 | if nx < cx then | |
| 65 | face = 3 | |
| 66 | end | |
| 67 | if nz > cz then | |
| 68 | face = 2 | |
| 69 | end | |
| 70 | if nz < cz then | |
| 71 | face = 4 | |
| 72 | end | |
| 73 | end | |
| 74 | function calc() | |
| 75 | x = nx - gx | |
| 76 | y = ny - gy | |
| 77 | z = nz - gz | |
| 78 | end | |
| 79 | function setDir(dir) | |
| 80 | noredoturndir = 0 | |
| 81 | c_face() | |
| 82 | if dir == 4 then | |
| 83 | if face == 1 then | |
| 84 | gototurnleft = 1 | |
| 85 | --print("E-to-N")
| |
| 86 | noredoturndir = 1 | |
| 87 | end | |
| 88 | end | |
| 89 | if dir == 1 then | |
| 90 | if face == 4 then | |
| 91 | gototurnleft = 0 | |
| 92 | --print("N-to-E")
| |
| 93 | noredoturndir = 1 | |
| 94 | end | |
| 95 | end | |
| 96 | ||
| 97 | if noredoturndir == 0 then | |
| 98 | if face >= dir then | |
| 99 | gototurnleft = 1 | |
| 100 | end | |
| 101 | if face < dir then | |
| 102 | gototurnleft = 0 | |
| 103 | end | |
| 104 | end | |
| 105 | ||
| 106 | if dir == 4 then | |
| 107 | if face == 1 then | |
| 108 | gototurnleft = 1 | |
| 109 | --print("E-to-N")
| |
| 110 | noredoturndir = 1 | |
| 111 | end | |
| 112 | end | |
| 113 | if dir == 1 then | |
| 114 | if face == 4 then | |
| 115 | gototurnleft = 0 | |
| 116 | --print("N-to-E")
| |
| 117 | noredoturndir = 1 | |
| 118 | end | |
| 119 | end | |
| 120 | while dir ~= face do | |
| 121 | c_face() | |
| 122 | if gototurnleft == 1 then | |
| 123 | turtle.turnLeft() | |
| 124 | face = face - 1 | |
| 125 | tturnup() | |
| 126 | end | |
| 127 | if gototurnleft == 0 then | |
| 128 | turtle.turnRight() | |
| 129 | face = face + 1 | |
| 130 | tturnup() | |
| 131 | end | |
| 132 | c_face() | |
| 133 | end | |
| 134 | noredoturndir = 0 | |
| 135 | end | |
| 136 | function f() | |
| 137 | while not turtle.forward() do | |
| 138 | tturned = 0 | |
| 139 | if not turtle.up() then | |
| 140 | --turtle.digUp() | |
| 141 | end | |
| 142 | y = y + 1 | |
| 143 | end | |
| 144 | end | |
| 145 | function go() | |
| 146 | tturned = 0 | |
| 147 | if x < 0 then | |
| 148 | setDir(1) | |
| 149 | while x ~= 0 do | |
| 150 | f() | |
| 151 | x = x + 1 | |
| 152 | end | |
| 153 | end | |
| 154 | if x > 0 then | |
| 155 | setDir(3) | |
| 156 | while x ~= 0 do | |
| 157 | f() | |
| 158 | x = x - 1 | |
| 159 | end | |
| 160 | end | |
| 161 | if z < 0 then | |
| 162 | setDir(2) | |
| 163 | while z ~= 0 do | |
| 164 | f() | |
| 165 | z = z + 1 | |
| 166 | end | |
| 167 | end | |
| 168 | if z > 0 then | |
| 169 | setDir(4) | |
| 170 | while z ~= 0 do | |
| 171 | f() | |
| 172 | z = z - 1 | |
| 173 | end | |
| 174 | end | |
| 175 | while y < 0 do | |
| 176 | tturned = 0 | |
| 177 | if turtle.up() ~= true then | |
| 178 | --turtle.digUp() | |
| 179 | end | |
| 180 | y = y + 1 | |
| 181 | end | |
| 182 | while y > 0 do | |
| 183 | tturned = 0 | |
| 184 | if turtle.down() ~= true then | |
| 185 | --turtle.digDown() | |
| 186 | end | |
| 187 | y = y - 1 | |
| 188 | end | |
| 189 | end | |
| 190 | ||
| 191 | ||
| 192 | ||
| 193 | tonumber(gx) | |
| 194 | tonumber(gy) | |
| 195 | tonumber(gz) | |
| 196 | PL() | |
| 197 | get_Face() | |
| 198 | turtle.turnLeft() | |
| 199 | turtle.turnLeft() | |
| 200 | turtle.forward() | |
| 201 | turtle.turnLeft() | |
| 202 | turtle.turnLeft() | |
| 203 | setDir(1) | |
| 204 | setDir(4) | |
| 205 | --if enddir ~= nil then | |
| 206 | -- setDir(enddir) | |
| 207 | --end | |
| 208 | ||
| 209 | end | |
| 210 | end | |
| 211 | ||
| 212 | gotoapi(1, 1, 1) | |
| 213 | ||
| 214 | function goto(Workinggototable) | |
| 215 | gototable = {}
| |
| 216 | goit = 1 | |
| 217 | while goit < 5 do | |
| 218 | if Workinggototable[goit] ~= nil then | |
| 219 | table.insert(gototable, Workinggototable[goit]) | |
| 220 | elseif Workinggototable[goit] == nil then | |
| 221 | table.insert(gototable, Workinggototable[goit]) | |
| 222 | break | |
| 223 | end | |
| 224 | goit = goit + 1 | |
| 225 | end | |
| 226 | gotoapi(gototable[1], gototable[2], gototable[3], gototable[4]) | |
| 227 | end | |
| 228 |