Stop particle velocity via treshold

hi, i am totaly new to MEL. i need to stop my particles to move after their speed falls under a certain tresholds, something like

if(velocity < threshold) {
velocity = 0;
}

now ... i really dont know where to put it, and how to actually script it, can anybody be so kind to tell me how i have to connect the script to my particles and what the code is going to look like? what I have so far doesnt work at all ... :frowning:
thankyou

Open expression editor and create expression that will control per-particle velocity. Note that velocity is stored as a vector, you need to calculate length of that vector in order to get actual speed of the particle.

$threshold = 1;
vector $v = particleShape1.velocity;
float $vAbs = sqrt ( $v.x * $v.x + $v.y * $v.y + $v.z * $v.z );

if( $vAbs < $threshold ){
particleShape1.velocity = <>;
}

thank you very much

slight optimize

if( mag(particleShape1.velocity)< $threshold ){
particleShape1.velocity = <>;
}

nice

and another,

if(particleShape1.velocity < $threshold )
{

particleShape1.velocity = << 0, 0, 0 >>;

}

though, it might actually make it slower than directly instructing.

velocity is a vector value < should not have anything to do with it but odes maya automaticaly convert it to magnitude? Oh vewll adding one mag is not all that much to do.