Author Topic: RE: Help - NPC won't return to start location  (Read 488 times)

Legacy_Pstemarie

  • Hero Member
  • *****
  • Posts: 4368
  • Karma: +0/-0
RE: Help - NPC won't return to start location
« on: November 30, 2014, 01:29:58 pm »


               

Here's the deal...I have an NPC smith that does the following:


  1. Starts in the CITY_AREA

  2.    
  3. If he's in the CITY_AREA and its Day or Dawn he does work at his forge

  4.    
  5. At dusk he goes to SMITHS_HOUSE - a different area

  6.    
  7. At Dawn and if in SMITHS_HOUSE he returns to the CITY_AREA

#1-3 work great. #4 doesn't happen unless the PC is in the same area as the smith when #4 triggers.


 


I am not using the POST_ and NIGHT_ waypoints because I was concerned they would interrupt his forging routine.


 


What do I need to do to get him to return to the CITY_AREA regardless of which area the PC is in? Does this scripting need to be added to the Module's OnHeartbeat event.


 


The script is attached


 



   Spoiler
   

 


 


The nCount variable is used to index a variable that is checked in the conversation. Eventually the NPC gets to a point where, if you linger in his house long enough he'll never speak to you again - just curse at you.



               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
RE: Help - NPC won't return to start location
« Reply #1 on: November 30, 2014, 02:26:31 pm »


               

OK, Pstemarie, here's the problem:


as you've discovered the AI scripts on an NPC do not execute unless the NPC is in the same area as the PCs.


 


So you need a script which executes independently. My solution to the problem was to execute the script in every area where the smith can appear. I used NESS spawn points to check the NPC's schedule and update the NPC's location. Alternatively the module heartbeat can work.



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
RE: Help - NPC won't return to start location
« Reply #2 on: November 30, 2014, 03:58:35 pm »


               

The scripts can run.  You need to set the AI level of the NPC higher if you want it to run its AI when there's no PC in the area. I believe setting it to LOW is actually enough.  Something like this in the spawn script: SetAILevel(OBJECT_SELF,AI_LEVEL_LOW);


 


This does have the effect of fixing the AI level to low rather than allowing the game to set it as needed (AI_LEVEL_DEFAULT). So I'd not recommend doing this for a creature you expect to have in combat. It works fine for ambient NPC although it is more efficient in a PW setting to just spawn the NPC in the right place when there are PCs around.

 



               
               

               
            

Legacy_Pstemarie

  • Hero Member
  • *****
  • Posts: 4368
  • Karma: +0/-0
RE: Help - NPC won't return to start location
« Reply #3 on: November 30, 2014, 05:19:04 pm »


               

OK got it to work, but not in the way proposed here by some helpful people. After reading the notes in the WalkWaypoints tutorial by TAD - posted here - I discovered to my delight that I could use the POST_ and NIGHT_ waypoints already coded in by Bioware.


 


Here's the final code I came up with...


 



   Spoiler
   


 


All that was required to make it work was a wypoint tagged "POST_NPC_SMITH" in the CITY_AREA to mark where he should be during the day and a waypoint tagged "NIGHT_NPC_SMITH" in the SMITH_HOUSE area to mark where he should be at night. Then I needed to activate the movement between areas behavior in the OnModuleLoad event - uncomment the line that reads


 


"SetModuleSwitch (MODULE_SWITCH_ENABLE_CROSSAREA_WALKWAYPOINTS, TRUE);"


 


AND tag the NPC smith with the appropriate behavior flag - I use a modified version of nw_c2_default9.nss (see below) that allows setting behavior by variables on the creature. Voila, he goes where he's supposed to. 


 



   Spoiler
   



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
RE: Help - NPC won't return to start location
« Reply #4 on: November 30, 2014, 06:48:44 pm »


               

It's been a while since I poked at that. But I'm surprised you still don't need the AI setting. On default AI level it will be set to VERY_LOW if there is no PC. At VERY_LOW the HB won't run so he won't come back once he leaves the area.  Are you sure you sat there in that one area all day (or night)? 


 


BTW if you are getting into making NPCs like this you might want to check out Nereng's ambient city. I don't know if it's moved over to the new vault yet. Also, as a shameless plug, my advanced waypoints system (see link in sig) would do this and allow you to specify the script to run when he arrives at each WP. 



               
               

               
            

Legacy_Pstemarie

  • Hero Member
  • *****
  • Posts: 4368
  • Karma: +0/-0
RE: Help - NPC won't return to start location
« Reply #5 on: November 30, 2014, 07:45:29 pm »


               


It's been a while since I poked at that. But I'm surprised you still don't need the AI setting. On default AI level it will be set to VERY_LOW if there is no PC. At VERY_LOW the HB won't run so he won't come back once he leaves the area.  Are you sure you sat there in that one area all day (or night)? 


 


BTW if you are getting into making NPCs like this you might want to check out Nereng's ambient city. I don't know if it's moved over to the new vault yet. Also, as a shameless plug, my advanced waypoints system (see link in sig) would do this and allow you to specify the script to run when he arrives at each WP. 




 


I'll have to look at those systems and see what I can do with them.


 


No, I didn't sit there all night and day. I used DebugMode to adjust the clock settings to see if he would actually move back forth across areas. I'll have to dig deeper, but if I recall correctly, when you toggle that switch any creature flagged to do that behavior gets its AI level adjusted.



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
RE: Help - NPC won't return to start location
« Reply #6 on: November 30, 2014, 08:46:13 pm »


               

I suspect advancing time like that causes the engine to fire all the HBs at least once. Since there are only the two WPs It would only need to run once to get him coming back.  Unless CROSSAREA_WALKWAYPOINTS effects the base engine all it does it control how the walkwaypoints code looks for waypoints (i.e. GetNearestObjectByTag or GetObjectBytag). 


 


I remember seeing oddness when testing AWW around advancing the clock, NPCs zipping across the screen, suddenly teleporting and being at sleep WPs without actually moving there etc. Not sure about this exact case because I usually set the time to right before the transition and wait a few minutes, and they already had AI level.


 


The ambient city stuff is basically a more complete realization of what BioWare started with the x2 ambient AI for populating cities. It really is pretty cool but is also very HB intensive. It's fairly script heavy. It's actually Ayath the Loafer and Nereng. But does not appear to be on the new vault yet. Probably because it starts with "x2"...


 


AWW is just an enhancement to walkwaypoints. One of the things it does is allows you to have more time based WPs than day and night. You could, for instance, have your guy work during the day and then spend his evening (dusk to 10, settable) at the local tavern and then head home for rest of night. Hammering on that anvil is thirsty work you know ...


               
               

               
            

Legacy_Pstemarie

  • Hero Member
  • *****
  • Posts: 4368
  • Karma: +0/-0
RE: Help - NPC won't return to start location
« Reply #7 on: December 01, 2014, 11:34:30 am »


               

Found the X2 Ambient System - aka Ambient City - by Ayath the Loafer and Nereng which was referenced above.