Funny, I was working on yet another script like this. Only mine will be much better when it's finished
Just thought I'd mention that there is a command that will find the speed of an object, without manually finding the magnitude of the velocity vector. Its the: speed
object command.
Just thought I'd point that out. I figure it might make the script run just an eency weency bit faster, which might make a difference if you have a couple hundred units all firing off their weapons at the same time.