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

if (first() | dupefinished()) {
    entity():setAlpha(0)
    
    holoCreate(1)
    holoPos(1,D1:toWorld(vec(0,0,0)))
    holoAng(1,ang(90,-90,90))
    holoAlpha(1,0)
    
    Scale = vec(8,8,10) * 12
    
    Door = holoCreate(2)
    
    holoScaleUnits(2,Scale)
    holoPos(2,entity():isWeldedTo():toWorld(vec(70,0,0)))
    holoAng(2,entity():isWeldedTo():angles())
    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())

D1:setAng(holoEntity(1):angles() + ang(0,0,0))

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 < 111) {
        A += 5
        holoAng(1,holoEntity(1):angles() - ang(4,0,0))
        D2:setPos(D2:pos() + vec(0,3,0))
    }
} else {
    if(A > 0) {
        soundStop(0)
        A -= 5
        holoAng(1,holoEntity(1):angles() + ang(4,0,0))
        D2:setPos(D2:pos() - vec(0,3,0))
    }
}
