Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require "component"
- local dtec = component.os_entdetector
- local turr = component.os_energyturret
- turr.powerOn()
- turr.extendShaft(2)
- turr.setArmed(true)
- local mob_names = {
- "Creeper",
- "Zombie",
- "Skeleton",
- "Spider"
- }
- local mob_lookup = {}
- for _, mob in pairs(mob_names) do
- mob_lookup[mob] = true
- end
- local function get_direction(entity)
- 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)
- return pitch, yaw
- end
- local function fire(entity)
- print("TARGET", entity.name)
- turr.moveToRadians(entity.yaw, entity.pitch)
- repeat
- os.sleep(0.05)
- until turr.isOnTarget()
- print "FIRING"
- turr.fire()
- end
- while true do
- local entities = dtec.scanEntities(32)
- local nearest
- for _, entity in pairs(entities) do
- if mob_lookup[entity.name] and (nearest == nil or entity.range < nearest.range) then
- local pitch, yaw = get_direction(entity)
- entity.pitch = pitch
- entity.yaw = yaw
- entity.y = entity.y + 1
- entity.z = entity.z + 1
- local degpitch = math.deg(pitch)
- print(entity.name, degpitch)
- if degpitch > -25 and degpitch < 50 then
- print("NEAR", degpitch, entity.name)
- nearest = entity
- end
- end
- end
- if nearest then
- fire(nearest)
- end
- os.sleep(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement