@name CTF4 II
@inputs 
@outputs Goals:array Players:array Flags:array
@outputs T1:entity T2:entity T3:entity T4:entity
@persist 
@trigger 
interval(20)

#This finds all the items for play formerly done by separate chips
FlagModel="roller.mdl"
GoalModel="ammocrate"
if(findUpdateRate()){
findInSphere(entity():pos(),100000)
findIncludeClass("player")
findIncludeModel(GoalModel)
findIncludeModel(FlagModel)
Dump=findToArray()
Players=array()
Flags=array()
Goals=array()
for(C=1,Dump:count()){
DC=Dump[C,entity]

if(DC:radius()){
if(DC:isPlayer()){Players:pushEntity(DC)}
if(DC:owner()==entity():owner()){
if(DC:model():find(GoalModel)){Goals:pushEntity(DC)}
if(DC:model():find(FlagModel)){Flags:pushEntity(DC)}
}}
Tar=array()
for(C=1,Players:count()){
Pl=Players[C,entity]
    for(D=1,Flags:count()){
    Fl=Flags[D,entity]
    Di=Fl:pos():distance(Pl:pos())<120
    if(Di&Flags[1,entity]==Fl){T1=Pl}
    if(Di&Flags[2,entity]==Fl){T2=Pl}
    if(Di&Flags[3,entity]==Fl){T3=Pl}
    if(Di&Flags[4,entity]==Fl){T4=Pl}
}}}}
