@name Detonation_Cord
@outputs Props:array PC
@persist [E EE]:entity Time Radius Plant
@model models/jaanus/wiretool/wiretool_detonator.mdl 
interval(1000)
if(first()){
    E=entity()
    EE=E:isWeldedTo()
    Time=5 # seconds
    Radius=800
    findInSphere(E:pos(),Radius)
    Props=findToArray()
    PC=Props:count()
    E:soundPlay(0,0,"weapons/c4/c4_plant.wav")
    Plant=1
}
if(Plant){
    timer("Boom",Time*1000)
    timer("Beep",1000)
    if(clk("Beep")){
        E:soundPlay(0,0,"weapons/c4/c4_beep1.wav")
    }
    if(clk("Boom")){
        E:soundPlay(0,0,"weapons/hegrenade/explode4.wav")
        soundVolume(0,200)
            EE:propBreak()
        for(I=1,PC){
            P=Props[I,entity]
            P:propGravity(0)
            P:deparent()
            #P:unWeld()
            P:propFreeze(0)
            P:applyForce((P:pos()-E:pos())*P:mass()*(Radius-P:pos():distance(E:pos())))
        }
        Plant=0
    }
}
else{
    
    timer("Delete",2000)
    if(clk("Delete")){
        for(I=1,PC){
            Props[I,entity]:propGravity(1)
            if(I==PC){selfDestruct()}
        }
        
    }
}
setName(ops():toString())

