@name Smart-Opener V3
@inputs Add Remove User:entity
@outputs Open
@persist P:array Distance:array Target:entity D Z TP:entity Time I
@trigger


interval(200)


#Distance
D = 100



#
Target = TP
S = owner():lastSaid():explode(" ")
if(S[1,string]==".ad" & chatClk(owner())){
    TP = findPlayerByName(S[2,string])
    if(TP:isPlayer()){
        Target == TP
        P:pushEntity(TP) 
        hint(TP:name() + " has been added", 7)
           }
    
}
if(S[1,string]==".re"& chatClk(owner())){
    TP = findPlayerByName(S[2,string])
    if(TP:isPlayer()){
        while(Z < 20){
        if(TP == P[Z,entity])
        {
        P:remove(Z)
        hint(TP:name() + " has been removed", 7)
        }
        Z++
}
}
Z = 0
}
Distance1 = round(((entity():pos() - P[1,entity]:pos()):length()))
Distance2 = round(((entity():pos() - P[2,entity]:pos()):length()))
Distance3 = round(((entity():pos() - P[3,entity]:pos()):length()))
Distance4 = round(((entity():pos() - P[4,entity]:pos()):length()))
Distance5 = round(((entity():pos() - P[5,entity]:pos()):length()))
Distance6 = round(((entity():pos() - P[6,entity]:pos()):length()))
Distance7 = round(((entity():pos() - P[7,entity]:pos()):length()))
Distance8 = round(((entity():pos() - P[8,entity]:pos()):length()))
Distance9 = round(((entity():pos() - P[9,entity]:pos()):length()))
Distance10 = round(((entity():pos() - P[10,entity]:pos()):length()))
Open = 0

if(Distance1<D){Open = 1
}elseif(Distance2<D){Open = 1
}elseif(Distance3<D){Open = 1
}elseif(Distance4<D){Open = 1
}elseif(Distance5<D){Open = 1
}elseif(Distance6<D){Open = 1
}elseif(Distance7<D){Open = 1
}elseif(Distance8<D){Open = 1
}elseif(Distance9<D){Open = 1
}elseif(Distance10<D){Open = 1
}


if(Add & Time){
    TP = User
    if(TP:isPlayer()){
        Target == TP
        P:pushEntity(TP)
        hint(TP:name() + " has been added", 7)
        Time = 0
        Timeleft = 2
        I = 1000
}}

if(Remove){
    TP = User
    if(TP:isPlayer()){
        while(Z < 20){
        if(TP == P[Z,entity])
        {
        P:remove(Z)
        hint(TP:name() + " has been removed", 7)
        }
        Z++
}
}
Z = 0
}

if(Time == 0){
    if(Timeleft == 0){
        Time = 1
        I = 1
    }
    else{
        if(clk()){Timeleft--}
    }
}
