Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modules = peripheral.find('manipulator')
- local function fire(entity)
- print('Fired at '.. entity.name)
- local x, y, z = entity.x, entity.y, entity.z
- local pitch = -math.atan2(y,math.sqrt(x * x + z * z))
- local yaw = math.atan2(-x, z)
- modules.fire(math.deg(yaw), math.deg(pitch), 5)
- sleep(1)
- end
- local mobNames = {'Creeper','Zombie','Skeleton','PigZombie','Spider'}
- local mobLookup = {}
- for i = 1, #mobNames do
- mobLookup[mobNames[i]] = true
- end
- while true do
- local mobs = modules.sense()
- local candidates = {}
- for i = 1, #mobs do
- -- print(mobs[i].name)
- local mob = mobs[i]
- if mobLookup[mob.name] then
- candidates[#candidates + 1] = mob
- end
- end
- if #candidates > 0 then
- local mob = candidates[math.random(1, #candidates)]
- fire(mob)
- else
- sleep(1)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement