How can I export the terrain as .hmp?

How can I export the terrain as .hmp?

Read the terrain heights using GetHeights, convert the resulting 2D float array to whatever format .hmp needs, then write the data to a file. You can use this script, which exports the terrain to an .obj file, as a starting point.