Advertisement
msmikesc

llama

Apr 18th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. modules = peripheral.wrap("back")
  2.  
  3. function main()
  4.  
  5. modules.disableAI()
  6.  
  7. while true do
  8.  
  9. player = modules.getMetaByName("mikesc")
  10.  
  11. if player ~= nil then
  12.  
  13. local x = player.x
  14. local y = player.y
  15. local z = player.z
  16.  
  17. local pitch = -math.atan2(y, math.sqrt(x * x + z * z))
  18. local yaw = math.atan2(-x, z)
  19.  
  20. local distancetoplayer = distance(0,0,x,z)
  21.  
  22. if not modules.isWalking()
  23. if distancetoplayer > 6 then
  24.  
  25. local newx = -(distancetoplayer - 2) * math.sin(yaw) * math.cos(pitch)
  26.  
  27. --local newy = (distancetoplayer - 2) * math.sin(yaw) * math.sin(pitch)
  28.  
  29. local newz = (distancetoplayer - 2) * math.cos(yaw)
  30.  
  31. success = modules.walk(newx,y,newz)
  32.  
  33. if not success then
  34. modules.walk(x,y,z)
  35. end
  36.  
  37. else
  38. modules.look(math.deg(yaw), math.deg(pitch))
  39. end
  40. end
  41.  
  42. end
  43.  
  44. os.sleep(2)
  45. end
  46.  
  47. end
  48.  
  49.  
  50. function distance ( x1, y1, x2, y2 )
  51. local dx = x1 - x2
  52. local dy = y1 - y2
  53. return math.sqrt ( dx * dx + dy * dy )
  54. end
  55.  
  56.  
  57.  
  58. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement