It needs some slight modifications but this script works just fine in v17. Removing the water passability check (or simply changing it to its new name) fixes one issue, and PBTerrain is a module, not a class.
That being said, I would love it if someone made it so you can pass under the rails...