Razvii

Laser sentry

Jul 31st, 2021
1,004
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 error("Cannot find laser", 0) end
  6. if not modules.hasModule("plethora:sensor") then error("Cannot find entity sensor", 0) end
  7. local function fire(entity)
  8.     local x, y, z = entity.x, entity.y, entity.z
  9.     local pitch = -math.atan2(y, math.sqrt(x * x + z * z))
  10.     local yaw = math.atan2(-x, z)
  11.  
  12.     modules.fire(math.deg(yaw), math.deg(pitch), 5)
  13.     sleep(0.2)
  14. end
  15. local mobNames = { "Creeper", "Zombie", "Skeleton" }
  16. local mobLookup = {}
  17. for i = 1, #mobNames do
  18.     mobLookup[mobNames[i]] = true
  19. end
  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
RAW Paste Data