@name Garage E2 Door
@persist Allowed:array
@outputs A
@persist User:entity
interval(100)
runOnChat(1)
if (first()) {
    function number isok(E:entity) {
        for (I=1, Allowed:count()) {
            if (E==Allowed[I,entity]) {return 1}
        }
        return 0
    }
}
findByClass("player")
User=findClosest(entity():pos())
if (User:inVehicle() & isok(User)) {
    Car=User:vehicle()
    MaxDist=Car:aabbSize():y()*2
    if (User:pos():distance(entity():pos())<MaxDist) {
        A=0
} else {A=1}
} else {A=1}
if (chatClk(owner()) & owner():lastSaid():sub(1,1)=="-") {
    hideChat(1)
    CMD=owner():lastSaid():sub(2)
    Args=CMD:explode(" ")
    if (Args:count()<1) {
        Args[1,string]=CMD
    }
    if (Args[1,string]=="reset") {
        print("Resetting door")
        reset()
    } elseif (Args[1,string]=="add") {
        print("Attempting to add "+Args[2,string]+" to table")
        Players=players()
        for (I=1, Players:count()) {
            if (Players[I,entity]:name():lower():matchFirst(Args[2,string]:lower())) {
                print("Added "+(Players[I,entity]:name())+" to allowed")
                Allowed[Allowed:count()+1,entity]=Players[I,entity]
            }
        }
    } elseif (Args[1,string]=="remove") {
        for (I=1, Allowed:count()) {
            if (Allowed[I,entity]:name():lower():matchFirst(Args[2,string]:lower())) {
                print("Popping "+(Allowed[I,entity]:name())+" from table.")
                Allowed:removeEntity(I)
        }
    }
}
}
