@Loveboy help of course but I think no one will give you full code...
Tip: Try to use IsLookingAt() function. (or geteye() function. I don't know which is better in this case so I ask someone with experience btw)
Here is a great collection of useful functions/scripts - http://www.zeroy.com/script/