@name Interactive Targeting
@inputs N
@outputs Targets:array TID 
@persist Players:array Chat1:string Last PA:array
Time = 250
interval(Time)
entity():setColor(0,140,255)
Command = "jack"
Menu = "menu"
Attack = "get" 
List = "list"
if(first()){
    PA=array()
    PA:pushString("1")
    PA:pushString("2")
    PA:pushString("3")
    PA:pushString("4")
    PA:pushString("5")
    PA:pushString("6")
    PA:pushString("7")
    PA:pushString("8")
    PA:pushString("9")
    PA:pushString("0")
}
S = " "
Origin = entity():pos()
findInSphere(Origin,1000000)
findSortByDistance(Origin)
findIncludeClass("player")
Players = findToArray()

Owner = entity():owner()
Chat = Owner:lastSaid()
#K=curtime()-Owner:lastSaidWhen()<Time*2/1000
K=chatClk()
runOnChat(1)
if(K){
    C = Chat:find(Command)
    M = Chat:find(Menu)
    A = Chat:find(Attack)
    L = Chat:find(List)
    CA=array()
    for(C=1,10){
        CA:pushNumber(Chat:find(PA[C,string]))
    }


#C1 = Chat:find(P1)
#C2 = Chat:find(P2)
#C3 = Chat:find(P3)
#C4 = Chat:find(P4)
#C5 = Chat:find(P5)
#C6 = Chat:find(P6)
#C7 = Chat:find(P7)
#C8 = Chat:find(P8)
#C9 = Chat:find(P9)
#C10 = Chat:find(P10)


    Concat = array()
    Concat:pushString("Targets:")
    for(C=0,9){
        if(Players:count()>C){
            Concat:pushString(S+PA[C+1,string]+S+Players[C+1,entity]:name())
            
        }
    }
}
#if (Players:count()>0) {
#Concat:setString(1,"Targets: ")
#Concat:setString(2,P1+S)
#Concat:setString(3,Players:entity(1):name())
#}
#if (Players:count()>1) {
#Concat:setString(4,S+P2+S)
#Concat:setString(5,Players:entity(2):name())
#}
#if (Players:count()>2) {
#Concat:setString(6,S+P3+S)
#Concat:setString(7,Players:entity(3):name())
#}
#if (Players:count()>3) {
#Concat:setString(8,S+P4+S)
#Concat:setString(9,Players:entity(4):name())
#}
#if (Players:count()>4) {
#Concat:setString(10,S+P5+S)
#Concat:setString(11,Players:entity(5):name())
#}
#if (Players:count()>5) {
#Concat:setString(12,S+P6+S)
#Concat:setString(13,Players:entity(6):name())
#}
#if (Players:count()>6) {
#Concat:setString(14,S+P7+S)
#Concat:setString(15,Players:entity(7):name())
#}
#if (Players:count()>7) {
#Concat:setString(16,S+P8+S)
#Concat:setString(17,Players:entity(8):name())
#}
#if (Players:count()>8) {
#Concat:setString(17,S+P9+S)
#Concat:setString(18,Players:entity(9):name())
#}
#if (Players:count()>9) {
#Concat:setString(19,S+P10+S)
#Concat:setString(20,Players:entity(10):name())
#}


if(C&K){
if (M) {print(Concat:concat())}
if (A) {
    Targets = array()
    E = 1
    for(C=1,CA:count()){
        if(CA[C,number]){Targets:pushEntity(Players[C,entity])}
    }    
#    if (C1) {Targets:setEntity(E,Players:entity(1)) E+=1}
#    if (C2) {Targets:setEntity(E,Players:entity(2)) E+=1}
#    if (C3) {Targets:setEntity(E,Players:entity(3)) E+=1}
#    if (C4) {Targets:setEntity(E,Players:entity(4)) E+=1}
#    if (C5) {Targets:setEntity(E,Players:entity(5)) E+=1}
#    if (C6) {Targets:setEntity(E,Players:entity(6)) E+=1}
#    if (C7) {Targets:setEntity(E,Players:entity(7)) E+=1}
#    if (C8) {Targets:setEntity(E,Players:entity(8)) E+=1}
#    if (C9) {Targets:setEntity(E,Players:entity(9)) E+=1}
#    if (C10) {Targets:setEntity(E,Players:entity(10)) E+=1}
}

TID = Targets:entity(N):id()
if (L) {print(Targets:concat())}
}#End of C&K

Count = Targets:count()
#D1=D2=D3=D4=D5=D6=D7=D8=D9=D10=1000000
Dist = array()
for(C=1,10){
    Dist[C,number]=1000000
}
for(C=0,9){
    if(Count>C){Dist[C+1,number]=Targets[C+1,entity]:pos():distance(Origin)}
}
#if (Count>0) {D1 = Targets:entity(1):pos():distance(Origin)} 
#if (Count>1) {D2 = Targets:entity(2):pos():distance(Origin)} 
#if (Count>2) {D3 = Targets:entity(3):pos():distance(Origin)} 
#if (Count>3) {D4 = Targets:entity(4):pos():distance(Origin)} 
#if (Count>4) {D5 = Targets:entity(5):pos():distance(Origin)} 
#if (Count>5) {D6 = Targets:entity(6):pos():distance(Origin)} 
#if (Count>6) {D7 = Targets:entity(7):pos():distance(Origin)} 
#if (Count>7) {D8 = Targets:entity(8):pos():distance(Origin)} 
#if (Count>8) {D9 = Targets:entity(9):pos():distance(Origin)} 
#if (Count>9) {D10 = Targets:entity(10):pos():distance(Origin)} 
#Dist:setNumber(1,D1)
#Dist:setNumber(2,D2)
#Dist:setNumber(3,D3)
#Dist:setNumber(4,D4)
#Dist:setNumber(5,D5)
#Dist:setNumber(6,D6)
#Dist:setNumber(7,D7)
#Dist:setNumber(8,D8)
#Dist:setNumber(9,D9)
#Dist:setNumber(10,D10)
K1 = Dist:minIndex()
Dist:remove(K1)
K2 = Dist:minIndex()
Dist:remove(K2)
K3 = Dist:minIndex()

T1 = Targets:entity(K1):id()
T2 = Targets:entity(K2):id()
T3 = Targets:entity(K3):id()



