Advertisement
Guest User

attack

a guest
Apr 6th, 2020
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.19 KB | None | 0 0
  1. local sensor = peripheral.wrap("left")
  2. turtle.refuel()
  3. local facing = "North"
  4.  
  5. function getpos(name)
  6.   local pos = sensor.getPlayerByName(name).all().position
  7.   return pos
  8. end
  9. while true do  
  10.   local pos = getpos("Blott")
  11.   local ypos = 0
  12.   local xpos = 0
  13.   local zpos = 0
  14.   local count = 1
  15.   for i in pairs(pos) do
  16.     print(pos[i])
  17.     if count == 1 then
  18.       ypos = pos[i]
  19.       print("ypos=" .. ypos)
  20.     elseif count == 2 then
  21.       xpos = pos[i]
  22.       print("xpos=" .. xpos)
  23.     elseif count == 3 then
  24.       zpos = pos[i]
  25.       print("zpos=" .. zpos)
  26.     else
  27.       print("invalid")
  28.     end
  29.     count = count + 1  
  30.   end
  31.    
  32.   if ypos <-0.5 then
  33.     turtle.down()
  34.     print("too high going down")
  35.   elseif ypos >0.5 then
  36.     turtle.up()
  37.     print("up")
  38.   end
  39.  
  40.   if zpos <-1.5 then
  41.     if facing == "South" then
  42.       turtle.turnLeft()
  43.       turtle.turnLeft()
  44.       facing = "North"
  45.     end
  46.     turtle.forward()
  47.     print("forward")
  48.   elseif zpos >1.5 then
  49.     if facing == "North" then
  50.       turtle.turnLeft()
  51.       turtle.turnLeft()
  52.       facing = "South"
  53.     end
  54.     turtle.forward()
  55.     print("back")
  56.   end
  57.    
  58.   turtle.attack()
  59.   sleep(0.5)
  60. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement