Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sensor = peripheral.wrap("left")
- turtle.refuel()
- local facing = "West"
- function getpos(name)
- local pos = sensor.getPlayerByName(name).all().position
- return pos
- end
- function setDirection(direction)
- if direction == "North" then
- if facing == "South" then
- turtle.turnLeft()
- turtle.turnLeft()
- elseif facing == "East" then
- turtle.turnLeft()
- elseif facing == "West" then
- turtle.turnRight()
- end
- facing = "North"
- end
- if direction == "South" then
- if facing == "North" then
- turtle.turnLeft()
- turtle.turnLeft()
- elseif facing == "East" then
- turtle.turnRight()
- elseif facing == "West" then
- turtle.turnLeft()
- end
- facing = "South"
- end
- if direction == "East" then
- if facing == "North" then
- turtle.turnRight()
- elseif facing == "South" then
- turtle.turnLeft()
- elseif facing == "West" then
- turtle.turnLeft()
- turtle.turnLeft()
- end
- facing = "East"
- end
- if direction == "West" then
- if facing == "North" then
- turtle.turnLeft()
- elseif facing == "South" then
- turtle.turnRight()
- elseif facing == "East" then
- turtle.turnLeft()
- turtle.turnLeft()
- end
- facing = "West"
- end
- end
- while true do
- local pos = getpos("iKipling")
- local ypos = 0
- local xpos = 0
- local zpos = 0
- local count = 1
- for i in pairs(pos) do
- print(pos[i])
- if count == 1 then
- ypos = pos[i]
- print("ypos=" .. ypos)
- elseif count == 2 then
- xpos = pos[i]
- print("xpos=" .. xpos)
- elseif count == 3 then
- zpos = pos[i]
- print("zpos=" .. zpos)
- else
- print("invalid")
- end
- count = count + 1
- end
- if ypos <-0.5 then
- turtle.down()
- print("down")
- elseif ypos >0.5 then
- turtle.up()
- print("up")
- end
- if zpos <-1.5 then
- setDirection("North")
- turtle.forward()
- elseif zpos >1.5 then
- setDirection("South")
- turtle.forward()
- print("South")
- end
- if xpos <-1.5 then
- setDirection("West")
- turtle.forward()
- elseif xpos >1.5 then
- setDirection("East")
- turtle.forward()
- end
- turtle.attack()
- sleep(0.5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement