@name Hotel 2 Door
@inputs D1:entity 
@outputs 
@persist A State [CornerPos1 CornerPos2]:vector 
@trigger 
interval(100)

if (first() | dupefinished()) {
    entity():setAlpha(0)
    
    Scale = vec(5,5,8) * 12
    
    Door = holoCreate(2)
    
    holoScaleUnits(2,Scale)
    holoPos(2,entity():isWeldedTo():toWorld(vec(-30,30,40)))
    holoAng(2,entity():isWeldedTo():angles() + ang(0,45,0))
    holoColor(2,vec(255,255,255),255)
    holoParent(2,entity())
    
    CornerPos1 = Scale / 2
    CornerPos2 = -CornerPos1
    
    CornerPos1 = Door:toWorld(CornerPos1)
    CornerPos2 = Door:toWorld(CornerPos2)
    
    CornerScale = vec() + 1
    
    holoCreate(3)
    holoPos(3,CornerPos1)
    holoScaleUnits(3,CornerScale)
    holoParent(3, Door)
    
    holoCreate(4)
    holoPos(4,CornerPos2)
    holoScaleUnits(4,CornerScale)
    holoParent(4, Door)
    
    for (I = 2,4) {holoColor(I,vec(),0)}
}

findInBox(CornerPos1,CornerPos2)
findIncludeClass("player")
User = findClosest(holoEntity(1):pos())

if (User:isPlayer()) {State = 1} else {State = 0}

if (changed(State == 1) & State == 1) {
    #soundPlay(0,0,"doors/door_metal_thin_close2.wav")
    soundPitch(0,50)
    soundVolume(0,0.4)
}

if(State == 1) {
    if(A < 700) {
        A += 20
        D1:setAng(D1:angles() + ang(0,5,0))
    }
} else {
    if(A > 0) {
        soundStop(0)
        A -= 20
        D1:setAng(D1:angles() - ang(0,5,0))
    }
}
