There are scripts that already do this. I suggest searching sites like
Hawkee mIRC.net mIRC Scripts for these scripts rather than making one of your own. Most (if not all) require the presence and use of one or more DLL's, so it's easier to get the scripts & DLL's all at once, than having to find them separately.
While some people will argue that 6.16 is the best, currently the only version available from the official download site is 6.17