Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("check") --http://pastebin.com/Sc2TWpeH
- os.loadAPI("try") --http://pastebin.com/ADttMQXz
- local tArgs = { ... }
- if #tArgs ~= 2 then
- print("Usage: platform <length> <width>")
- return
- end
- x = tonumber(tArgs[1])
- z = tonumber(tArgs[2])
- if not check.whole(x) or not check.positive(x) then
- print("Improper arguments!")
- return
- end
- if not check.whole(z) or not check.positive(z) then
- print("Improper arguments!")
- return
- end
- --Checking for block amount
- local total = x * z
- local inv = 0
- local nItems = 0
- for i = 1,16 do
- nItems = turtle.getItemCount(i)
- inv = inv + nItems
- end
- if total > inv then
- print("Not enough blocks!")
- return
- end
- local function tryPlace()
- while not turtle.placeDown() do
- if turtle.detectDown() then
- if not turtle.digDown() then
- print("Cannot place block, exiting script!")
- return false
- end
- elseif not turtle.attackDown() then
- sleep(0.5)
- end
- end
- return true
- end
- local function forward()
- if not try.forward() then
- print("Cannot move forward, exiting script!")
- return false
- end
- return true
- end
- local slot = 1
- function checkSlot()
- turtle.select(slot)
- while turtle.getItemCount(slot) == 0 do
- slot = slot + 1
- turtle.select(slot)
- end
- end
- --Start building
- local dir = true
- local done = false
- for j = 1,z-1 do
- for k = 1,x-1 do
- checkSlot()
- if not tryPlace() then return end
- if not forward() then return end
- end
- if not tryPlace() then return end
- if dir then
- turtle.turnRight()
- if not forward() then return end
- turtle.turnRight()
- else
- turtle.turnLeft()
- if not forward() then return end
- turtle.turnLeft()
- end
- dir = not dir
- end
- for k = 1,x-1 do
- checkSlot()
- if not tryPlace() then return end
- if not forward() then return end
- end
- if not tryPlace() then return end
- print("Platform built! Used " .. tostring(total) .. " blocks.")
Advertisement
Add Comment
Please, Sign In to add comment