Back to index

The copyright situation for this article is unclear. It does not belong to the author of this site. Please see the copyright notice. If you have information about the copyright contact me!

Automating NPCs

by Zykes

How come you very rarely see an mud NPC leave the streets of to Go home and eat dinner? Is it so that Joe the farmer never gets hungry? No, I don't think so, I believe that it is mostly because the creator of the town didn't have time to make poor Joe smart enough to realize that he gets hungry every now and then. Now, if I, as a designer or coder would want Joe to Realize that he is hungry, what should I do?
American Gothic - Grant Wood

A nice stereotypical male farmer and a nice stereotypical female farmer.

There are many ways of handling this problem, and I would like to bring forth the "state machine", something I picked up on while learning to basics of regular computer game programming. Shortly It is about letting a NPC or an object having different "states". For example, most muds have two states For NPC's - either it is aggressive or its not. Lets say we expand this a little. To start with, lets make a set of NPC stereotypes. The stereotypes may be a bit different depending on where we want the NPC placed, for a village we might have types like FARMER or HORSE, while in a city we may want types Like MERCHANT or maybe GUARD.

For every stereotype we have we also have to make up a set of needs, so lets take the farmer stereotype as an example from now on. What needs does the farmer have? Well, first of all, he has to sleep, eat and drink to stay alive. And to eat and drink he has to work. Why? Well, if he wants something to eat he has to either kill one of cattle or maybe trade something he produces at his farm for food. So, lets keep it this simple, we have the following needs: Eat, Drink, Work and Sleep.

Ok, now we have a stereotype and a set of needs for that stereotype.. So, what should we do with it? And how do we know when Joe have to eat or sleep? We could always set a couple of variables to keep track of how hungry and sleepy he is, but is that really necessary? Why not use the clock to keep track of when he is supposed to do something? Supposedly the mud has a time handler that keeps track of the current time in the muds world. Now lets set this up in a neater way and see what we got.

FARMER (stereotype)

EAT (need that is activated at 07.00, 12.00 and 17.00)
DRINK (need that is activated 14.00 supposing he drinks while he eats too)
WORK (need that is activated after every meal he eats except the last one)
SLEEP (need that is activated after his last meal)

So, uhm.. now we have all this, but still there is something missing huh? Yes, there is something missing, what we need now are rules. Rules that will take place when a need is to be filled, like at 07.00 when he is hungry. Every rule is preferably represented by a function that handles what happens when he needs to fulfill one need. Like in eating the function would tell Joe to go eat and take care of this ( How it is handles is another article, maybe you just want to remove him from the room telling everyone there that Joe leaves for supper, or if you want a routing system that allows Joe to walk all the rooms to his home and there start a supper scene with his wife and all the kids ).

Now we have this:


TimeCheck - Need - Rule
TimeCheck - Need - Rule

Maybe an idea to work with, modify or use? If not, just forget that you read it and go on living your happy lives.