@name Snow
@persist S:array Height I X Y E:entity A Z Range SnowCount SpawnSpeed

if(first() | dupefinished())
{
    ######### SETTINGS #########
    Range = 100
    Height = 200
    SnowCount = 50
    SpawnSpeed = 100
    ######### SETTINGS #########
    
    runOnTick(1)
    A = 0
    E = entity()
}

if(A < SnowCount - 1)
{
    timer("spawn",SpawnSpeed)
}

if(clk("spawn"))
{
    X = random(E:pos():x() - Range,E:pos():x() + Range)
    Y = random(E:pos():y() - Range,E:pos():y() + Range)
    A++
    holoCreate(A)
    holoModel(A,"hqicosphere")
    holoScale(A,vec(0.2,0.2,0.2))
    holoPos(A,vec(X,Y,E:pos():z() + Height))
    S:pushEntity(holoEntity(A))
}

for(I = 1,S:count())
{
    Z = S[I,entity]:pos():z() - 1
    holoPos(I,vec(S[I,entity]:pos():x(),S[I,entity]:pos():y(),Z))
    if(Z < E:pos():z()) {holoPos(I,vec(S[I,entity]:pos():x(),S[I,entity]:pos():y(),E:pos():z() + Height))}
}
