9551

auto turret

Jun 9th, 2021 (edited)
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.60 KB | None | 0 0
  1. --pastebin get VKEcYuGy
  2. --auto turret by 9551--
  3. local kill = {
  4.     --examples:
  5.     --"Creeper",
  6.     --"Spider",
  7.     --"Skeleton",
  8.     --"Zombie"
  9.     }
  10. local noKill = {
  11.     --examples:
  12.     --"Wolf",
  13.     --"Pig"
  14. }
  15. local defRange = 5
  16. local defPower = 2
  17. local wrap = "back"
  18. local mobs,queue,cord,deg,num
  19. local abs = {}
  20. local degCalc = function(entity)
  21.     local x, y, z = entity.x, entity.y, entity.z
  22.     local pitch = -math.atan2(y, math.sqrt(x * x + z * z))
  23.     local yaw = math.atan2(-x, z)
  24.     return math.deg(yaw), math.deg(pitch)
  25. end
  26. local check = function()
  27.     return (cord[1] < num) and
  28.     (cord[1] > num - num * 2) and
  29.     (cord[2] < num) and
  30.     (cord[2] > num - num * 2) and
  31.     (cord[3] < num / 4) and
  32.     (cord[3] > num / 4 - num / 2 * 2)
  33. end
  34. local x = peripheral.wrap(wrap)
  35. if not x then error("Must have a neural interface", 0) end
  36. if not x.hasModule("plethora:sensor") then error("Must have an entity sensor", 0) end
  37. if not x.hasModule("plethora:laser", 0) then error("Must have a laser", 0) end
  38. local arg = {...}
  39. num = tonumber((arg[1] or defRange))
  40. local powah = tonumber((arg[2] or defPower))
  41. local function shot()
  42.     if check() then
  43.         local ya,pi = degCalc(mobs[queue])
  44.         x.fire(ya, pi, powah)
  45.     end
  46. end
  47. while true do
  48.     mobs = x.sense()
  49.     queue = math.random(1, #mobs)
  50.     cord = {mobs[queue].x, mobs[queue].z, mobs[queue].y}
  51.     local abs = {math.abs(cord[1]),math.abs(cord[2])}
  52.     for i = 1, math.max(#kill,#noKill) do
  53.         if abs[1] > 0 and abs[2] > 0 then
  54.             if mobs[queue].name == kill[i] and mobs[queue].name ~= noKill[i] then shot() end
  55.         end
  56.     end
  57. end
  58.  
Add Comment
Please, Sign In to add comment