Advertisement
Guest User

guard2

a guest
Dec 21st, 2014
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.73 KB | None | 0 0
  1. s = peripheral.wrap("left")
  2. dir=0
  3. x,y,z=nil
  4.  
  5. function turnRight()
  6.   turtle.turnRight()
  7.   dir=dir+1
  8.   define()
  9. end
  10.  
  11. function turnLeft()
  12.   turtle.turnLeft()
  13.   dir=dir-1
  14.   define()
  15. end
  16.  
  17. function turnAround()
  18.   turnRight()
  19.   turnRight()
  20. end
  21.  
  22. function define()
  23.   if (dir > 3) then
  24.     dir=dir-4
  25.   elseif (dir < 0) then
  26.     dir=dir+4
  27.   end
  28. end
  29.  
  30. function move()
  31.     if (dir == 0) then
  32.       if (z > 1.5) then
  33.         turtle.forward()
  34.       elseif (z < -1.5) then
  35.         turnAround()
  36.       elseif (x < -1.5) then
  37.         turnRight()
  38.       elseif (x > 1.5) then
  39.         turnLeft()
  40.       end
  41.     elseif (dir == 1) then
  42.       if (x < -1.5) then
  43.         turtle,forward()
  44.       elseif (x > 1.5) then
  45.         turnAround()
  46.       elseif (z > 1.5) then
  47.         turnLeft()
  48.       elseif (z < -1.5) then
  49.         turnRight()
  50.       end
  51.     elseif (dir == 2) then
  52.       if (z > 1.5) then
  53.         turnAround()
  54.       elseif (z < -1.5) then
  55.         turtle.forward()
  56.       elseif (x < -1.5) then
  57.         turnLeft()
  58.       elseif (x > 1.5) then
  59.         turnRight()
  60.       end
  61.     elseif (dir == 3) then
  62.       if (x < -1.5) then
  63.         turnAround()
  64.       elseif (x > 1.5) then
  65.         turtle.forward()
  66.       elseif (z > 1.5) then
  67.         turnRight()
  68.       elseif (z < -1.5) then
  69.         turnLeft()
  70.       end
  71.     end
  72. end
  73.  
  74. function turnToAttack()
  75.     if (dir == 0) then
  76.         if (z > 0 and z < 1.5 and x < 1.5 and x > -1.5) then
  77.             turtle.attack()
  78.         elseif (x < 0 and x > -1.5 and z < 1.5 and z > -1.5) then
  79.             turnLeft()
  80.             turtle.attack()
  81.         elseif (x > 0 and x < 1.5 and z < 1.5 and z > -1.5) then
  82.             turnRight()
  83.             turtle.attack()
  84.         end
  85.     elseif (dir == 1) then
  86.         if (x < 0 and x > -1.5 and z < 1.5 and z > -1.5) then
  87.             turtle.attack()
  88.         elseif (z > 0 and z < 1.5 and x < 1.5 and x > -1.5) then
  89.             turnLeft()
  90.             turtle.attack()
  91.         elseif (z < 0 and z > -1.5 and x < 1.5 and x > -1.5) then
  92.             turnRight()
  93.             turtle.attack()
  94.         end
  95.     elseif (dir == 2) then
  96.         if (z < 0 and z > -1.5 and x < 1.5 and x > -1.5) then
  97.             turtle.attack()
  98.         elseif (x < 0 and x > -1.5 and z < 1.5 and z > -1.5) then
  99.             turnRight()
  100.             turtle.attack()
  101.         elseif (x > 0 and x < 1.5 and z < 1.5 and z > -1.5) then
  102.             turnLeft()
  103.             turtle.attack()
  104.         end
  105.     elseif (dir == 3) then
  106.         if (x > 0 and x < 1.5 and z < 1.5 and z > -1.5) then
  107.             turtle.attack()
  108.         elseif (z < 0 and z > -1.5 and x < 1.5 and x > -1.5) then
  109.             turnLeft()
  110.             turtle.attack()
  111.         elseif (z > 0 and z < 1.5 and x < 1.5 and x > -1.5) then
  112.             turnRight()
  113.             turtle.attack()
  114.         end
  115.     end
  116. end
  117.  
  118. while true do
  119.   id = s.getMobIds()[1]
  120.   if not (id == nil) then
  121.     pos = s.getMobData(id).position
  122.     x = pos.x
  123.     y = pos.y
  124.     z = pos.z
  125.    
  126.     move()
  127.     turnToAttack()
  128.   end
  129. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement