19.06.2015, 21:56
I posted something like that a long time ago: https://sampforum.blast.hk/showthread.php?tid=284296 . Feel free to use it. (it is not the most efficient method, it can be much shorter, but you can take some examples from it)