Here's something to get you started. I didn't try to test it. It assumes that each of your safe rooms has been an id with the word "safe" and a sequential number, i.e. safe1, safe2, safe3... , safe34, safe35.
If you've broken up your map into zones, you can put the variable @number_of_safe_rooms in the zone script section of map properties.
#ALIAS gosafe {
closest_room = ""
least_cost = 999999
#LOOP @number_of_safe_rooms {
safe_room = %concat("safe",%i)
this_path = %remove(".", %walk(@safe_room))
this_room = %roomnum
path_cost = 0
LOOP %len(@this_path) {
next_room = %roomlink(@this_room, %copy(@this_path, %i, 1))
path_cost = @path_cost + %roomcost(@next_room)
this_room = @next_room
#IF (@path_cost > @least_cost) {#ABORT}
}
#IF (@path_cost < @least_cost) {closest_room = @safe_room; least_cost = @path_cost}
}
#WALK @closest_room
}
Troubadour
(Win 98, Pentium III, 550 MHz)