@name GarageHouseDoor
@inputs [Door Handle Handle2]:entity 
@outputs User:entity 
@persist Locked 
@trigger 
interval(100)
runOnChat(1)

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

if (first()) {
    holoCreate(1)
    holoPos(1,Door:toWorld(vec(-24,0,0)))
    holoAlpha(1,0)
    
    holoCreate(2)
    holoModel(2,Handle:model())
    holoPos(2,Handle:pos())
    holoAng(2,Handle:angles())
    holoParent(2,Door)
    
    holoCreate(3)
    holoModel(3,Handle2:model())
    holoPos(3,Handle2:pos())
    holoAng(3,Handle2:angles())
    holoParent(3,Door)
    
    Handle:setAlpha(0)
    Handle2:setAlpha(0)
    Door:setAlpha(0)
    
    holoCreate(4)
    holoMaterial(4,"phoenix_storms/Indenttiles_1-2")
    holoPos(4,Door:pos())
    holoAng(4,Door:angles())
    holoScale(4,Door:boxSize()/12+vec(0,0,-0.08))
    holoParent(4,1)
    
    Door:parentTo(holoEntity(1))
    
    Locked = 0
}

Handle:setPos(holoEntity(2):pos())
Handle:setAng(holoEntity(2):angles())

Handle2:setPos(holoEntity(3):pos())
Handle2:setAng(holoEntity(3):angles())

if (Locked == 0 & User:aimEntity() == Handle & changed(User:keyUse()) & User:keyUse()) {
    holoAng(1,ang(0,-90,0))
    Door:soundPlay(1,0,"doors/door_latch3.wav")
    timer("close",5000)
}

if (Locked == 0 & User:aimEntity() == Handle2 & changed(User:keyUse()) & User:keyUse()) {
    holoAng(1,ang(0,90,0))
    Door:soundPlay(1,0,"doors/door_latch3.wav")
    timer("close2",5000)
}

if (clk("close")) {
    holoAng(1,ang(0,0,0))
    Door:soundPlay(2,0,"doors/door_wood_close1.wav")
    timer("wait",2000)
}

if (clk("close2")) {
    holoAng(1,ang(0,0,0))
    Door:soundPlay(2,0,"doors/door_wood_close1.wav")
    timer("wait2",2000)
}

if (clk("wait")) {
    soundStop(1)
    soundStop(2)
}

if (clk("wait2")) {
    soundStop(1)
    soundStop(2)
}

if (Locked == 1 & User:aimEntity() == Handle & changed(User:keyUse()) & User:keyUse()) {
    Door:soundPlay(3,0.8,"doors/door_lock_1.wav")
}

if (Locked == 1 & User:aimEntity() == Handle2 & changed(User:keyUse()) & User:keyUse()) {
    Door:soundPlay(3,0.8,"doors/door_lock_1.wav")
}

if (chatClk(owner()) & owner():lastSaid():find("!lock")) {
    hideChat(1)
    Locked = 1
}

if (chatClk(owner()) & owner():lastSaid():find("!unlock")) {
    hideChat(1)
    Locked = 0
}
