@name Port Key
@inputs Reset
@outputs Count Self ID:string 
@outputs Dist Link1 Link2 Me Pos:vector Use Offset:vector
@persist Array:array Self ID:string Count  Pos:vector
@persist Plate:entity Pl:array Me 
interval(1000)
if(duped()){ timer("reset",random(100,500))}
Net="net"




if(first()){
    timer("Start",1000) 
    timer("net",2000)
}
entity():setAlpha(0)
if (clk("Start")) {
Plate=entity():isConstrainedTo()
Array=entity():getConstraints() Self=entity():id()
Count=Array:count()}
if (Reset) {reset()}
if(Array:count()){interval(10)



Self+=Array:popEntity():id()
ID = toString(Self)
}
if (!Array:count()) {
#Your chip here
if (clk("Start")) {hint(ID,7)}
}

gSetGroup(ID)
if(clk("net")){
IDs=gGetNum(Net)
#print("IDs: "+IDs)
#print("Me B: "+Me)
if (Me==0){
if(IDs<2){
    Me=IDs+1 
    gSetNum(Net,Me) 
    print("Key Pair: "+ID+"Unit:"+Me)
    }else{Me=0 gSetNum(Net,0) print("IDs: "+IDs) timer(Net,1)}}

}


if(Me==1){
    Link2=gDeleteNum("Link2")
    Offset=vec(0,0,entity(Link2):radius())   
    gSetNum("Link1",Plate:id())
    Pos=entity(Link2):pos()+Offset
}
if(Me==2){
    Link1=gDeleteNum("Link1")
    Offset=vec(0,0,entity(Link1):radius() ) 
    gSetNum("Link2",Plate:id())
    Pos=entity(Link1):pos()+Offset
}

if(clk("jump")){gSetNum("Stop",0)}
Stop=gGetNum("Stop")
findByClass("player")
findSortByDistance(Plate:pos())
Pl=findToArray()
Use=Pl:entity(1):keyUse()
Dist=Plate:pos():distance(Pl:entity(1):pos())
if(Dist<Plate:radius()+50 & Use &!Stop){
    gSetNum("Stop",1)
    Pl:entity(1):setPos(Pos)
        timer("jump",2000)
    }
    Chat=entity():owner():lastSaid()
    Tele=Chat:find("Tele")
    if(Chat:find("Reset Tele")){
    gDeleteNum(Net)
    timer("reset",random(100,500))}
if(Chat:find("Die")&Dist<Plate:radius()+100&Tele){
    print("Teleporter Destroyed")
    gSetNum("Kill",1)
    selfDestruct()}
if(clk("reset")){reset()}
if(Dist<Plate:radius()+100 & Chat:find("ID")&Tele){
print("This teleporter's ID is: "+ID)}

if(gDeleteNum("Kill")){selfDestruct()}

if(!Count==1&Pos==vec(0,0,0)|Pos==Offset&!clk("Start")){timer("Start",5000)}
