@name Cenn's Multi Door opener
@inputs [D1 D2 D3 D4 D5]:wirelink
@outputs S:array
@persist Radius Interval


interval(1)

runOnChat(1)

L = owner():lastSaid() 


if(first()){
    Interval = 250
     Players = players()
    Pplayers = Players
    Radius = 50
    I = 0
    while(I < Players:count()){
        findExcludePlayer(Players[I,entity])
        findDisallowPlayer(Players[I,entity])
        I++
    }
}



function addplayer(P:string){
    findIncludePlayer(P)
    findAllowPlayer(P)
}

function remplayer(P:string){
    findExcludePlayer(P)
    findDisallowPlayer(P)
}


function void message(A:array){
    if(A[1,string] == ".add"){
    addplayer(A[2,string])
    }
    
    if(A[1,string] == ".rem"){
    remplayer(A[2,string])
    }
    
    if(A[1,string] == ".set"){
    Radius = A[2,string]:toNumber()
    } 
    
}

if(chatClk(owner()) || chatClk(findPlayerByName("Hirvio"))){
    A = L:explode(" ")
    message(A)
}

findInSphere(D1:entity():pos(),Radius+20)
findSortByDistance(D1:entity():pos())
findClipToClass("player")
A1 = findToArray()

findInSphere(D2:entity():pos(),Radius+20)
findSortByDistance(D2:entity():pos())
findClipToClass("player")
A2 = findToArray()

findInSphere(D3:entity():pos(),Radius+20)
findSortByDistance(D3:entity():pos())
findClipToClass("player")
A3 = findToArray()

findInSphere(D4:entity():pos(),Radius+20)
findSortByDistance(D4:entity():pos())
findClipToClass("player")
A4 = findToArray()

findInSphere(D5:entity():pos(),Radius+20)
findSortByDistance(D5:entity():pos())
findClipToClass("player")
A5 = findToArray()

if(A1[1,entity]:pos():distance(D1:entity():pos())< Radius & A1[1,entity]:isAlive()){
    D1["Fade",number] = 1
}else{D1["Fade",number] = 0}

if(A2[1,entity]:pos():distance(D2:entity():pos())< Radius & A2[1,entity]:isAlive()){
    D2["Fade",number] = 1
}else{D2["Fade",number] = 0}

if(A3[1,entity]:pos():distance(D3:entity():pos())< Radius & A3[1,entity]:isAlive()){
D3["Fade",number] = 1
}else{D3["Fade",number] = 0}

if(A4[1,entity]:pos():distance(D4:entity():pos())< Radius & A4[1,entity]:isAlive()){
    D4["Fade",number] = 1
}else{D4["Fade",number] = 0}

if(A5[1,entity]:pos():distance(D5:entity():pos())< Radius & A5[1,entity]:isAlive()){
    D5["Fade",number] = 1
}else{D5["Fade",number] = 0}


if(players():count() != Players:count()){
        findExcludePlayer(Players[Players:count(),entity])
        findDisallowPlayer(Players[Players:count(),entity])
}
