Well, if you have a squad under your command, you can just select one of your men with the F1-F12 keys, and then it will show you the distance to wherever the mouse is pointed.
This Q has come up a few different times, I believe. Scripting-wise, it can't be done, short of using a weapon that is fired, and the distance to impact calculated. But there is no way, scriptingwise, of knowing where a player is pointing in 3 dimensions, other than having him fire something (like a gun or laser designator).
So it could be done, but it would require making an addon of some sort in addition to the script, or else settling for having the player fire a gun or his laser designator, and calling it a rangefinder.