Aling Object to Surface (Old Script)

I found this demo file which is exactly what i need but the script is “old” and i’m new to this script section.
If anyone could fix it for me and others who have the same issue, it would be nice.
It’s only about 22 lines of code so for somebody who knows vectors and matrices it should be easy.