Cobra_Tomtrein-temp-

Untitled

May 28th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. local modules = peripheral.wrap("back")
  2.  
  3.  
  4. local function fire(entity)
  5. local x, y, z = entity.x, entity.y, entity.z
  6. local pitch = -math.atan2(y-1, math.sqrt(x * x + z * z))
  7. local yaw = math.atan2(-x, z)
  8.  
  9. modules.fire(math.deg(yaw), math.deg(pitch), 5)
  10. sleep(0.4)
  11. end
  12.  
  13. local mobNames = { "Creeper", "Zombie", "Skeleton","Pig" }
  14. local mobLookup = {}
  15. for i = 1, #mobNames do
  16. mobLookup[mobNames[i]] = true
  17. end
  18.  
  19.  
  20. while true do
  21. local mobs = modules.sense()
  22. local candidates = {}
  23. for i = 1, #mobs do
  24. local mob = mobs[i]
  25. if mobLookup[mob.name] then
  26. candidates[#candidates + 1] = mob
  27. end
  28. end
  29. if #candidates > 0 then
  30. local mob = candidates[math.random(1, #candidates)]
  31. fire(mob)
  32. else
  33. sleep(1)
  34. end
  35. end
Advertisement
Add Comment
Please, Sign In to add comment