Advertisement
Guest User

PetSensor

a guest
Oct 20th, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.50 KB | None | 0 0
  1. sensor = peripheral.wrap("left")
  2. modemw = peripheral.wrap("right")
  3.  
  4. local function moveto(dirant,diratu)
  5.  
  6. if dirant == "norte" then
  7.   if diratu == "leste" then
  8.   turtle.turnRight()
  9.   elseif diratu == "oeste" then
  10.   turtle.turnLeft()
  11.   elseif diratu == "sul" then
  12.   turtle.turnRight()
  13.   turtle.turnRight()
  14.   end
  15. elseif dirant == "leste" then
  16.   if diratu == "sul" then
  17.   turtle.turnRight()
  18.   elseif diratu == "norte" then
  19.   turtle.turnLeft()
  20.   elseif diratu == "oeste" then
  21.   turtle.turnRight()
  22.   turtle.turnRight()
  23.   end
  24. elseif dirant == "sul" then
  25.   if diratu == "oeste" then
  26.   turtle.turnRight()
  27.   elseif diratu == "leste" then
  28.   turtle.turnLeft()
  29.   elseif diratu == "norte" then
  30.   turtle.turnRight()
  31.   turtle.turnRight()
  32.   end
  33. elseif dirant == "oeste" then
  34.   if diratu == "norte" then
  35.   turtle.turnRight()
  36.   elseif diratu == "sul" then
  37.   turtle.turnLeft()
  38.   elseif diratu == "leste" then
  39.   turtle.turnRight()
  40.   turtle.turnRight()
  41.   end
  42. end
  43.  
  44. if turtle.detect() == true then
  45. turtle.equipRight()
  46. turtle.dig()
  47. turtle.equipRight()
  48. end
  49.  
  50. turtle.forward()
  51.  
  52. end
  53.  
  54. direcao = "norte"
  55.  
  56. term.clear()
  57. term.setCursorPos(1,1)
  58. print("Insert Your Nickname / Insira Seu Nome de Jogador")
  59. nickname = io.read()
  60.  
  61. term.clear()
  62. term.setCursorPos(1,1)
  63. print("Insert the Turtle Height / Insira a Altura da Turtle")
  64. altura = tonumber(io.read())
  65.  
  66. term.clear()
  67. term.setCursorPos(1,1)
  68. print("Following"..nickname.." / Seguindo "..nickname)
  69.  
  70.  
  71. while 1 == 1 do
  72. posicao = "naoconferida"
  73. yourinfo = sensor.getPlayerData(nickname)
  74.  
  75.  
  76. xpronto = math.floor((tonumber(yourinfo["position"]["x"]))+0.5)
  77. zpronto = math.floor((tonumber(yourinfo["position"]["z"]))+0.5)
  78. ypronto = math.floor(((tonumber(yourinfo["position"]["y"]))+0.5)+altura)
  79.  
  80.   if ypronto > 0 then
  81.     if turtle.detectUp() == true then
  82.     turtle.equipRight()
  83.     turtle.digUp()
  84.     turtle.equipRight()
  85.     end
  86.   turtle.up()
  87.  
  88.   elseif ypronto < 0 then
  89.     if turtle.detectDown() == true then
  90.     turtle.equipRight()
  91.     turtle.digDown()
  92.     turtle.equipRight()
  93.     end
  94.   turtle.down()
  95.  
  96.   elseif ypronto == 0 then
  97.    
  98.     if zpronto > 0 then
  99.     moveto(direcao,"sul")
  100.     direcao = "sul"
  101.    
  102.     elseif zpronto < 0 then
  103.     moveto(direcao,"norte")
  104.     direcao = "norte"
  105.    
  106.       elseif zpronto == 0 then
  107.      
  108.       if xpronto > 0 then
  109.       moveto(direcao,"leste")
  110.       direcao = "leste"
  111.      
  112.       elseif xpronto < 0 then
  113.       moveto(direcao,"oeste")
  114.       direcao = "oeste"
  115.      
  116.       elseif xpronto == 0 then
  117.       posicao = "conferida"
  118.      
  119.       end
  120.      
  121.     end
  122.    
  123.   end
  124.  
  125. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement