Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sensor = peripheral.wrap("left")
- turtle.refuel()
- local facing = "North"
- function getpos(name)
- local pos = sensor.getPlayerByName(name).all().position
- return pos
- end
- while true do
- local pos = getpos("Blott")
- 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("too high going down")
- elseif ypos >0.5 then
- turtle.up()
- print("up")
- end
- if zpos <-1.5 then
- if facing == "South" then
- turtle.turnLeft()
- turtle.turnLeft()
- facing = "North"
- end
- turtle.forward()
- print("forward")
- elseif zpos >1.5 then
- if facing == "North" then
- turtle.turnLeft()
- turtle.turnLeft()
- facing = "South"
- end
- turtle.forward()
- print("back")
- end
- turtle.attack()
- sleep(0.5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement