Author Topic: Generic NPC Conversation Scripting  (Read 758 times)

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Generic NPC Conversation Scripting
« on: March 27, 2014, 06:53:13 pm »


               

I am working on a conversation script for generic NPCs. By generic I mean all the filler NPCs that farm the fields, drink in the taverns, work the regular jobs in your fantasy world. I am using z-dialog as the starting point, and then creating a generic conversation script which can be fed flavor text from local strings set on the creature.


 


Z-dialog script (without includes): v2_dlg_generic


 


Wyvern Crown of Cormyr (the premium module by DLA) did this a little bit. They had the right idea. And I think I've seen some PWs do this too. Sigil Planar Legends for example has particular types of NPCs - Touts, Guides, Gate Keepers, Merchants etc… that seem to each use variations on a typical conversation, but each is a little different (as if settings were adjusted). I think Escape from Undeath does this too, but I've forgotten. And I am sure there are many more that do things like this.


 


First, I am wondering if others are interested in sharing similar work in this vein?


 


Second, I'll share a little but of what I have done so far.


 


Conversation has five basic sections:


(1) If you have a weapon drawn on conversation start, NPC gives a response to the weapon, no greetings are given, and PC has an opportunity to:


  • THREATEN - opportunities for extorting, press ganging etc… uses intimidate skill

  • STOW WEAPON - attempt to smooth over the faux pas, and continue without weapon

  • CONTINUE CONVERSATON with WEAPON DRAWN - continue conversation, with potential to threaten with the weapon. NPC reaction will be negative.

(2) If PC is not currently speaking a language which the NPC speaks, PC has a chance to try other languages until they get it right, or otherwise fail to communicate.


(3) Greeting/Introductions. PC has a chance to introduce self if unknown, or if known provide a pleasant greeting to get things started.


(4) Continuing Conversation. PC is given a response showing reaction of NPC to them (this is basically a patience meter, that when it runs out, the NPC will try to end the convo), and NPC's response to the PCs prior convo option. A variety of options (depending on PC social skills and reputation) to seek information (stores, inns, jobs, quests, news etc…), ask the NPC to join party, convert the NPC to your religion and so on.


(5) NPC tries to end conversation. PC can say goodbye or if social skills are sufficient use one of them to keep the conversation going.


 


Thats it so far. I'm playing with more measurements than just "reputation", but not sure how complex I will get. I have ideas about how "fear" and "trust" could enter into this as values from 0-100 along with "reputation" which is the "how much they like you" measure. Another one I have considered is how well the PC is known.  Each of these metrics can be "personal" and "group" related.


 


Anyhow, just playing so far and am interested to see what others have done in this vein.



               
               

               
            

Legacy_Rolo Kipp

  • Hero Member
  • *****
  • Posts: 4349
  • Karma: +0/-0
Generic NPC Conversation Scripting
« Reply #1 on: March 27, 2014, 09:24:46 pm »


               

<continuing...>


 


I really like this. I like what you're doing and the direction it's taking you.


Now, understanding that you are keeping it (relatively) simple and prototypish...


 


I think it's quite worth considering breaking the stored metrics you use into two categories with multiple entries. Specifically, using Renown (or something) as the *weight* of a relationship vector and the value of the relationship axis (fear/attraction, trust/distrust, contempt/respect) as the direction of the vector.


 


Further, break the renown into multiple, additive parts: Racial, Class, Geographic. Hence a fellow from Helm's Deep is better known there and a fellow from Luskan less well known, but the reputation/relationship they've built is of the same vector/flavor. Likewise, a fighter NPC knows a fighter PC better than a cleric or mage NPC would. This allows for subtle shades of responses that are truly affected by they PCs actions and their character build.


 


As for how many, what kinds of axis to employ, you know I am really trying to develop a three-axis, 3 dimensional relationship model :-) A bit more complicated than what you want... <a *lot* more complicated>


...but it will be necessary for my vapor-ware socio-political engine that will generate emergant behaviors from NPCs. Hush bird. <as long as you don't call *me* an npc>


Wouldn't dream of it, old friend. <*skeptical raven look*>


 


<...from chat>



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Generic NPC Conversation Scripting
« Reply #2 on: March 28, 2014, 01:04:56 am »


               

I've been working on something like this for a while now.  It's in pretty good shape although I started a bit differently so it does not have some of the things yours does (like support for different languages and the drawn weapon thing, but I like those...).  


 


Most if not all of the text can be specified as variables on the NPC. There can be multiple pages of text for some entries which have [Continue] or "Go on..." for the PC. This specification includes the prompt the PC speaks. When not specified either something random is used or the option is not shown depending on the situation. It also drives my quest system and can open stores  or allow the PC to steal from the store. There's an option to start a sub dialog which can be configured (I use that for say an innkeeper to start the inn zdlg, or for a weaponsmith to repair weapons etc).


 


Anyway, I realized a while ago that this is the only way to go. Write a couple of moderately complicated dialogs and you've got 100 tiny scripts that are all the same except for one number or one word. Been working on it ever since. Fwiw, I used an earlier version of it my old ABC module.


 


It does not have the focus yours seems to on continuing social skills. That's an interesting thought.  There are some uses of skills and PRR plays some role, and there are some more that need to be added. You may have the whole thing collapse if you get too complicated. I was more focused on getting something I can use so I can make progress.  


 


One issue I see though is that this sort of thing is going to be pretty tightly coupled to a lot of other systems in the module (as are many of these things).  How you handle stores, quests, inns jobs news and what not will all be different in different modules.  I was just thinking of how I could share what I have with you and it gets to be a lot of stuff pretty fast '<img'>


               
               

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
Generic NPC Conversation Scripting
« Reply #3 on: March 28, 2014, 04:27:54 am »


               


(1) If you have a weapon drawn on conversation start, NPC gives a response to the weapon, no greetings are given, and PC has an opportunity to:




 


A thought to consider: unlike Mass Effect/WoW/Dragon Age/etc, NWN does not have the ability to have a weapon equipped but appear sheathed.  And there's a major difference between having a weapon in evidence (because a Greatsword is clearly going to be visible strapped across a person's back or whatever) and having it pointed at a person in a hostile manner.  NWN does not allow this distinction in terms of animations.


 


Which means you'd literally have to unequip the item (not sheath it, not hold it in an nonthreatening manner).  If it's something like a +1 sword, that's no big deal.  If it's a caster staff with a bonus spell slot or a primary casting stat?  That is a big deal because it messes up your spellbook.  If it's a paladin sword with a bonus to charisma?  That is a big deal because it lowers your Persuade/etc during conversation.  If it's something like the Black Rider Quill?  That is a big deal because it lowers your Lore during the conversation if there's a skill check.


 


So if you want something like that in a conversation then you'd also need to ensure that no weapons or shields have problematic properties.  And the idea of having to put your Greatsword into your backpack (somehow) because otherwise someone would feel threatened seems completely jarring given that fitting a Greatsword into a backpack makes no sense.  The whole of idea of inventory is an abstraction of gameplay and trying to make it "realistic" just seems to make it even MORE unrealistic.



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Generic NPC Conversation Scripting
« Reply #4 on: March 28, 2014, 02:06:43 pm »


               


Which means you'd literally have to unequip the item (not sheath it, not hold it in an nonthreatening manner).  If it's something like a +1 sword, that's no big deal.  If it's a caster staff with a bonus spell slot or a primary casting stat?  That is a big deal because it messes up your spellbook.  If it's a paladin sword with a bonus to charisma?  That is a big deal because it lowers your Persuade/etc during conversation.  If it's something like the Black Rider Quill?  That is a big deal because it lowers your Lore during the conversation if there's a skill check.




 


"You wouldn't part an old man from his walking stick would you?"


 


Equipped in NWN means in hand and ready to wield. Standing around in polite company with bared steal like the paladin sword example would take a lot of charisma bonus to get over the shear rudeness of it.  I suppose you could rescript all your items to provide the benefit if just in possession, but I'd argue that just having it in it's scabbard at your side should not give you the bonus. "Persuade" with a sword in hand is not really persuade anyway. Also for that example, do you think the charisma bonus of that sword is really for the conversational skill aspect of charisma or more the presence or leadership parts? if we're going to pick nits anyway '<img'>


 


I don't think having to sheath your sword to have a polite conversation is a problem, even if it means you can't maximize your stats.


               
               

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
Generic NPC Conversation Scripting
« Reply #5 on: March 28, 2014, 02:15:58 pm »


               


I don't think having to sheath your sword to have a polite conversation is a problem, even if it means you can't maximize your stats.




 


You missed my entire point which is that you CANNOT sheath your sword.  Because if putting your sword into your inventory is sheathing it then you're walking around with 20 swords and bows sheathed, which obviously makes no sense.  Every other game I have seen has equipped items sheathed while not in combat -- but they're still considered equipped.


 


And having to redo your spellbook and losing spells if you're "forced" to unequip (NOT sheath) is a big problem because you have to reinsert the proper spells and rest to get them back.  Curiously enough, the same modules that try to do stuff like this also tend to complain about people resting -- even when it's the module's own rules which force the caster to rest to fix a problem the module created in the first place.



               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Generic NPC Conversation Scripting
« Reply #6 on: March 28, 2014, 02:22:57 pm »


               

Alright folks, this conversation project is for a particular PW I am contributing to, so let the team and me worry about the details of equipment. In general MM, the problem you see of lost spell slots will never occur because (1) I am only including weapons in this. staffs, quills, shields are not weapons. and (2) I would never give a weapon an inappropriate property like a stat boost. Magical properties only further enhance what the item does rather than random other benefits to the aspects of the character you think might wield it.


 


As far as the issue of sheathing yet still having an item equipped goes, I just can't worry about such a detail given that the engine doesn't do such things. I could possibly script "sheathing", but until the graphic resources are available as VFX I'm not interested in pursuing it.


 


Meaglyn, in terms of comparing notes, I don't need to see your code (though I wouldn't mind taking a peek) as much as I am interested in hearing how your algorythm works.



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Generic NPC Conversation Scripting
« Reply #7 on: March 28, 2014, 03:28:29 pm »


               


You missed my entire point which is that you CANNOT sheath your sword.  Because if putting your sword into your inventory is sheathing it then you're walking around with 20 swords and bows sheathed, which obviously makes no sense.  Every other game I have seen has equipped items sheathed while not in combat -- but they're still considered equipped.


 


And having to redo your spellbook and losing spells if you're "forced" to unequip (NOT sheath) is a big problem because you have to reinsert the proper spells and rest to get them back.  Curiously enough, the same modules that try to do stuff like this also tend to complain about people resting -- even when it's the module's own rules which force the caster to rest to fix a problem the module created in the first place.




 


Um, you missed my entire point. I got your point. In NWN sheathing it _is_ unequipping it.  If that's a problem play WoW or some other game that has that state. Or put it in your quickslot if it makes you feel better. Then you can think of that one as sheathed and easily accessible and the other 19 as stowed.  (But if you're running around with 20 swords, one for each type of enemy that's a whole different "realism" issue).


 


Edit. Sorry that sounded more snide than I meant it. Don't go play WoW. I like having you around in the NWN world...


 


And my quote about not taking away the walking stick addressed the issue of staves and spell slots.



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Generic NPC Conversation Scripting
« Reply #8 on: March 28, 2014, 03:30:39 pm »


               

Meaglyn, in terms of comparing notes, I don't need to see your code (though I wouldn't mind taking a peek) as much as I am interested in hearing how your algorythm works.


 



 


Which part?


               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Generic NPC Conversation Scripting
« Reply #9 on: March 28, 2014, 04:51:03 pm »


               

Meaglyn, how do you initialize your NPC with the conversation text? I assume you use local variables, but how do you apply these. If you set them directly on the creature in the toolset, then you still need a separate blueprint each time.


 


One thing I have started to do is to propagate local data to the creature on spawn. One way to do this is to copy particular variables from the NESS spawn point to the spawned creature. This allows me to set the local variables in the toolset, but not on the blueprint itself. The advantage of this is that I can get a lot of variability with a single blueprint and yet still allow a builder in the toolset to achieve all of this (not require a scripter to achieve these ends).


 


And secondarily but related, I am interested in learning how you implement the random array of generic responses.


 


I am interested in more, but I suppose I could look at your ABC module to really dig into the details. In general I'd like to understand your approach to the various problems so as to inform my own.



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Generic NPC Conversation Scripting
« Reply #10 on: March 28, 2014, 05:43:20 pm »


               


Meaglyn, how do you initialize your NPC with the conversation text? I assume you use local variables, but how do you apply these. If you set them directly on the creature in the toolset, then you still need a separate blueprint each time.


 


One thing I have started to do is to propagate local data to the creature on spawn. One way to do this is to copy particular variables from the NESS spawn point to the spawned creature. This allows me to set the local variables in the toolset, but not on the blueprint itself. The advantage of this is that I can get a lot of variability with a single blueprint and yet still allow a builder in the toolset to achieve all of this (not require a scripter to achieve these ends).




 


Yes, that's one of the issues. I've actually gone one step farther than that recently.  I modified NESS to have a NT (New Tag) flag which is the tag to use for the spawned creature. I then have a NESS spawn script which can run code (either directly or executing an appropriate sub script) to configure the NPC based in its tag (or area and tag or whatever). This provides all the basic variables for the NPC, including store tag, all the dlg data, name, description, etc . And it can set heads, skin and hair color and give clothing as well so one blueprint for each race and gender. Important NPCs have their own of course, but all those named minor characters can just be scripted.


 


Quests, which also need a lot of information is done by a string variable that lists all the quests this NPC can offer in order. That variable is set using the generic NESS spawn code above. Then the conversation init routine calls questInitQuest(oPC, oNPC) to figure out which if any quest the NPC can offer this PC (or if already offered one need to use that one all the time etc). Then it puts all the info to drive the quest as needed.   PC's can only have one quest outstanding with a given NPC at a time. Quests are configured currently in two scripts. One that provides all the conditions needed to offer the quest and the other that provides all the quest details.  All of these are of course cleared when the conversation ends so the next PC to start a convo gets re-initialized correctly.


 


Rumor/news code is similar but a bit simpler. If the NPC does not have a quest to offer then a call is made to getRumor. If this finds something it will set the rumor text on the NPC. If not you get something like "No news is good news" or "I haven't heard anything new". etc


 


Some if it is still underway. Like I realized when I read your post that started this that I left of a quest condition relating to the NPCs current feelings about the PC. That will be needed.


 


And secondarily but related, I am interested in learning how you implement the random array of generic responses.

 


This is really just a collection of simple routines which all return string. Then they are just put in the zdlg script where needed.


 


This one gets the text for the PC option to ask the NPC about him or herself.



string dlgGetPCSelfTalk(object oPC) {
    switch (Random(4)) {
    case 0: return "Tell me about yourself.";
    case 1: return "What do you do around here?";
    case 2: return "What brings you here?";
    case 3: return "Who are you?";
    }
    return  "Tell me about yourself.";
}

Then in the main page of the dialog:



if(!PRR_GetPersistentInt(oPC, "PRR_" + PRR_GetTargetId(OBJECT_SELF) + "_DID_ASK_ABOUT_ME")) {
        AddStringElement(dlgGetPCSelfTalk(oPC), sPage, oPC);
        ReplaceIntElement(nIndex++, 1, sPage, oPC);
}

Similar is used for NPC lines when nothing specific is provided. Or he doesn't want to tell or whatever. That can be more or less complex depending on if you want to have reputation influence how he responds.  Just have to be a little careful about grammar so that the combinations that go together actually make sense. Sometimes that leads to slightly odd sentences.  There's always more that can be added to something like this...


               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Generic NPC Conversation Scripting
« Reply #11 on: March 28, 2014, 08:44:55 pm »


               

I modified NESS to have a NT (New Tag) flag which is the tag to use for the spawned creature.


That is a good idea, and I can't believe I hadn't thought of that. Allowing a spawn to have a custom tag is really useful.

I then have a NESS spawn script which can run code (either directly or executing an appropriate sub script) to configure the NPC based in its tag (or area and tag or whatever).


Interesting method. I end up in the same place, but by a different road. Yours seems like a good way to go about it.

My method is a bit more cumbersome as it requires a builder to know what various local variables do, and to make use of them. It seems like you provide a number of options for builders based on tag, and so builders just need to know the tags while the scripters do all the heavy lifting.

That said as a builder and a scripter I like making use of local variables directly on the NESS tag or creature. I just need to consider usability since this results in me doing most of the technical/fiddily stuff, and others just ignoring all the cool features.

With regards to conversation text however it seems to me that you'd want to specify unique lines for a creature rather than populate them based on tag.

In addition you indicated you had a system for a multiple page response. That is an interesting idea. How do you indicate when this is the case? And how do you key particular dialog like this to a particular PC "response"? Do you key NPC dialog text to PC options/responses?

Basically I am wondering how you establish topics that a NPC can talk about.

I am guessing that it could be done by creating a list of key words/responses that a PC can select, and then store under the same keyed label, the dialog text which the NPC speaks in response to the PC selecting that particular option. I imagine such an approach would be cool, but also flat because all those options would presumably be laid out in the beginning rather than gradually unveiled when conditions are met.

However if you have a state model for the NPC like I was talking about earlier tracking things like NPC interest in talking with the PC and this can be influenced by a combination of charisma, social skill use, reputation, and certain conversation options I suppose you could model a fairly interesting little mini-game of socializing with the undefined NPCs in the game even when the DM isn't around. I am trying to achieve a semblance of this without creating too much complexity. You'd set as a requirement certain thresholds of the NPCs state before they offer certain conversation options.

With regards to quests and news, I'm not sure if'll be setting up any generic NPC give those out, but it would be great to model what knowledge their group has (NPCs typically belong to a group - kinda like a faction) and enable them to dole out this knowledge. So that if a unique NPC in their group has a quest, any given NPC might know about it and direct the PC to talk with the special NPC. Likewise this would be done for merchants, inn keepers and various other NPC "types" that PCs are always looking for.
               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Generic NPC Conversation Scripting
« Reply #12 on: March 28, 2014, 11:56:40 pm »


               A stimulating discussion!


I take the point that since there are so many systems for influence, language, weapons and so on, a common approach is not so easy, but learning about other people's rules and techniques here is very helpful.


I like some NPCs to initiate conversation, too. I'm classifying clothing (e.g. rich / poor, drab  / attractive etc) and playing around with concealed weapons (sword-stick etc) because even a sheathed sword will attract attention if carried by a peasant.


It's possible to make lots of conversations with few scripts by using a standard set  (condition1, 2, 3... response1, 2, 3...) which pass control to master check and action scripts. I also find it useful to switch dialogue files in mid-conversation, between bespoke and commonplace chat, so that the logic only has to be done once. I'll definitely be borrowing some ideas here, though. Thanks for sharing.
               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Generic NPC Conversation Scripting
« Reply #13 on: March 29, 2014, 01:44:36 am »


               


That is a good idea, and I can't believe I hadn't thought of that. Allowing a spawn to have a custom tag is really useful.




 


I can probably cook up a patch easily enough if you want it.


 




That said as a builder and a scripter I like making use of local variables directly on the NESS tag or creature. I just need to consider usability since this results in me doing most of the technical/fiddily stuff, and others just ignoring all the cool features.


With regards to conversation text however it seems to me that you'd want to specify unique lines for a creature rather than populate them based on tag.




 


I started with a bunch of variables but since I'm both the builder and the scripter I just find it easier to put it in code. When I hit the same realization you did about needing blueprints for all the different ones I just went all the way to code. Plus then it takes a few lines in a script that may or may not run. Following Funky's wisdom from a different thread I started doing the same thing with all the area variables.  On enter checks for initialization of the area and does that first if needed. I can just scroll through or search one or two files and see that all the areas have the right setting for variable FOO.


 


As to the tags, my plan with this is for named minor characters, bar tenders, shop owners, smiths, each would generally be uniquely tagged. But if you have some other characteristic along with the tag you could easily code different actual words for different same tagged NPCs.  You can have most of it common and then just conditionalize part of it. I use several different NESS spawn script numbers.  You could do that. Same tag, different spawn script number, mostly the same code.


 


In addition you indicated you had a system for a multiple page response. That is an interesting idea. How do you indicate when this is the case? And how do you key particular dialog like this to a particular PC "response"? Do you key NPC dialog text to PC options/responses?

 


It's not an AI or anything. The multipage stuff is for cases where the PC has asked the NPC to tell him something and the NPC has agreed and is telling. Be it introduction, back story, some local flavor text, a quest etc. The PC responses are just [Continue] or "Go on...".   I should probably add an "okay, enough already" option.  Some of the text variables just support it and some don't. Most do. There's a generic zdlg page builder and handler for it which tracks the current page. Variables are like "dlg_back", "dlg_back1", "dlg_back2", it just goes until it gets "". (for some reason I did not want to have to type the 0 on the first one, don't ask).


 


 


For some of it like the flavor text and quest continuation information you can specify the PC text (or let it default to something if possible). Some of those PC text entries are required for it to make sense, some have a random selection of defaults. For the quest continuation info you can make the NPC require a bribe or persuasion or intimidation before saying anything or giving up the item or whatever.


 


You're giving me some food for thought...


               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Generic NPC Conversation Scripting
« Reply #14 on: March 29, 2014, 01:55:40 am »


               


It's possible to make lots of conversations with few scripts by using a standard set (condition1, 2, 3... response1, 2, 3...) which pass control to master check and action scripts. I also find it useful to switch dialogue files in mid-conversation, between bespoke and commonplace chat, so that the logic only has to be done once. I'll definitely be borrowing some ideas here, though. Thanks for sharing.




 


True enough. I have some of those helper scripts too. More important NPCs can need real TLC and a regular DLG.


 


As to the switching dialogs I use a subdlg system where you can specify another zdlg script or regular DLG file and appropriate PC text and if that is selected you go off to the new dialog. I use this for among other things my inn keeper, which is it's own fairly complicated zdlg. PC gets the option to say "I'd like to see about a room." or some such on the main page. Can't get back to the original conversation as easily, but I could probably fix that.


 


You can also set an override conversation which will always fire first until something marks it as done. This way you can have a more specific conversation on an NPC first and then have them settle into the generic one.


 


Always more to add though ...