Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Buil everything from a string char.
- Commands characters:
- - moving:
- - i: move turtle forward
- - j: turn turtle to left
- - k: move turtle backward
- - l: turn turtle to right
- - u: move turtle up
- - n: move turtle down
- - building:
- - 0: select and place down the item in slot 1
- - 1: select and place down the item in slot 2
- - 2: select and place down the item in slot 3
- - 3: select and place down the item in slot 4
- - 4: select and place down the item in slot 5
- - 5: select and place down the item in slot 6
- - 6: select and place down the item in slot 7
- - 7: select and place down the item in slot 8
- - 8: select and place down the item in slot 9
- - 9: select and place down the item in slot 10
- - a: select and place down the item in slot 11
- - b: select and place down the item in slot 12
- - c: select and place down the item in slot 13
- - d: select and place down the item in slot 14
- - e: select and place down the item in slot 15
- - f: select and place down the item in slot 16
- - z: place down the item in last selected slot
- - x: search for the first slot not empty and place down it (useful for big constructions with the same block type and you have the turtle filled with the same block)
- ]]--
- -- get args
- local args = {...}
- local strCommand = args[1]
- local function getConstructionSlot()
- for i = 1,16 do
- if turtle.getItemCount(i) > 0 then
- return i
- end
- end
- return 0
- end
- local function selectConstructionSlot()
- local slot = getConstructionSlot()
- if slot > 0 then
- turtle.select(slot)
- else
- printError("No construction material found")
- end
- end
- local function turtleMove(command)
- if command == 'i' then
- return turtle.forward()
- elseif command == 'k' then
- return turtle.back()
- elseif command == 'j' then
- return turtle.turnLeft()
- elseif command == 'l' then
- return turtle.turnRight()
- elseif command == 'u' then
- return turtle.up()
- elseif command == 'n' then
- return turtle.down()
- end
- return false
- end
- local function selectInventory(command)
- if command == '0' then
- return turtle.select(1)
- elseif command == '1' then
- return turtle.select(2)
- elseif command == '2' then
- return turtle.select(3)
- elseif command == '3' then
- return turtle.select(4)
- elseif command == '4' then
- return turtle.select(5)
- elseif command == '5' then
- return turtle.select(6)
- elseif command == '6' then
- return turtle.select(7)
- elseif command == '7' then
- return turtle.select(8)
- elseif command == '8' then
- return turtle.select(9)
- elseif command == '9' then
- return turtle.select(10)
- elseif command == 'a' then
- return turtle.select(11)
- elseif command == 'b' then
- return turtle.select(12)
- elseif command == 'c' then
- return turtle.select(13)
- elseif command == 'd' then
- return turtle.select(14)
- elseif command == 'e' then
- return turtle.select(15)
- elseif command == 'f' then
- return turtle.select(16)
- end
- return false
- end
- for i = 1, #strCommand do
- local c = strCommand:sub(i, i)
- if c == 'z' or selectInventory(c) then
- -- place
- turtle.placeDown()
- elseif c == 'x' then
- -- place
- selectConstructionSlot()
- turtle.placeDown()
- elseif turtleMove(c) then
- -- move
- else
- -- invalid char
- print("Invalid char command "..c)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement