if you read what i said on my post Callumlord .. that was a script which I did for one of MY mirc bots,
Jethro_ has shown you one way to do it.. I have shown you a slightly different way of doing it,
both have the same end results. it just depends what sort you would rather have.. a simpler one like Jethro_'s which is neater and cleaner, or a more messier but slightly more advanced functionable version like mine.
all we have done is shown you different ways in which to acheive what you are after, so using the 2 .. you should be able to source a variant for yourself :)