@name NUKE
@inputs Detonate
@outputs Rdy
@persist Armed Det Vel CVel I Int Mx Lau
@persist [P]:array
@persist [E]:entity
@model models/sprops/misc/domes/size_1/dome_12x48.mdl

interval(10)

if(first())
{
    E = entity()
    E:setMaterial("phoenix_storms/bomb")
    
    runOnChat(1)
    
    Mx = 250
    setName("NUKE
Power: "+toString(Mx))
    timer("p",300)
}

if(Det & Rdy)
{
    if(changed(Det))
    {
        E:setColor(0,0,0,0)
        E:propFreeze(1)
    }
    
    local Min = 50
    local Max = 2000
    P[Int,entity]:setPos(E:pos()+vec(cos(random(-180,180))*random(Min,Max),sin(random(-180,180))*random(Min,Max),random(0,25)))
    P[Int,entity]:propBreak()
    
    if(Int<Mx)
    {
        Int++
    }
    else
    {
        selfDestruct()
    }
}
else
{
    Det = Detonate
    
    if(I==Mx)
    {
        if(changed(I))
        {
            print("Nuke ready")
        }
        Int = 1
        Rdy = 1
    }
    else
    {
        while(perf() & propCanCreate() & I<Mx)
        {
            I++
            P[I,entity] = propSpawn("models/props_phx/torpedo.mdl",E:pos()+vec(0,0,10000+I),1)
            P[I,entity]:propNotSolid(1)
            P[I,entity]:setColor(0,0,0,0)
            
        }
    }
    
    if(chatClk(owner()))
    {
        local LS = owner():lastSaid():lower()
        switch(LS)
        {
            case "-clr",
                hideChat(1)
                P:propDelete()
                selfDestruct()
            break
            
            case "-det",
                hideChat(1)
                Det = 1
        }
    }
    
    print(4, "(" + I + " / " + Mx + ")")
}

