Script people in a town area going to sleep at night?

This is probably a bit over-ambitious for my module, but in a certain town area it would have been cool if people were to disappear at night, go to sleep that is. I rembember that in the first The Witcher game they had some kind of system like that. I would guess it involves advanced scripting, or could one place a script on the OnHeartbeat of each creature, or maybe on the OnHeartbeat of the area itself to maybe remember where each creature was and then respawn them there when it’s morning again? If this is too complicated I will have to just ignore this, but maybe you guys here on the forums know of a way to do this?

The way I have it right now is that the creatures in this area are not spawned in every time you go there. My guess that would maybe make things easier, but I have them there already and quite a few of them walk a certain way (waypoint sets), so it would be good if I didn’t need to change that.

i haven’t done one of those but have heard about them …

I wouldna say it’s advanced, but time-consuming and detailed.

Basically place waypoints at doors, with each waypoint’s tag based on the tag of the NPCs. (Or you could just tell NPCs to find the nearest door, etc.) And OnHeartbeat, if dusk, tell them to all walk to a door and disappear. (Or just make them disappear from the area.) If not in conversation or combat.

You could do either scripthidden or an outright Destroy() i guess.

Possibly have them respawn inside their house-areas (if applicable).

Then OnHeartbeat, if dawn, reverse the process and get them to WalkWayPoints() again.

Perhaps use staggered times for despawn and respawn, so doesn’t look like 1984 or Metropolis,

 
like i say, it’s not particulary hard just tedious and intricate

i think @kamal has done it … he might have a library ready to go …

If I remember correctly (most probably from rjshae’s toolset guide), if NPC have a waypoint tagged “NW_HOME”, they’ll go there at night.

1 Like

Having used the NW_HOME waypoint in NWN1, my experience has been that the whole automated “go here at night” system is buggy as Hell. Maybe Obsidian fixed it in NWN2, but I wouldn’t hold my breath.

I’ve found it far more reliable to place NPCs into a holding area, then use a time check in the area’s OnEnter event to move them around to their daytime or nighttime stations (waypoints). This method allows you to use a custom OnHeartbeat event to define specific behavior based on which area the NPC is in.

You could check out Wulverheim, Shockwolf had system like that. When 6pm came around town people closed up shop and went to a room in the inn and bar and tavern keepers swapped, husbands came on duty and wives when to the room. The stores and government building locked their doors until 6am. He also has time piece you could buy to advance the time.

1 Like

My system is here: https://neverwintervault.org/project/nwn2/script/kamals-generic-commoner-ai

It’s based on Uncle FB’s system here: https://neverwintervault.org/project/nwn2/script/uncle-fbs-npc-control

Uncle FB’s is more powerful and what you want to use if you want to control specific npc like named npcs. Mine is more generic, it can deal with specific npcs to give them things like set animations easily (for a blacksmith for instance), but can’t do more advanced things like have them change areas.

3 Likes

CHeck out NPC Activities, though that might be more than your looking for. Acting Fenora has an expanded version of NPCA, but that’s for having a living village with schedules and behaviors.

PJ156 did this in his Tales from the Lake of Sorrows campaign. All of his towns and villages work this way.

1 Like

Thanks for all the replies. I’ll go through your different suggestions and see if I can find something that works for me.

Looking at Kamal’s system with his scripts there’s so much there that I won’t need, it’s hard to know what I can remove. I wish there was only one generic NPC heartbeat script, but here there are all these for different NPCs with different professions doing all sorts of different animations. Apart from that it seems to be a very neat system…
I think I’ll have to take a look at Lake of Sorrows campaign next and see if I can somehow figure out how it’s done there.

Edit: Hmm, maybe I’ve found something. The script sh_npc_activinc_simple might be what I need for my npcs. @kamal Do you know if this is what I’m looking for perhaps? A script that don’t do a lot of animations on the various NPCs in the town and just does the “go home” and “wake up” at the right time?

In kamal’s system it says like this:

“If you are using any generics with the “go home” behavior (the ones without 24 in the script name), you must mark any door you want them to “go home” to with the local int nCAIUseOK, and this must equal 1.”

How do I mark the door with this? Do I go to Variables under Properties and do it like this perhaps? Will this create a local int? I’ve never quite understood the Variables section…

markdoor

Edit: I mean, I know I could make a script with SetLocalInt, but then I wouldn’t know in which slot on the door to put that script…OnSpawn perhaps? So maybe he means to use the Variables section…Sorry if these are stupid questions, but I’ve never quite grasped this particular thing.
It seems like this is just as you would do a SetLocalInt when typing this into the Variables, since because when looking at the demo module it was used like that.

Edit 2: Another thing I’m not quite clear on…Does the doors available with this local int have to be openable or can they be static? Scratch that…I just found the answer in kamal’s PDF.

Tried with doing the variables thing on the doors and put the sh_npc_activinc_simple on every NPC’s heartbeat slot. When testing it ingame nothing happens. Maybe I need to place waypoints or something. It doesn’t seem that way though when I read the PDF.

Maybe I should just look at the Tales from the Lake of Sorrows campaign instead…

Edit: Ugh! Looking at Sheep and Stone it’s even more confusing exactly how it works there…

Edit 2: Ok, I just noticed why the sh_npc_activinc_simple doesn’t work. I didn’t realize this is just an include script. I have been trying to look at for instance sh_hbeat_generic_standardhb, as that seems to be the heartbeat script I think I’m after. However, when I tested and compiled it I get a weird error:
It says ERROR: PARSING VARIABLE LIST, and I don’t get that because what it complains about is this line: int DoOnce = GetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF));
and I can see no wrong with that.

Edit 3: I changed the function to int DoThisOnce = GetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF)); and then that worked. It didn’t compile however. Found an if statement that was followed by ; so I corrected that, then it compiled. Will try with this script on the NPCs now. I think that should work, at least I hope so.

Ugghh! That didn’t work either. Don’t know what I’m doing wrong.

The demo module and readme, should hopefully do it. The local int goes as a property on the doors. Iirc the doors can be static

I’ve already checked the demo module and that didn’t help. It must be something I’m missing…I guess…I will have to check again then.

There are 4 different types of waypoint to get your NPC to move around in a set pattern via the standard Bioware Waypoint system. WP_ , WN_ , POST_ , NIGHT_

Each waypoint has a prefix (as shown above) followed by the TAG of the NPC. So if your NPC had a tag of SMITH then the waypoint tags would be, WP_SMITH, WN_SMITH, POST_SMITH, NIGHT_SMITH

Ok, I tried running the demo module, and the characters with the sh_hbeat_generic_standardhb all behave like I want my characters in my module to behave. And they have that script on their heartbeat and the doors have the variable nCAIUseOK. It’s just the way I’ve done it in my module. I don’t understand why it doesn’t work then…

The demo module uses the x2_mod_def_load for OnModuleLoad and I use the…eh, ok, I use the same. Then that’s not it. I also noticed all kamal’s characters have the X2_L_SPAWN_USE_AMBIENT=1 and I only have that on some of my characters. Could that somehow have to do with anything? And I use custom NPCs in this area, although they all have the standard scripts, and I’ve placed the sh_hbeat_generic_standardhb on their OnHeartbeat slots, just as in the demo module. Gaah, I hate NWN2 sometimes!

Tried again now after baking and now it kind of works actually. Most of them go and sleep but a few of them won’t, but at least there’s progress now.

You need to copy NW_C2_DEFAULT9 and make our own version of it (very important). Remove comments (// ) before the “Set…” functions to activate // * them. All instruction to do it is in the NW_C2_DEFAULT9 script. So if you wish to have a smith that goes home at night (let say is name is Seb) you create in a house interior a wp call NIGHT_Seb, and the Smith call Seb will go there at night.

1 Like