@name stack
@inputs 
@outputs 
@persist Aim:vector Pos:vector Grid [Crate Crate2]:entity Holding:entity Hold A B C On Speed Water_level Di Spawn_grid  X Y Ready
@trigger 
runOnTick(1)

findByModel("models/hunter/blocks/cube075x075x075.mdl")
if (first()) {
    holoCreate(1,entity():pos())
    holoColor(1,vec(1,255,1))
    holoModel(1,"models/holograms/cone.mdl")
    holoScale(1,vec(1,1,2))
    holoAlpha(1,255)
    Grid = 35
    Aim = entity():pos()
    Pos = (round(Aim/Grid)*Grid+vec(0,0,Grid/2))
    holoPos(1,Pos)
    holoCreate(2)
    holoMaterial(2,"models/shadertest/predator")
    holoColor(2,vec(255,255,255))
    holoScale(2,vec(50,50,0.1))
    holoAlpha(2,0)
    A=0
    B=0
    C=0
    It = owner()
    Water_level=0.2
    Di=100
    Hold=0   
    #0.001 easy
    #0.0025 normal
    #0.01 hard
    Speed=0.0001
    Ready=0
    Spawn_grid=8
    X=0
    Y=0
    holoPos(1,Pos)
    Crate=propSpawn("models/hunter/blocks/cube075x075x075.mdl",holoEntity(1):pos()+vec(0,0,20),1)
    Crate:setMaterial("phoenix_storms/cube")
    Crate2:setMaterial("models/props_wasteland/wood_fence01a")
    timer("spawn",2000)





if(Speed>0){timer("spawn",2000)}

}




if(clk("spawn")&Y<Spawn_grid){
    Crate2=propSpawn("models/hunter/blocks/cube075x075x075.mdl",holoEntity(1):pos()+vec(X*Grid,Y*Grid,sin(B*4)*5),ang(90*randint(1,4),90*randint(1,4),90*randint(1,4)),1)  
    Crate2:setMaterial("models/props_canal/rock_riverbed01a")
    Crate2:setColor(vec(1,255,1)*randint(70,100)/100)
    B+=1
    X+=1
   Crate2:soundPlay(1,1,"/items/ammocrate_open.wav")
   if(X>Spawn_grid){X=0 Y+=1}
    if(Y<Spawn_grid){
        timer("spawn",100)
    }else{
    Ready=1
    holoAlpha(2,255)
    soundPlay(1,5,"/vo/announcer_am_roundstart01.wav")
    A1=findToArray()
    holoEntity(2):soundPlay(4,0,"/offspringfling.mp3")
    B=0

    }    
}

if(Ready){

if(clk("count")){
timer("5",1500)
owner():soundPlay(7,1,"/vo/announcer_attention.wav")
}
if(clk("5")){
timer("4",1500)
owner():soundPlay(7,1,"/vo/announcer_ends_5sec.wav")
}
if(clk("4")){
timer("3",1500)
owner():soundPlay(7,1,"/vo/announcer_ends_4sec.wav")
}
if(clk("3")){
timer("2",1500)
owner():soundPlay(7,1,"/vo/announcer_ends_3sec.wav")
}
if(clk("2")){
timer("1",1500)
owner():soundPlay(7,1,"/vo/announcer_ends_2sec.wav")
}
if(clk("1")){
owner():soundPlay(7,1,"/vo/announcer_ends_1sec.wav")
timer("0",1500)
}
if(clk("0")){
B=1
owner():soundPlay(7,1,"/vo/announcer_am_teamscramble01.wav")
timer("Win",2500)
}

if(!Crate&On==0){On=1
    
        timer("count",75000)
    owner():soundPlay(1000,1000,"/frantic_factory_remix.mp3")
    }
if(On==1&B==1){
    Water_level+=Speed+(Speed/5)+(owner():pos():z()/4000)
}
Aim = owner():aimPos()
Pos = (round(Aim/Grid)*Grid+vec(0,0,Grid/2))
holoPos(1,Pos)
holoAng(1,(holoEntity(1):pos()-(owner():pos()+vec(0,0,70))):toAngle()+ang(-90,0,0))
if(A>0){A-=1}
if(owner():aimEntity()&A<1&Hold==0&owner():aimEntity():model()=="models/hunter/blocks/cube075x075x075.mdl"&owner():aimPos():distance(owner():pos())<Di&owner():keyAttack2()){
    owner():soundPlay(1,1,"/items/ammopickup.wav")
    A=50
    Hold=1
    owner():aimEntity():propDelete()   
}
if(A<1&Hold==1&owner():aimEntity()&owner():aimPos():distance(owner():pos())<Di&owner():keyAttack2()){
    owner():soundPlay(1,1,"/items/ammocrate_open.wav")
    A=50
    Hold=0
    Crate2=propSpawn("models/hunter/blocks/cube075x075x075.mdl",holoEntity(1):pos()+vec(0,0,0),ang(90*randint(1,4),90*randint(1,4),90*randint(1,4)),1)  
    Crate2:setMaterial("models/props_wasteland/wood_fence01a")
    Crate2:setColor(vec(255,255,255)*randint(70,100)/100)
}
holoPos(2,entity():pos()+vec((Spawn_grid/2)*Grid,(Spawn_grid/2)*Grid,Water_level))
if((owner():pos():z()+20)<holoEntity(2):pos():z()&On==1&!Crate){
    print("Game over.")
    concmd("say @slay "+owner():name())
    soundPlay(7,1,"/vo/announcer_dec_failure01.wav")
    A1=findToArray()
    for(I=1,A1:count()){
        E = A1[I,entity]  
        E:propBreak()
    }
    reset()  
}
if(owner():aimEntity()&owner():aimPos():distance(owner():pos())<Di){
      holoColor(1,vec(1,255,1))    
}else{
    holoColor(1,vec(255,1,1))
}
}
  A1=findToArray()
    for(I=1,A1:count()){
        E = A1[I,entity]  
        if((E:pos():z()+8)<holoEntity(2):pos():z()&randint(1,150)==1&E:isFrozen()){
        E:propFreeze(0)
        E:soundPlay(randint(10,20),1,"/ambient/water/rain_drip"+randint(1,4)+".wav")
        }
        if((E:pos():z()+15)<holoEntity(2):pos():z()&!E:isFrozen()){
        E:propDelete()
        }
    }


if(clk("Win")){
holoPos(2,entity():pos()+vec((Spawn_grid/2)*Grid,(Spawn_grid/2)*Grid,Water_level))
if((owner():pos():z()+20)<holoEntity(2):pos():z()&On==1&!Crate){
    print("You Win!")
soundPlay(7,1,"/vo/announcer_dec_success01.wav")   
    reset()  
A1=findToArray()
    for(I=1,A1:count()){
        E = A1[I,entity]  
        E:propBreak()
    }
    reset()  
}


#/vo/announcer_dec_success01.wav
soundPlay(7,1,"/vo/announcer_dec_success01.wav")
}


