It depends how your enemy sprite number are organised.
Mine are
`10-19 = alien top layer
`20-29 = alien
`30-39 = alien
`40-49 = alien
`50-59 = alien bottom layer
And the alien fire function is
function alien_fire()
`randomly fires a bullet from a random alien that has no aliens below it
local i as integer : local check as integer
local row as integer : local column as integer
if rnd(alien.fire_chance) = 0
`check there is an alien to fire bullet
check = 0
for i = 10 to 59
inc check,sprite exist(i)
next i
if check > 0 :`there is at least 1 alien
check = 0
repeat : `randomly select a column until a column is found with an alien in it
row = rnd(9)
for i = 50 to 10 step -10
if sprite exist(i+row) and check = 0
inc check
column = i
endif
next i
until check > 0
check = 0
for i = 75 to 80 : `find the lowest sprite in the column and fire a bullet
if check = 0
if sprite exist(i)=0
sprite i,sprite x(row+column)+10,sprite y(row+column)+20,5
bullet(i-74).y = sprite y(i)
bullet(i-74).energy = alien.bullet_energy+rnd(50)
inc check
endif
endif
next i
else
`there are no aliens so goto next level
next_level()
endif
endif
alien.last_fire = timer()
endfunction