Advertisement
osmarks

Untitled

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