Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function correctfacing()
- if (facingnum == 5) then
- facingnum = 1
- elseif (facingnum == 0) then
- facingnum = 4
- end
- end
- function getDir()
- local facing = ""
- if (facingnum == 1) then
- facing = "n"
- elseif (facingnum == 2) then
- facing = "e"
- elseif (facingnum == 3) then
- facing = "s"
- elseif (facingnum == 4) then
- facing = "w"
- end
- return facing
- end
- function facedir(dir)
- if (dir == "n") then
- dirnum = 1
- elseif (dir == "e") then
- dirnum = 2
- elseif (dir == "s") then
- dirnum = 3
- elseif (dir == "w") then
- dirnum = 4
- end
- facingprocess = 1
- while (facingprocess == 1) do
- if (facingnum < dirnum) then
- turtle.turnRight()
- facingnum = (facingnum + 1)
- elseif (facingnum > dirnum) then
- turtle.turnLeft()
- facingnum = (facingnum - 1)
- elseif (facingnum == dirnum) then
- facingprocess = 0
- end
- correctfacing()
- end
- end
- -- Creuse le passage
- function tdig()
- while turtle.detect() do
- if turtle.dig() or turtle.attack() then
- sleep(0.5)
- else break end
- end
- end
- function tdigUp()
- while turtle.detectUp() do
- if turtle.digUp() or turtle.attackUp() then
- sleep(0.5)
- else break end
- end
- end
- -- Mouvements
- function tforward()
- tdigUp()
- if turtle.forward() then
- if (facingnum == 1) then
- z = (z - 1)
- elseif (facingnum == 2) then
- x = (x + 1)
- elseif (facingnum == 3) then
- z = (z + 1)
- elseif (facingnum == 4) then
- x = (x - 1)
- end
- return true
- else
- return false
- end
- end
- function tup()
- if turtle.up() then
- y = (y+1)
- return true
- else
- return false
- end
- end
- function tdown()
- if turtle.down() then
- y = (y-1)
- return true
- else
- return false
- end
- end
- function tright()
- turtle.turnRight()
- facingnum = (facingnum + 1)
- correctfacing()
- end
- function tleft()
- turtle.turnLeft()
- facingnum = (facingnum - 1)
- correctfacing()
- end
- function flyto(tarx,tary,tarz)
- tx = tonumber(tarx)
- ty = tonumber(tary)
- tz = tonumber(tarz)
- fly = 1
- flyingloop()
- end
- function flyingloop()
- while (fly == 1) do
- if (tonumber(y) < tonumber(ty)) then
- tup()
- elseif (tonumber(z) > tonumber(tz)) then
- facedir("n")
- tforward()
- elseif (tonumber(z) < tonumber(tz)) then
- facedir("s")
- tforward()
- elseif (tonumber(x) < tonumber(tx)) then
- facedir("e")
- tforward()
- elseif (tonumber(x) > tonumber(tx)) then
- facedir("w")
- tforward()
- elseif (tonumber(y) > tonumber(ty)) then
- tdown()
- else
- fly = 0
- end
- end
- end
- function setcoords()
- term.clear()
- term.setCursorPos(1,1)
- print("Please input target coordinates")
- write("X: ")
- targetx = read()
- write("Y: ")
- targety = read()
- write("Z: ")
- targetz = read()
- print("Coordinates set.")
- sleep(2)
- end
- function status()
- term.clear()
- term.setCursorPos(1,1)
- facing = getDir()
- print("X: "..x.." Y: "..y.." Z: "..z.." Facing: "..facing)
- local fuelLevel = tostring( turtle.getFuelLevel() )
- print("Fuel level: "..fuelLevel)
- sleep(0.5)
- end
- function calibrate()
- print("Please input turtles current X, Y and Z coordinates.")
- write("X: ")
- tempx = read()
- x = tonumber(tempx)
- write("Y: ")
- tempy = read()
- y = tonumber(tempy)
- write("Z: ")
- tempz = read()
- z = tonumber(tempz)
- print("")
- print("Coordinates set.")
- print("Please input the facing of the turtle, n / e / s / w")
- write("Facing: ")
- facingloop = 1
- while (facingloop == 1) do
- facing = read()
- if (facing == "n") then
- facingloop = 0
- facingnum = 1
- elseif (facing == "e") then
- facingloop = 0
- facingnum = 2
- elseif (facing == "s") then
- facingloop = 0
- facingnum = 3
- elseif (facing == "w") then
- facingloop = 0
- facingnum = 4
- else
- print("Invalid input")
- end
- end
- print("Facing set.")
- sleep(1)
- -- main()
- end
Advertisement
Add Comment
Please, Sign In to add comment