The first warning about ".m$pacporing4" is originated in line 312:
OnInit:
getmapxy(getd(".m$"+strnpcinfo(3)),getd(".x"+strnpcinfo(3)),getd(".y"+strnpcinfo(3)),1);
end;
As far as I could see, that var is there only to fill the args needed by getmapxy command. It has no use in the script, as .x and .y has with the proper npcs.
To fix it, just change the getd for the nex one:
getd(".m"+strnpcinfo(3)+"$")
I fix the indentation of the script, remove the menu commands and some gotos and change the set commands for direct assignation. I think it's a little bit more readeable now, here you have it:
I didn't check about the infinite loop warning.