Why don't you simply add a plain terrain at the height of the grid, and then use a trace with mouse_pos3d and mouse_dir3d like the example from the manual?

http://www.conitec.net/beta/mouse_pos3d.htm

As soon as the player places a Terrain, he wants to place the things at the height of the hills or valley anyway.