@name Kron's Damage Door
@inputs In Button DmgClk Dmger:entity 
@outputs Reset 
@persist DoorNormalPlace DoorOpenPlace Tog On Door:entity 

runOnTick(1)

#The two sounds

#Moving "doors/doormove7.wav"
#Stopping "doors/door_chainlink_close2.wav"

if(first()) {
    Door = entity():isWeldedTo()
    entity():setColor(vec(),0)
    
    DoorNormalPlace = round(Door:pos():y())
    DoorOpenPlace = DoorNormalPlace + 230
}

if(DmgClk & Dmger != owner()) {
    Reset = 1
    timer("ResetFinish", 500)
}

if(DmgClk & Dmger == owner()) {
    On = 1
    timer("Close", #[SECONDS]#10 * 1000)
    Reset = 1
}

if(In | On | Button) {
    if(Door:pos():y() < DoorOpenPlace) {
        Door:setPos(Door:pos() + vec(0, 1, 0))
    }
} else {
    if(Door:pos():y() > DoorNormalPlace) {
        Door:setPos(Door:pos() - vec(0, 1, 0))
    }
}

if(clk("ResetFinish")) {Reset = 0}
if(clk("Close")) {On = 0 Reset = 0}
