Author Topic: Ambient animations AI for cities?  (Read 655 times)

Legacy_virusman

  • Sr. Member
  • ****
  • Posts: 448
  • Karma: +0/-0
Ambient animations AI for cities?
« on: July 30, 2012, 03:47:53 pm »


               Has anyone tried making an AI system for NPCs in a multi-area city?
We have 5 exterior areas and numerous interiors, multiple points of interest: shops, taverns, etc. 'Ordinary' ambient anims look very inappropriate in this case: NPCs just randomly wander in a limited space in a single area.
My ideas were:
- Spawn: Generate NPC with random appearance, generate activity list (i.e. go to a tavern, spend 5 hrs there, then go to a local bazaar, spend 3 hrs there, then go to a random door and despawn).
- Pathfinding: built-in pathfinding causes NPCs to cut edges and walk near the building walls. People usually walk on the roads. My approach was to pre-configure the area by placing waypoints on intersections and linking them together with localvars. The pathfinding script then finds the best path to the destination and makes sure that NPC walks on the road.
- POI activity: Once an NPC reaches the POI, the AI control is handed over to the local AI script written specifically for this POI (tavern, shop, bazaar, etc.)
- Once the activity queue has been executed, the NPC despawns. The spawner script is then free to create another NPC with a different appearance and activities
- Resource saving: if there are no players in the area, the AI doesn't assgn any actions to the NPC, but still mantains the action queue and timers.

Has anyone tried doing something like this?
               
               

               


                     Modifié par virusman, 30 juillet 2012 - 02:50 .
                     
                  


            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Ambient animations AI for cities?
« Reply #1 on: July 30, 2012, 07:00:46 pm »


               I played with this idea, but then backed off. My thinking is that while it is useful to implement more interesting animations (Tom Banjo's social pheno has some good ones for example) and variability, I don't see much value in trying to recreate the scheduled wandering NPC of games like Ultima IV and V as it creates significant overhead merely for enhancing the background.

I think it is more interesting to make interesting special events that can happen in particular areas. Examples: A team of goblin miners in a cave. A roaming wolf pack in the woods that essentially patrols, howls, hunts etc... from point to point to point until it leaves the area. An itinerant peddler that shows up along certain roads based on the calendar. A party of roughs that arrive at an inn and start to cause trouble. An old adventurer who shows up at an inn and offers to sell information, give a quest etc....

The idea is to create special spawns that don't always happen, and can be configured to only happen to a particular PC once.

Implementation (which I have not fully worked out)
Insert a function call into OnAreaEnter which receives the PC object and the Area object.
This function has a percentage chance of occurring based on a local int set on the area
Function call draws upon two arrays set on the area. Indexes match so that these act like columns in a table. Array 1: is a list of script names. Array 2: is a string of event conditions like a NESS tag
Function goes down the list sequentially to determine if any of the events can occur, if an event occurs the event script is executed on the area.


I have not done this yet, but the above is my plan. At present I simply trigger events as the DM when it makes sense in game, and then after a particular session I have used an event I consider deleting the event script so that it doesn't get used again.
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Ambient animations AI for cities?
« Reply #2 on: July 30, 2012, 07:20:04 pm »


               also tried to make this, but abadoned it, i was able to make spawn and leave area in certain time, but failed with interactions, the npcs just wander around it doesnt look so live in the end...

Im currently destroying and respawning all npcs in area, but I have to manually make script for each are where I enter how many and which npc to spawn. So far not figured good way how to do that using local vars. Anyway considering switching to NWNX and using SetEventScript to none when there are no PCs.

So - if anyone have this done I would like to borrow the solution. Think I had long time ago NPC Actions 6.0? But then I abadoned it from some reason, not sure why now but it doesnt suited me I guess.

EDIT: henesua, what you are trying to do is better to do as DM, dm can spawn and controll npcs, with a bit support he can make all of what you are trying to make driven by script, so why to bother?
               
               

               


                     Modifié par ShaDoOoW, 30 juillet 2012 - 06:25 .
                     
                  


            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Ambient animations AI for cities?
« Reply #3 on: July 30, 2012, 07:23:14 pm »


               For what it's worth I looked at doing something like this too.

Initially I was going to use the NPC Activities scripts, but it seemed like a lot of work to specifically
plan out all the NPC activities. It seemed better to spend time on the plot and story relevant things.

I settled on a compromise approach, which was to re-work the X2 ambient city scripts from Nereng
to make them more user friendly (controlled by variables on the NPC instead of different scripts for each job etc).  And then I plan to have some collection of these ambients spawn randomly as needed in each area and use the commoner package (with some bugs fixed) to put in some random looking NPCs who a are walking to specific destinations. I think that combination of both of those should make a reasonably decent city scape without completely micro managing the whole thing.

I'll probably use NESS to spawn then in. It means a lot of resrefs. I wonder if there is good way to
randomize the appearance and clothing of NESS spawned creatures...

NPC activities; http://nwvault.ign.c....Detail&id=2483
X2 ambient city: http://nwvault.ign.c....Detail&id=2433
original commoner package :http://nwvault.ign.com/View.php?view=Scripts.Detail&id=310
               
               

               
            

Legacy_virusman

  • Sr. Member
  • ****
  • Posts: 448
  • Karma: +0/-0
Ambient animations AI for cities?
« Reply #4 on: July 30, 2012, 07:35:58 pm »


               We use something like this for appearance randomization. HeadCommoner and ColorHair are just case statements with lists of valid values. One NPC blueprint, 3 clothing blueprints and this script generate a variety of NPCs, without spawning too wild appearance combinations.
               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Ambient animations AI for cities?
« Reply #5 on: July 30, 2012, 09:55:12 pm »


               I'd been thinking of making a new WalkWayPoints script that included not just a post for where they sleep, but one for their meal and prayer times as well.

 There'd have to be ground triggers around chairs that the NPCs would only use at the right time of day for meals.  I use the same already on floor mats for NPCs that sleep in their stores.

 I'd just never settled on how I wanted to handle it.  It was either a variable for each hour, which would take a fair amount of time setting up, or one for each "event" expected through the day.

 Since it would have to be included before the AI level check to work, I kept putting it off.  On a large scale there's just too much potential lag there for my liking.
               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Ambient animations AI for cities?
« Reply #6 on: July 30, 2012, 10:06:43 pm »


               Virusman - thanks. That looks useful...

Failed.Bard, I think you could pretty much do all of that with the NPC Activities stuff.  Although you might lose some of the "free" ambient moving around.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Ambient animations AI for cities?
« Reply #7 on: July 30, 2012, 11:30:26 pm »


               

ShaDoOoW wrote...

EDIT: henesua, what you are trying to do is better to do as DM, dm can spawn and controll npcs, with a bit support he can make all of what you are trying to make driven by script, so why to bother?


I'm typically too busy as a DM to handle these sorts of things duirng the course of a game. So I prefer to prescript them and set them in motion during play while focusing my efforts elsewhere.

Another advantage of using scripts to control NPC actions is the speed at which you can make things happen. Its much more natural in the course of play rather than waiting for the DM to clumsily spawn creatures on the fly with the crappy DM client, and then set them in motion, let alone the painful struggle to control the motion of several NPCs all at the same time.

So for a hunting wolfpack, I find a combination of a sequence of walkwaypoints (which act as approximate home bases rather than as actual walkway points), random chance to howl at the moon, flocking behavior, and random walk all wrapped up together much more natural than a DM spawning a bunch of wolves and trying to control them as they move as a pack.

I've also prescripted ambushes and response behavior to alarms being raised. Much better by script rather than by DM.
               
               

               
            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Ambient animations AI for cities?
« Reply #8 on: July 31, 2012, 12:45:24 am »


               MemeticAI seemed like a good push in this direction, but it seems to have a lot of overhead and has been abandonware for quite a while. Even if you don't want the whole thing, you could steal a few of the ideas from it.

In particular, it has a pathfinding library that lets the builder place landmarks and link them with trails. When an NPC is told to go to a landmark, he looks for trails that will take him there and follows them, even across areas. It was broken in the latest package, but I managed to fix it up (only tested on intra-area navigation, though, so YMMV). If you're interested in the rest of the package, lemme know.
               
               

               
            

Legacy_OldTimeRadio

  • Hero Member
  • *****
  • Posts: 2307
  • Karma: +0/-0
Ambient animations AI for cities?
« Reply #9 on: July 31, 2012, 04:54:50 am »


               Just wanted to toss out this newer version of NPC Activities.  I haven't used it yet but I was a big fan of NPCA back in the day.  Nothing against NPC Activities, but Carcerian mentioned the one I was actually thiking of, Ultima NPC Scheduled Activities, below.
               
               

               


                     Modifié par OldTimeRadio, 31 juillet 2012 - 04:46 .
                     
                  


            

Legacy_Carcerian

  • Hero Member
  • *****
  • Posts: 1655
  • Karma: +0/-0
Ambient animations AI for cities?
« Reply #10 on: July 31, 2012, 05:17:32 am »


               Ken Demerest, (lead programmer on U7) wrote : Tseramed's NPC Puttering

You can also try : Ultima NPC Scheduled Activities (made for ultima time schedules, but works for any setting)

'Image

[Edit:] @ Radio: Thx, glad u liked it!
               
               

               


                     Modifié par Carcerian, 31 juillet 2012 - 08:47 .
                     
                  


            

Legacy__six

  • Hero Member
  • *****
  • Posts: 1436
  • Karma: +0/-0
Ambient animations AI for cities?
« Reply #11 on: July 31, 2012, 06:43:43 am »


               Warning: vaguely relating post about my own experience of implementing time-based NPC behaviour.

I've written a single-function version of this that handles a single day and night state for each NPC, but it wouldn't be too hard to implement the same for optional hourly events. It was actually rather easy to set up. I store a seperate night and day script filename to execute every heartbeat as a local variable on each npc using the system, allowing for more complex individual behaviour on NPCs if necessary. This script is only executed if the NPC is within a small radius of their target waypoint. Usually it's just an animation, an attack command etc.

For anyone who wants to attempt a similar system, I did learn two requirements to get cross-area AI working though (the hard way). Firstly, all NPCs must be set to AI_LEVEL_LOW or higher for as long as they are supposed to be moving between areas. They can be set back to DEFAULT when they arrive at their destination. If not they will require a PC present before they'll move, which is a serious problem if they are meant to be entering a player-filled area from a player-less area - ie if the player is waiting for an NPC questgiver to arrive at a location.

Secondly, for NPCs to correctly handle a MoveTo command in another area, the default area transition script needs to be modified to redirect NPCs to their target waypoint again. Otherwise they will wander to the location relative to their position in the previous area, which can cause very odd movement patterns. I store the target waypoint's tag as a local variable and redirect based on that.

Anyway, what I came up with in very raw form, to be called from hb or pseudo hb:
http://pastebin.com/7sZ7Ezrv

The only thing that'd need to change to get it to work with hours instead is the bit where the target waypoint tag is garnered.

Other general observation: if NPCs are moving around and animating differently, I think it's a good idea to find plot uses for this. For example a worker who will only hold a proper conversation with the player in the pub at night, or a merchant who tells you to get out if startled whilst sleeping.
               
               

               


                     Modifié par _six, 31 juillet 2012 - 05:50 .