@name 3 Closest Enemy Targets NPC Filter
@inputs Pl:array Pass:entity PlayerKill On
#@outputs Threat1 Threat2 Threat3 Threat4 Threat5 Threat6 Threat7
#@outputs C1:entity C2:entity C3:entity Count C11 C21 C31 
@outputs Tar:array NPCC Friend:array Enemy:array
if(duped()){reset()}
setColor(0,255,255)
if(first()){
    Friend=array()
    Enemy=array()
    Friend:pushString("npc_alyx")
    Friend:pushString("npc_barney")
    Friend:pushString("npc_citizen")
    Friend:pushString("npc_eli")
    Friend:pushString("npc_dog")
    Friend:pushString("npc_magnusson")
    Friend:pushString("npc_mossman")
    Friend:pushString("npc_vortigaunt")
    Friend:pushString("npc_kleiner")
    Friend:pushString("npc_monk")
    Friend:pushString("prop_vehicle_airboat")
    #These are "Friends" cause bullets don't kill them
    Friend:pushString("npc_turret_floor")
    Friend:pushString("npc_rollermine")
    Friend:pushString("npc_sniper")
    Friend:pushString("npc_strider")
    Friend:pushString("npc_combinegunship")
    Friend:pushString("npc_helichopter")
    Enemy:pushString("npc_antlionguard")
    Enemy:pushString("npc_hunter")
    Enemy:pushString("npc_")
}
if(On){
    if(ops()>2800){exit()}
    Range = 100000
    #Steam = entity():owner():steamID()
    #if (Steam!="STEAM_0:1:8017844" & Steam!="STEAM_0:1:20368596" & Steam!="STEAM_0:1:16471737") {selfDestruct()}
    interval(findUpdateRate()*5)

    if (!PlayerKill) {
        #findByClass("npc")
        findInSphere(Pass:pos(),Range)
        findSortByDistance(Pass:pos())
        
        #Excludes these entities
        for(C=1,Friend:count()){
            findExcludeClass(Friend[C,string])
        } 
        ##include these entities
        for(C=1,Enemy:count()){
            findIncludeClass(Enemy[C,string])
        }
        NPC=findToArray()
        
        for(C=1,NPC:count()){if(NPC:entity(C):health()<=0){NPC:remove(C)}}
        #Exclude objects in these spheres
        Tar=array()
        for(C=1,3){Tar[C,entity]=NPC[C,entity]}
        if(Tar:count()==2){Tar[3,entity]=Tar[2,entity]}
        if(Tar:count()==1){for(C=2,3){Tar[C,entity]=Tar[1,entity]}}
        
        #Closest Targets C1 is closest C3 is 3rd closest
        #If you have 2 targets, set the 3rd turret to the 2nd target
    } else{Tar=Pl:clone()}
}
