Advertisement
LocalSt0arge

Untitled

Mar 22nd, 2024 (edited)
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. function equipAndAttack()
  2. while true do
  3. local radar = peripheral.find("radar")
  4. if not radar and turtle then
  5. for i=1,16 do
  6. local data = turtle.getItemDetail(i)
  7. if data then
  8. if data.name == "computronics:radar" then -- Changed from "computronics:computronics.radar"
  9. turtle.select(i)
  10. turtle.equipRight()
  11. sleep(0.15)
  12. radar = peripheral.find("radar")
  13. break
  14. end
  15. end
  16. end
  17. end
  18.  
  19. if radar then
  20. local entities = radar.getEntities()
  21. if entities and #entities > 0 then
  22. for _, entity in ipairs(entities) do
  23. if entity and entity.type == "mob" then
  24. local x, y, z = entity.x, entity.y, entity.z
  25. local distance = math.sqrt((x - turtle.point.x) ^ 2 + (z - turtle.point.z) ^ 2)
  26. if distance > 1 then
  27. -- Move towards the entity
  28. turtle.attack()
  29. sleep(0.5) -- Wait for a short time before attacking again
  30. else
  31. print("Reached entity. Attacking...")
  32. turtle.attack()
  33. sleep(0.5) -- Wait for a short time before attacking again
  34. end
  35. end
  36. end
  37. else
  38. print("No entities found. Scanning...")
  39. end
  40. else
  41. print("No radar found. Retrying...")
  42. sleep(5) -- Wait for 5 seconds before retrying
  43. end
  44. end
  45. end
  46.  
  47. equipAndAttack() -- Start the function
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement