Sunday, April 1, 2012

More on the commoner ai project

My wintertime funk has pretty much lifted, and so I'm spending much more time in the toolset. While I'm not working on Crimmor per se, I am working on functionality that I view as critical for it, my commoner ai system. It's at the stage of fixing bugs. Here's a link to my original blog post

How to build with it:
There are premade ipoint placeables for each time period of the day, there are 6 periods, that can be set via script for whatever hours you want. These ipoints are placed in the area, and contain the local variables for the actions, the percentage chance an npc will adopt a given action. The builder sets the chance.

There are premade waypoints for each action. To be placed where the builder wants an action to take place. If you place multiple of the same type, the npc will randomly choose which one to go to.

A heartbeat script: any npc using this system needs to run this heartbeat, but does not need any other customization. No local variables need to be assigned (scripts auto set local variables), no creature tags required.

That's it.

How it works:
The npc heartbeat sets it's initial activity by determining the time, and checking against the ipoint for that time period, selecting an activity based on the percent chance as stored on the ipoint. It also determines a slight offset to the time period that shifts the time period for that npc, so not all npcs will change activity at the same time. The npc then selects a random waypoint tagged for the chosen activity.

The npc moves to the waypoint, and carries out the activity it chose until the heartbeat determines a new time period has been entered. It then selects a new activity based on the ipoint for the new time period and the process starts over.

Activities have predefined scripts to determine them, so a builder does not have to. These are pulled from Uncle FB and Lugaid of the Red Stripes systems. There are approximately 70 activities defined (and more can be added by a builder), covering things like farming, sweeping, working a forge, sitting and drinking, playing the lute, etc.

Scripts automatically ensure the npc is appropriately equipped (and eventually appropriately dressed). An npc that goes from walking around to playing the lute automatically has one generated and equipped, the npc does not need to be pre-equipped. If the npc then decided to be a woodsman, the lute is unequipped and destroyed, and a handaxe is equipped.

Nifty notes:
If you use Apep's dynamic commoner (, like I am, you can have your commoners also automatically randomize their appearance, soundset, name, hair etc. on spawn. Use his included npcs, set the variables you want for his system on the blueprints, and change the blueprints to use my heartbeat. Viola, a town full of customized commoners carrying out randomized actions. Apep's system works, so it's just a matter of getting my ai working. Ideally, town ambiance has never been so easy.

I've also done some preliminary work on random pickpocket results (including failure and being caught) for generic npcs, similar to how Baldur's Gate had it, as a separate script for the OnInventoryDisturbed. That's a separate but related project. Status for that is built but not working. It's on my "would be nice to have" list. When I get that working at some point in the future, I will post a blog on that.

No comments:

Post a Comment