@name BadassDoor
@persist E:entity MoveMax MoveCurrent State Scale:vector Percent Scale2
@inputs A
#1,0,0
if (first()) {
    Scale=vec(-3,0,0) #scale at which to move (toworld)
    Scale2=3
    Percent=40 #% at which to make the prop nocollide
    E=entity():isWeldedTo()
    E:setAlpha(0)
    MoveMax=E:aabbSize():x()
    print(MoveMax)
    holoDeleteAll()
    holoCreate(1,E:toWorld(vec(0,0,0)))
    holoAng(1,E:angles())
    holoModel(1,E:model())
    holoScale(1,vec(1,1,0.5))
    holoMaterial(1,E:getMaterial())
    holoColor(1,E:getColor())
    function sound(S:string) {
        for (I=1, 7) {
            soundStop(I)
            E:soundPlay(I,0,S)
        }
    }
    function sound2(S:string) {
        for (I=1, 4) {
            soundStop(I+7)
            E:soundPlay(I+7,0,S)
        }
    }
}
if (changed(A)) {
    sound("doors/door_metal_gate_move1.wav")
}
if (changed(A) & A) {
    sound2("buttons/button6.wav")
}
if (changed(A) & !A) {
    sound2("buttons/button4.wav")
}

if (A) {
    if (MoveCurrent<MoveMax/Scale2-1) {
        MoveCurrent++
        #print(MoveCurrent)
        holoPos(1,E:toWorld(Scale*MoveCurrent))
        if (MoveCurrent>=MoveMax/Scale2-1) {
            sound("doors/door_metal_large_close2.wav")
        }
    }
    #print(MoveCurrent,MoveMax)
} else {
    if (MoveCurrent>0) {
        MoveCurrent--
        holoPos(1,E:toWorld(Scale*MoveCurrent))
        if (MoveCurrent<=0) {
            sound("doors/door_metal_large_close2.wav")
        }
    }
}

if (MoveCurrent/(MoveMax/Scale2)<=Percent/100) {
    E:propNotSolid(0)
} else {
    E:propNotSolid(1)
}
interval(100)
holoScale(1,vec(1,1,0.3))
holoMaterial(1,E:getMaterial())
holoColor(1,E:getColor())
entity():isWeldedTo():setAlpha(0)
