Monday, April 9, 2012

A new feature for my commoner ai

As I was testing various activities for my commoner ai I realized that my "sleeping" commoners would get up and pick another activity at the time period change, meaning they wouldn't be asleep for a normal amount of time. I also realized there was no way for them to go home for the night (only sleep in the same area was allowed). So I've added a new activity and some new functionality that I'm currently working out bugs in. You can now give a "go home and sleep" activity and commoners will find and move to a random door in the area, play the "use" animation, and go script hidden for 9 hours (8+1 for breakfast). At their wake up time they unhide themselves and pick a new activity based on the time. Once that is working, I will add the code to force the activity for a sleep period to all the sleep activity functions, and add a sleep until morning and a sleep until evening function.

The go home and sleep functions will allow builders to have their streets empty out at night (or day if you want vampire commoners :) ). Since these are command to essentially "leave the area", I could see them being used to empty out a tavern at closing time or give a shop hours, with the timely player being able to see these transitions.

Another use case for the commoner ai would be for something like a tavern, have the patrons sit and eat during the day, and get up and dance or play instruments at night, automatically.

edit: it looks like I've solved my problem with npc's sometimes getting stuck at their old waypoint when they pick a new activity. Pesky bug solved! And now my npc's also are "sleeping" properly in their go home and sleep activity, so I can add the sleep period code to the other sleep activities.


  1. This sounds good, later on I will be taking advantage of this for a fishing village. I also like that fact that you recognize the importance of a good breakfast. Those NPCs will be ready for whatever the PC throws at them.

  2. I can hardly keep up with what you're saying. But I know for a fact, you're making progress. Please keep this up. All the hardwork you're putting into this are much appreciated, esp for us non-modders. -fredamora

  3. Hi Kamal,

    Setting up commoner AI does turn out a little more awkward than it first seems. I too had "sleep" issues with my characters, and you may recall the problems I have had with them "all going to the tavern" until I worked out the issue.

    However, I believe if one can achieve a relatively basic system, then the benfits to having the commoners act more real can add an element of gameplay as well as ambiance.

    Keep up the great work. :)