Advertisement
9551

Untitled

Jun 9th, 2021
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.05 KB | None | 0 0
  1. local modules = peripheral.find("manipulator")
  2. if not modules then
  3.     error("Cannot find manipulator", 0)
  4. end
  5. if not modules.hasModule("plethora:laser") then
  6.     error("Cannot find laser", 0)
  7. end
  8. if not modules.hasModule("plethora:sensor") then
  9.     error("Cannot find entity sensor", 0)
  10. end
  11. local function fire(entity)
  12.     local x, y, z = entity.x, entity.y, entity.z
  13.     local pitch = -math.atan2(y, math.sqrt(x * x + z * z))
  14.     local yaw = math.atan2(-x, z)
  15.  
  16.     modules.fire(math.deg(yaw), math.deg(pitch), 5)
  17.     sleep(0.2)
  18. end
  19. local mobNames = {"Creeper", "Zombie", "Skeleton"}
  20. local mobLookup = {}
  21. for i = 1, #mobNames do
  22.     mobLookup[mobNames[i]] = true
  23. end
  24. while true do
  25.     local mobs = modules.sense()
  26.     local candidates = {}
  27.     for i = 1, #mobs do
  28.         local mob = mobs[i]
  29.         if mobLookup[mob.name] then
  30.             candidates[#candidates + 1] = mob
  31.         end
  32.     end
  33.  
  34.     if #candidates > 0 then
  35.         local mob = candidates[math.random(1, #candidates)]
  36.         fire(mob)
  37.     else
  38.         sleep(1)
  39.     end
  40. end
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement