@name GarageHouseGarageDoor
@inputs [Door Button Button2]:entity 
@outputs [User User2]:entity 
@persist A State 
@trigger 
interval(100)

findInSphere(Button:pos(),40)
User = find()

findInSphere(Button2:pos(),40)
User2 = find()

if (first()) {
    Door:setAlpha(0)
    
    holoCreate(1)
    holoScale(1,Door:boxSize()/12+vec(0,0,-0.06))
    holoMaterial(1,Door:getMaterial())
    holoPos(1,Door:pos())
    holoAng(1,Door:angles())
    
    holoClipEnabled(1,1,1)
    holoClip(1,vec(0,0,-1),vec(0,0,-1),1)
    
    Door:parentTo(holoEntity(1))
    Button:setAlpha(0)
    Button2:setAlpha(0)
}

if (User:aimEntity() == Button & changed(User:keyUse()) & User:keyUse()) {
if (State == 0) {State = 1} else {State = 0}}

if (User2:aimEntity() == Button2 & changed(User2:keyUse()) & User2:keyUse()) {
if (State == 0) {State = 1} else {State = 0}}

if(State == 1) {
    if(A < 1) {
        A += 0.014
        holoPos(1,holoEntity(1):pos()+vec(0,0,2))
    }
} else {
    if(A > 0) {
        A -= 0.014
        holoPos(1,holoEntity(1):pos()+vec(0,0,-2))
    }
}

if (changed(State == 1) & State == 1) {
    Door:soundPlay(1,7.4,"doors/doormove7.wav")
    timer("open",7400)
} elseif (changed(State == 0) & State == 0) {
    Door:soundPlay(3,7.4,"doors/doormove7.wav")
    timer("close",7400)
}

if (clk("open")) {
    Door:soundPlay(2,2,"doors/door_metal_large_open1.wav")
}

if (clk("close")) {
    Door:soundPlay(4,2,"doors/door_metal_large_open1.wav")
}
