Random NPC

Dr.Froth
Hey guys,

Do any of you know how to make an non-player character move randomly through a small area (six rooms or so).

I am interested in having the NPC move around and then to have a script execute when the NPC and the player are in the same room (whenever that occurs, if it occurs at all).

Any thoughts, code, or ideas would be appreciated.

Thanks,
Dr. Froth

Elexxorine
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.

Dr.Froth
Hey...that is great. Thanks for sharing that Elex...cool.

Elexxorine
No problem, it's a cool code. Only ask you put like a 'with thanks to Elex' in the game credits or similar. lol.

witch wyzwurd
I've got a similar idea coded out. If you want to view another block of code let me know.

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums