You probably want to get onto your hardware supplier and ask them why they haven't implemented G31.
Unfortunately I don't think you can do what you want very elegantly. It's pretty easy to write a macro that will record your Z value when an input goes active but your problem is going to be in stopping Z during a programed move. The only way I can think of you doing this is to decrement Z by a small amount in a loop and break out of the loop when the input activates. It's not a good solution and that's why I think you should complain to your hardware vendor about their lack of G31 support.