@name VaultDoor
@inputs 
@outputs User:entity 
@persist A State Prop1:entity 
@trigger 
runOnTick(1)

findByClass("player")
User = findClosest(entity():pos())

if (first()) {
    holoCreate(1)
    holoModel(1,"models/hunter/tubes/tube2x2x1c.mdl")
    holoPos(1,entity():toWorld(vec(0,0,60)))
    holoAng(1,entity():angles()+ang(90,90,0))
    holoScale(1,vec(1,1,0.25))
    
    holoCreate(2)
    holoModel(2,"models/hunter/plates/plate025x125.mdl")
    holoPos(2,entity():toWorld(vec(44.4,0,31)))
    holoAng(2,entity():angles()+ang(0,90,90))
    
    holoCreate(3)
    holoModel(3,"models/hunter/plates/plate025x125.mdl")
    holoPos(3,entity():toWorld(vec(-47.4,0,31)))
    holoAng(3,entity():angles()+ang(0,90,90))
    
    holoCreate(4)
    holoPos(4,entity():toWorld(vec(44,0,46)))
    holoAlpha(4,0)
    
    holoCreate(5)
    holoModel(5,"models/hunter/tubes/circle2x2c.mdl")
    holoPos(5,entity():toWorld(vec(0,0,60)))
    holoAng(5,entity():angles()+ang(90,90,0))
    holoParent(5,4)
    
    holoCreate(6)
    holoModel(6,"models/hunter/plates/plate1x2.mdl")
    holoPos(6,entity():toWorld(vec(0,0,30)))
    holoAng(6,entity():angles()+ang(90,90,0))
    holoScale(6,vec(1.27,1,1))
    holoParent(6,4)
    
    holoCreate(7)
    holoModel(7,"models/props_borealis/door_wheel001a.mdl")
    holoPos(7,entity():toWorld(vec(0,0,42)))
    holoAng(7,entity():angles()+ang(0,90,0))
    holoScale(7,vec(1.6,1.6,1.6))
    holoParent(7,6)
    
    Prop1 = propSpawn("models/hunter/plates/plate1x2.mdl",1)
    Prop1:setPos(holoEntity(6):pos())
    Prop1:setAng(holoEntity(6):angles())
    Prop1:setColor(vec(255,255,255),0)
}

if (User:aimEntity() == Prop1 & changed(User:keyAttack1()) & User:keyAttack1() & User:weapon():type() == "lockpick") {
    timer("lockpick",randint(25000,30000))
    Prop1:soundPlay(1,0.8,"weapons/357/357_reload3.wav")
}

if (clk("lockpick")) {
    State = 1
}

R = owner():aimEntity() == Prop1 & owner():keyUse()

if(changed(R) & R) {if(State == 0) {State = 1} else {State = 0}}

if(State == 1) {
    if(A < 0.1) {
        A += 0.01
        holoAng(7,holoEntity(7):angles()+ang(0,0,8))
        timer("wait",2500)
    }
} else {
    if(A > 0) {
        A -= 0.01
        holoAng(4,holoEntity(4):angles()+ang(0,7,0))
        holoAng(7,holoEntity(7):angles()+ang(0,0,-8))
    }
}

if (clk("wait")) {
    holoAng(4,holoEntity(4):angles()+ang(0,-70,0))
}
