Do you mean to say move within a set area even if there are exits to outside this area?
I have a very nice code for NPC movement. If you give the NPC properties 'mm' (moving mob) and 'amm' (active mm), then you need to change nothong in my code. Also if the NPC has property 'attackable', it can't go into rooms with property 'safe' (so enemies don't walk into towns, etc). Here you go:
define procedure <mob_setup>
for each object in game {
if property <#quest.thing#; mm> and property
<#quest.thing#; amm> then {
do <mob_mover(#quest.thing#)>
}
}
end define
define procedure <mob_mover>
set string <directions[0]; up>
set string <directions[1]; north>
set string <directions[2]; northeast>
set string <directions[3]; east>
set string <directions[4]; southeast>
set string <directions[5]; down>
set string <directions[6]; south>
set string <directions[7]; southwest>
set string <directions[8]; west>
set string <directions[9]; northwest>
set numeric <dm; 0>
set string <loc; $parameter(1)$>
set string <loc; $locationof(#loc#)$>
set string <mm; $parameter(1)$>
if property <#mm#; attackable> then {
for <i; 0; 9> if property <#loc#; #directions[i]#> and not
property <$objectproperty(#loc#; #directions[i]#)$; safe> then {
inc <dm>
set string <xdirpos[dm]; #directions[i]#>
set string <xdirpla[dm]; $objectproperty(#loc#;
#directions[i]#)$>
set numeric <opposite; %i% + 5>
if ( %opposite% > 9 ) then dec <opposite; 10>
set string <xdiropp[dm]; #directions[opposite]#>
set string <pla; #xdiropp[dm]#>
set string <xdiropl[dm]; #loc#>
}
set numeric <dirc; $rand(1; %dm%)$>
set string <alias; #(mm):alias#>
for each object in <#loc#> if property <#quest.thing#;
netplayer> then {
msgto <#quest.thing#; |b$capfirst(#alias#)$|xb
moved #xdirpos[dirc]#.>
}
for each object in <#xdirpla[dirc]#> if property
<#quest.thing#; netplayer> then {
msgto <#quest.thing#; |b$capfirst(#alias#)$|xb
moved from the #xdiropp[dirc]#.>
}
move <#mm#; #xdirpla[dirc]#>
}
else {
for <i; 0; 9> if property <#loc#; #directions[i]#> then {
inc <dm>
set string <xdirpos[dm]; #directions[i]#>
set string <xdirpla[dm]; $objectproperty(#loc#;
#directions[i]#)$>
set numeric <opposite; %i% + 5>
if ( %opposite% > 9 ) then dec <opposite; 10>
set string <xdiropp[dm]; #directions[opposite]#>
set string <pla; #xdiropp[dm]#>
set string <xdiropl[dm]; #loc#>
}
set numeric <dirc; $rand(1; %dm%)$>
set string <alias; #(mm):alias#>
for each object in <#loc#> if property <#quest.thing#;
netplayer> then {
msgto <#quest.thing#; |b$capfirst(#alias#)$|xb
moved #xdirpos[dirc]#.>
}
for each object in <#xdirpla[dirc]#> if property
<#quest.thing#; netplayer> then {
msgto <#quest.thing#; |b$capfirst(#alias#)$|xb
moved from the #xdiropp[dirc]#.>
}
move <#mm#; #xdirpla[dirc]#>
}
end define
Have 'mob_setup' run from a timer or in the afterturn stuff, btw.