Advertisement
Guest User

startup.lua

a guest
Jul 19th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.90 KB | None | 0 0
  1. local modules = peripheral.find('manipulator')
  2.  
  3. local function fire(entity)
  4.     print('Fired at '.. entity.name)
  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.     modules.fire(math.deg(yaw), math.deg(pitch), 5)
  10.     sleep(1)
  11. end
  12.  
  13. local mobNames = {'Creeper','Zombie','Skeleton','PigZombie','Spider'}
  14. local mobLookup = {}
  15. for i = 1, #mobNames do
  16.     mobLookup[mobNames[i]] = true
  17. end
  18.  
  19. while true do
  20.     local mobs = modules.sense()
  21.     local candidates = {}
  22.     for i = 1, #mobs do
  23.    -- print(mobs[i].name)
  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.        
  33.     else
  34.         sleep(1)
  35.     end
  36. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement