|
| 1 | +-- |
| 2 | +-- This script will create a Direwolf20 classic 9x9 room |
| 3 | +-- |
| 4 | +-- If the turtle is a mining turtle it can clear the area as well |
| 5 | +-- if not it will just place the walls,floor and ceiling as needed |
| 6 | +-- but will get stuck if there are obsticles. |
| 7 | +-- |
| 8 | +-- It will prompt you for what to place in which slots |
| 9 | +-- |
| 10 | +-- Version 1.0 |
| 11 | +-- Author: yazug ([email protected]) |
| 12 | +-- |
| 13 | +-- http://turtlescripts.com/project/gjdhcs-9by9 |
| 14 | +-- |
| 15 | + |
| 16 | +local tArgs = {...} |
| 17 | +local wall_slot = 1 |
| 18 | +local floor_slot = 2 |
| 19 | +local ceiling_slot = 1 |
| 20 | +local skylight_slot = 3 |
| 21 | +local torch_slot = 4 |
| 22 | +local fuel_slot = 16 |
| 23 | +local junk_slot = 1 |
| 24 | +local forward_sleep_time = 4 |
| 25 | +local gravel_fall_time = 0.7 |
| 26 | +local isRunning=true |
| 27 | + |
| 28 | +if tArgs[1] == "update" then |
| 29 | + local sCode, sFile, sPin = "gjdhjd", "9by9", "" |
| 30 | + local sPath = shell.resolve( sFile ) |
| 31 | + write( "Connecting to TurtleScripts.com... " ) |
| 32 | + local response = http.post("http://api.turtlescripts.com/getFileRaw/"..textutils.urlEncode( sCode ),"pin="..sPin) |
| 33 | + if response then |
| 34 | + local sResponse = response.readAll() |
| 35 | + response.close() |
| 36 | + local file = fs.open( sPath, "w" ) |
| 37 | + file.write( sResponse ) |
| 38 | + file.close() |
| 39 | + print( " " ) |
| 40 | + print( "Remote: #"..sCode ) |
| 41 | + print( "Local: "..sFile ) |
| 42 | + print( "[===========================] 100%" ) |
| 43 | + print(string.len(sResponse).." bytes") |
| 44 | + print( " " ) |
| 45 | + print( "Update Complete." ) |
| 46 | + print( " " ) |
| 47 | + else |
| 48 | + print( "Failed to update." ) |
| 49 | + print( " " ) |
| 50 | + end |
| 51 | + isRunning = false |
| 52 | +end |
| 53 | + |
| 54 | +function printUsage() |
| 55 | + print(" Usage: ") |
| 56 | + print(" 9by9 ") |
| 57 | + print(" 9by9 help ") |
| 58 | + print(" 9by9 update ") |
| 59 | + print(" ") |
| 60 | +end |
| 61 | + |
| 62 | +function doCorner(count, action) |
| 63 | + for i=1,count-1 do |
| 64 | + action() |
| 65 | + end |
| 66 | + turtle.turnRight() |
| 67 | + for i=1,count do |
| 68 | + action() |
| 69 | + end |
| 70 | +end |
| 71 | + |
| 72 | +function dig() |
| 73 | + turtle.select(junk_slot) |
| 74 | + while turtle.digUp() do end |
| 75 | + while turtle.dig() do end |
| 76 | + while turtle.digDown() do end |
| 77 | + while turtle.detectUp() or turtle.detect() do |
| 78 | + turtle.digUp() |
| 79 | + turtle.dig() |
| 80 | + sleep(gravel_fall_time) |
| 81 | + end |
| 82 | +end |
| 83 | + |
| 84 | +function forward() |
| 85 | + |
| 86 | + while not turtle.forward() do |
| 87 | + turtle.select(junk_slot) |
| 88 | + while turtle.dig() do end |
| 89 | + while turtle.getFuelLevel() == 0 do |
| 90 | + turtle.select(fuel_slot) |
| 91 | + if turtle.getItemCount() == 0 or not turtle.refuel(1) then |
| 92 | + print("Need Fuel to move... Please add fuel to slot " .. fuel_slot ) |
| 93 | + sleep(5) |
| 94 | + end |
| 95 | + end |
| 96 | + turtle.select(junk_slot) |
| 97 | + turtle.dig() |
| 98 | + while turtle.detect() do |
| 99 | + turtle.dig() |
| 100 | + turtle.attack() |
| 101 | + sleep(forward_sleep_time) |
| 102 | + print("Blocked from going forward") |
| 103 | + end |
| 104 | + end |
| 105 | +end |
| 106 | + |
| 107 | +function doFloor() |
| 108 | + dig() |
| 109 | + placeDown(floor_slot) |
| 110 | + forward() |
| 111 | +end |
| 112 | + |
| 113 | +function doWall() |
| 114 | + dig() |
| 115 | + placeWall(wall_slot) |
| 116 | +end |
| 117 | + |
| 118 | +function doCeiling() |
| 119 | + dig() |
| 120 | + placeDown(ceiling_slot) |
| 121 | + forward() |
| 122 | +end |
| 123 | + |
| 124 | +function doSkylight() |
| 125 | + dig() |
| 126 | + placeDown(skylight_slot) |
| 127 | + forward() |
| 128 | +end |
| 129 | + |
| 130 | +function doAir() |
| 131 | + dig() |
| 132 | + forward() |
| 133 | +end |
| 134 | + |
| 135 | +function placeWall(slot) |
| 136 | + checkSupplies(slot,3) |
| 137 | + turtle.select(slot) |
| 138 | + turtle.placeDown() |
| 139 | + turtle.placeUp() |
| 140 | + forward() |
| 141 | + turtle.select(slot) |
| 142 | + turtle.turnRight() |
| 143 | + turtle.turnRight() |
| 144 | + turtle.place() |
| 145 | + turtle.turnRight() |
| 146 | + turtle.turnRight() |
| 147 | +end |
| 148 | + |
| 149 | +function checkSupplies(slot, quantity) |
| 150 | + if turtle.getItemSpace(slot) > 60 then |
| 151 | + --TODO: Don't steal from other named slots |
| 152 | + for i=1,16 do |
| 153 | + turtle.select(i) |
| 154 | + if turtle.compareTo(slot) then |
| 155 | + turtle.transferTo(slot) |
| 156 | + end |
| 157 | + if turtle.getItemSpace(slot) < 32 then |
| 158 | + break |
| 159 | + end |
| 160 | + end |
| 161 | + end |
| 162 | + while turtle.getItemCount(slot) < quantity do |
| 163 | + print("Need Items in " .. slot .. " quantity " .. quantity - turtle.getItemCount(slot)) |
| 164 | + sleep(10) |
| 165 | + end |
| 166 | +end |
| 167 | + |
| 168 | +function placeDown(slot) |
| 169 | + checkSupplies(slot,1) |
| 170 | + turtle.select(slot) |
| 171 | + turtle.placeDown() |
| 172 | +end |
| 173 | + |
| 174 | +function placeUp(slot) |
| 175 | + checkSupplies(slot,1) |
| 176 | + turtle.select(slot) |
| 177 | + turtle.placeUp() |
| 178 | +end |
| 179 | + |
| 180 | +function place(slot) |
| 181 | + checkSupplies(slot,1) |
| 182 | + turtle.select(slot) |
| 183 | + turtle.place() |
| 184 | +end |
| 185 | + |
| 186 | +function nextLoop() |
| 187 | + turtle.turnRight() |
| 188 | + forward() |
| 189 | + turtle.turnLeft() |
| 190 | +end |
| 191 | + |
| 192 | +function nextLoopTop() |
| 193 | + turtle.turnLeft() |
| 194 | + forward() |
| 195 | + turtle.turnRight() |
| 196 | +end |
| 197 | +function goUp(count) |
| 198 | + for i=1,count do |
| 199 | + while turtle.digUp() do end |
| 200 | + while not turtle.up() do |
| 201 | + turtle.digUp() |
| 202 | + sleep(gravel_fall_time) |
| 203 | + if turtle.getFuelLevel() == 0 then |
| 204 | + turtle.select(fuel_slot) |
| 205 | + if not turtle.refuel(1) then |
| 206 | + print("Need Fuel to move... Please add fuel to slot " .. fuel_slot ) |
| 207 | + sleep(5) |
| 208 | + end |
| 209 | + print("Turtle Movement blocked going up") |
| 210 | + end |
| 211 | + end |
| 212 | + end |
| 213 | +end |
| 214 | + |
| 215 | +function goDown(count) |
| 216 | + for i=1,count do |
| 217 | + while not turtle.down() do |
| 218 | + turtle.digDown() |
| 219 | + if turtle.getFuelLevel() == 0 then |
| 220 | + turtle.select(fuel_slot) |
| 221 | + if turtle.getItemCount() == 0 or not turtle.refuel(1) then |
| 222 | + print("Need Fuel to move... Please add fuel to slot " .. fuel_slot ) |
| 223 | + sleep(5) |
| 224 | + end |
| 225 | + end |
| 226 | + print("Turtle Movement blocked going down") |
| 227 | + end |
| 228 | + end |
| 229 | +end |
| 230 | + |
| 231 | +function doArea2(size,center,corner, next) |
| 232 | + turtle.turnLeft() |
| 233 | + center() |
| 234 | + turtle.turnRight() |
| 235 | + for i=1,size do |
| 236 | + print(i) |
| 237 | + for j=1,4 do |
| 238 | + center() |
| 239 | + doCorner(i,corner) |
| 240 | + end |
| 241 | + if i < size then |
| 242 | + next() |
| 243 | + end |
| 244 | + end |
| 245 | +end |
| 246 | + |
| 247 | +function doArea(size,center,corner, next) |
| 248 | + for i=1,size do |
| 249 | + print(i) |
| 250 | + for j=1,4 do |
| 251 | + center() |
| 252 | + if size-i == 0 then |
| 253 | + return |
| 254 | + end |
| 255 | + doCorner(size-i,corner) |
| 256 | + end |
| 257 | + next() |
| 258 | + end |
| 259 | +end |
| 260 | + |
| 261 | +function digRoomInsideOut() |
| 262 | + goUp(1) |
| 263 | + for i=1,4 do |
| 264 | + forward() |
| 265 | + end |
| 266 | + turtle.turnLeft() |
| 267 | + doArea2(3,doAir,doAir,nextLoopTop) |
| 268 | + turtle.turnRight() |
| 269 | + |
| 270 | + for i=1,3 do |
| 271 | + forward() |
| 272 | + end |
| 273 | + |
| 274 | + goUp(2) |
| 275 | + turtle.turnLeft() |
| 276 | + doArea2(3,doAir,doAir,nextLoopTop) |
| 277 | + goDown(3) |
| 278 | + turtle.turnLeft() |
| 279 | + forward() |
| 280 | + turtle.turnLeft() |
| 281 | + turtle.turnLeft() |
| 282 | +end |
| 283 | + |
| 284 | +function digRoom() |
| 285 | + goUp(1) |
| 286 | + forward() |
| 287 | + turtle.turnLeft() |
| 288 | + turtle.turnLeft() |
| 289 | + forward() |
| 290 | + turtle.turnRight() |
| 291 | + doArea(4,doAir,doAir,nextLoop) |
| 292 | + turtle.back() |
| 293 | + goUp(2) |
| 294 | + turtle.turnLeft() |
| 295 | + for i=1,3 do |
| 296 | + forward() |
| 297 | + end |
| 298 | + turtle.turnLeft() |
| 299 | + turtle.turnLeft() |
| 300 | + print("NextFloor") |
| 301 | + turtle.turnLeft() |
| 302 | + doArea(4,doAir,doAir,nextLoop) |
| 303 | + turtle.back() |
| 304 | + turtle.turnLeft() |
| 305 | + goDown(3) |
| 306 | + for i=1,4 do |
| 307 | + forward() |
| 308 | + end |
| 309 | + turtle.turnLeft() |
| 310 | + turtle.turnLeft() |
| 311 | + turtle.back() |
| 312 | +end |
| 313 | + |
| 314 | +if isRunning then |
| 315 | + |
| 316 | + print("Place 4 stacks of wall building materials into slot " .. wall_slot .. " and others") |
| 317 | + turtle.select(wall_slot) |
| 318 | + -- TODO: Actually count how many other blocks of same type are in inventory |
| 319 | + while turtle.getItemCount(wall_slot) < 64 do |
| 320 | + print("Waiting for more items for the wall") |
| 321 | + sleep(2) |
| 322 | + end |
| 323 | + print("Place 1 stack of Flooring materials into slot " .. floor_slot) |
| 324 | + turtle.select(floor_slot) |
| 325 | + while turtle.getItemCount(floor_slot) < 50 do |
| 326 | + print("Waiting for more items for the floor") |
| 327 | + sleep(2) |
| 328 | + end |
| 329 | + print("Place Skylight material into slot " .. skylight_slot) |
| 330 | + turtle.select(skylight_slot) |
| 331 | + while turtle.getItemCount(skylight_slot) < 16 do |
| 332 | + print("Waiting for more items for the skylights") |
| 333 | + sleep(2) |
| 334 | + end |
| 335 | + print("Place torches into slot " .. torch_slot) |
| 336 | + turtle.select(torch_slot) |
| 337 | + while turtle.getItemCount(torch_slot) < 4 do |
| 338 | + print("Waiting for more torches") |
| 339 | + sleep(2) |
| 340 | + end |
| 341 | + print("Place fuel into slot " .. fuel_slot) |
| 342 | + turtle.select(fuel_slot) |
| 343 | + |
| 344 | + while turtle.getFuelLevel() < 200 do |
| 345 | + |
| 346 | + while turtle.getItemCount(fuel_slot) < 1 do |
| 347 | + print("Waiting for more fuel. have ["..turtle.getFuelLevel() .. "] of 200") |
| 348 | + sleep(2) |
| 349 | + end |
| 350 | + if not turtle.refuel(1) then |
| 351 | + print("Item in fuel slot is not burnable!") |
| 352 | + sleep(1) |
| 353 | + end |
| 354 | + end |
| 355 | + print("Starting") |
| 356 | + |
| 357 | + digRoomInsideOut() |
| 358 | + |
| 359 | +end |
0 commit comments