@name Port Key 2
@inputs 
@outputs Kp1:vector Kp2:vector Use1 Use2 Key1off Key2off
@persist Obj:array Pl:array New:string Key1:entity Key2:entity
@persist Rad1 Rad2 Key1off Key2off Offset:vector
@trigger all

interval(1000)
if(first()|duped()){
    entity():setAlpha(0)
    Obj=entity():getConstraints()
    if(Obj:count()==1){
        print("nocolid 2 things then add me to one, not before")
        selfDestruct()
    }
    New="new player"
    timer(New,1)
    Key1=Obj[1,entity]
    Key2=Obj[2,entity]
    Buffer=75
    Rad1=Key1:radius()+Buffer
    Rad2=Key2:radius()+Buffer

}
timer(New,10000)
if(clk(New)){
#findByClass("player")
#Pl=findToArray()
Pl=players()
}
Dist1=array()
Dist2=array()
PCount=Pl:count()

    C=1

while(C<=PCount&perf()){
    Dist1:setNumber(C,Key1:pos():distance(Pl:entity(C):pos()))
    Dist2:setNumber(C,Key2:pos():distance(Pl:entity(C):pos()))
    C++
}
Near1=Dist1:min() Pl1=Pl:entity(Dist1:minIndex()) Use1=Pl1:keyUse()
Near2=Dist2:min() Pl2=Pl:entity(Dist2:minIndex()) Use2=Pl2:keyUse()



if(Near1<Rad1&Use1&!Key1off){
    Key2off=1
    timer("key2off",2000)
    Pl1:teleport(Key2:pos()+vec(0,0,Rad2))
    }    
if(Near2<Rad2&Use2&!Key2off){
    Key1off=1
    timer("key1off",2000)
    Pl2:teleport(Key1:pos()+vec(0,0,Rad1))
    }    
if(clk("key2off")){Key2off=0}
if(clk("key1off")){Key1off=0}

Kp1=Key1:pos()
Kp2=Key2:pos()
