@name Auto Door WireMod Door Extra
@inputs Ent:vector Numpad 
@outputs Door Door2 OpenDoor CloseDoor
@persist [SwaggyPlayers Last]:array [AFound Found Closest In]:entity Swaggy:string Max Distance

if(first()|duped()){
    hint("Type + to add and - to remove a person! Type !list to see the list of people",5)
    hint("Made By Mailman02",5)
    print( _HUD_PRINTCENTER,("Type + to add and - to remove a person! Type !list to see the list of people"))
    entity():setColor( 33,255,0 )
    
    setName( owner():name() + "'s Auto Door Wiremod Extra" )
    
    runOnChat(1)
    Ent=vec(4936,-1471,-195)
    SwaggyPlayers = array(owner():name())
    Distance = 50
}
interval(100)
if(chatClk(owner())){
    Last = owner():lastSaid():explode(" ")
    Max = 0
    foreach(Index,Name:string=SwaggyPlayers){
        Max = Index
    }
    if(Last[1,string] == "+"){
        hideChat(chatClk(owner()))
        if(Last:count() > 1){
            Found = findPlayerByName(Last[2,string])
            if(Found == noentity()){
                print( _HUD_PRINTCENTER,("Player Not Found"))
            } else {
                Swaggy = SwaggyPlayers:concat()
                if(!Swaggy:find(Found:name())){
                    print(Found:name() + " is now swaggy")
                    SwaggyPlayers[Max+1,string] = Found:name()
                    entity():soundPlay(1,1,"/buttons/blip1.wav")
                } else {
                    print( _HUD_PRINTCENTER,(Found:name() + " is already swaggy"))
                    entity():soundPlay(1,1,"/buttons/button10.wav")
                }
            }
        } else {
      print( _HUD_PRINTCENTER,("Type + (name) to add someone"))
        }
    }
    if(Last[1,string] == "-"){
        hideChat(chatClk(owner()))
        if(Last:count() > 1){
            foreach(Index,Name:string=SwaggyPlayers){
                if(Name:lower():find(Last[2,string])){
                    print(Name + " is no longer swaggy!")
                    entity():soundPlay(1,1,"/buttons/blip1.wav")
                    SwaggyPlayers:remove(Index)
                    break
                }
                if(Index == SwaggyPlayers:count()){
                    print(Last[2,string] + " is not swaggy")
                    entity():soundPlay(1,1,"/buttons/button10.wav")
                }
            }
        } else {
            print("!remove [Player Name]")
        }
    }
    if(Last[1,string] == "!list"){
        hideChat(chatClk(owner()))
        print(SwaggyPlayers:count() + " Swaggy player(s):")
        foreach(Index,Name:string=SwaggyPlayers){
            print(Name)
        }
    }
    if(Last[1,string] == "!distance"){
        hideChat(chatClk(owner()))
        if(Last:count() > 1 & Last[2,string]:toNumber()){
            Distance = Last[2,string]:toNumber()
            print("Open distance set to: "+Last[2,string]:toNumber())
            entity():soundPlay(1,1,"/buttons/blip1wav")
        } else {
            print("!dis [Distance]")
        }
    }
} else {
    Door = 0
    CloseDoor = 1
    OpenDoor = 0
    Door2 = 0
    findByClass("player")
    AFound = findClosest(entity():pos())
    if(AFound:pos():distance(entity():pos())<Distance){
        foreach(Index,Name:string=SwaggyPlayers){
            if(AFound:name():lower() == Name:lower()){
                Door = 1
                CloseDoor = 0
                OpenDoor = 1 
                
            }
        }
    }
}

