@name Auto Door 
@inputs 
@outputs Door:entity
@persist [Allowed Distances]:array Door:entity On
@trigger 
runOnChat(1)
interval(100)


function void printCommands(){
    hint("Commands have been printed type /help if you lose them", 3)
    print("Make sure the chip is attatched to the desired door prop")
    print("Type /add <player name> to add someone")
    print("Type /remove <player name> to remove someone")
    
    
    }


if(first() | dupefinished()){

    Door = entity():isWeldedTo()
    }


if(chatClk(owner())){
    
    #1 If the owner talked in chat.
    
    #2 CC is what the owner said last
    
    #3 If the string /add was said by the OWNER then:
    #Hide the chat of what hey said.
    #Find the last said player (2) and set as a Allowed user.
    
    #Remove is the opposite getting it from an array.
    
    
    
    
    CC=owner():lastSaid():explode(" ")
    if(CC:string(1)=="/add"){
        hideChat(1)
        Allowed:pushEntity(findPlayerByName(CC:string(2)))
        hint("Added: " + findPlayerByName(CC:string(2)):name(),3)
        }
    if(CC:string(1)=="/remove"){
        hideChat(1)
        for(I=1, Allowed:count()){
            if(Allowed[I, entity]:name()==findPlayerByName(CC:string(2)):name()){
                Allowed:remove(I)
                }
            }
            hint("Removed: " + findPlayerByName(CC:string(2)):name(),3)
        }
    if(CC:string(1)=="/help"){
        hideChat(1)
        printCommands()
        }
    if(CC:string(1)=="/print"){
        hideChat(1)
        print(Allowed)
        }
    }


if(findCanQuery()){
    for(I=1, Allowed:count()){
        Distances[I, number] = Allowed[I, entity]:pos():distance(entity():pos())
        }
    for(I=1, Distances:count()){
        if(Allowed:exists(I)){
        if(Distances[I, number]<=60){
            Door:propNotSolid(1)
        }else{Door:propNotSolid(0)}
        }
}
    }

