• ### Popular Now

• 9
• 9
• 10
• 9
• 10

#### Archived

This topic is now archived and is closed to further replies.

# How to make NPC's "gossip"

This topic is 5545 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

##### Share on other sites
Ok,
Looking through the archives, I have found a couple of threads which bring up the idea of gossip and how it would improve RPG''s. Unfortunately, most of the posts are just blue-sky ideas which are well-nigh impossible to implement ("What if the NPC was a dwarf, so he thought killing elves was OK, but he didn''t like the PC, so he lied about it, and then since the PC didn''t understand dwarvush very well, it was further garbled...").

Being a staunch realist about my skills, I''m leaning toward having each possible fact live in a data structure (or database), and NPC''s will either have access to the data or not. At this point, they will report it truthfully. If I can get that to work, _then_ I''ll look at having biased NPC''s, "Chinese whispers" where the truth becomes muddled, etc.

I''m still curious as to what would be the most efficient way to build and store the "facts" themselves. Especially whether a big array (list in Python) would be faster or slower than some sort of database (in my case, I''d be using MySQL or Postgres). At some point, an NPC has to go from an event to a description of the event. Or maybe the events build gossip items themselves?

Opinions?

Thanks,
chris

##### Share on other sites
well I''m not an expert at this but =)
what I''d say is this build one centeral database with all the current gossip in it...maybe not as strings but say as structors like this

  struct sGossip{ DWORD ID; DWORD Subject; DWORD Verb; DWORD Noun;};

then for each thing in your game (or type say orc) asign an ID to you would then put this into Subject... then for the second game object put its id in noun say "HappyTown"... then you would have a list (enum) of verbs "at war" "raid" "killed" ect... for this example we''ll use "raid" so we have "orc raid HappyTown" then you could use a chatterbot (basicaly) to elaberate on this... then for passing info from one NPC to the next just have a list in each npc''s class/struct of DWORDs... then just pass a random ID or two when ever an npc gets with in say 5 feet... to generate new gossip... when ever an PC/NPC performs and action worthy of noting generate a new bit of gossip... then everyone with in visual/hearing range would get the new gossips ID in there lists... for clearing old gossip out ID say maybe expanding the NPC''s gossip list to include a Timestap for when they got it and maybe a decay rate... with each message having its own decay rate for each npc you could bias how long he will rember it and how likly he would tell you about it... O heh one more thing... put a reference counter in the sGossip struct... then for each NPC that knows about it increment it by one... for each npc that forgets decrament it... then when it reachs 0 remove it from the database....

anyways thats my two cents...

##### Share on other sites
Use a semantic network! read about them on google and implement one... I did in 20 min...

##### Share on other sites
the problem with this is processing it. to have ur idea work , you would need MANY ncp''s, so thay they can interact with each other and the player in a complex way. the problem with that is processing it - - it would be time consuming. not that that is a problem, but you would be doing lots of processing for the player, and doing mad processing for stuff the player may not even encounter might be a bad thing.
you need to work with assumptions, just make them very complex.

##### Share on other sites
quote:
Original post by EvilCrap
the problem with this is processing it... and doing mad processing for stuff the player may not even encounter might be a bad thing

for anyone that is not near the character, you could just update this every game "day" at midnight or something... for people within any given town, just scatter the gossip randomly... and NPCs who travel between towns (if they do) can carry their gossip list to a new town, where you can give it to a few random NPCs there (say, at the inn).

--- krez (krezisback@aol.com)

Edited by - krez on February 2, 2002 6:51:47 PM

##### Share on other sites
Yes Gollum, this idea has come up before... there have been several good threads discussing it so I suggest you persist in scouring the archives of this forum.

As a brief reminder to readers about one of the key issues in allowing NPC gossip, you need to consider how information disseminates throughout a collective of communicating agents. Essentially information flow is a diffusive process. I wrote a detailed post about this for a previous thread, so I''m not going to reiterate it in detail here.

Needless to say, you need to limit the temporal memory of NPCs so that they forget some things over time. If you do not, then eventually, everyone knows everything.

The best way to store information is in a central database. This central database works as a knowledge base where each NPC knows (has access to) only a (very) limited portion of the knowledge base. When NPCs converse, they share information so as to expand the overlap between their respective sections of the knowledge base. As NPCs forget things, their access to the KB shrinks.

If an NPC dies then their access to the KB is lost so access to certain pieces of knowledge may be lost. If a piece of information is vital to the game then an oracle could be used to ''plant'' the information in the world somewhere... perhaps a book, or an ancient scroll, or a message from the Gods?

As for how NPCs gather information, you could consider the following: 1) interaction with other NPCs; 2) interaction with the environment; and 3) divine insight! Ignoring the latter, the first is covered by conversation. The second is the most difficult because it implies that NPCs are able to observe their environment and make inferences about it. While this is possible, the computational load is too much for your average computer RPG. I would stick with (1) and (3) as sources of information. Use an oracle to tell NPCs things that you would expect them to know based on their locale and activities.

Finally, you need to consider ''why'' NPCs share information. While a butcher might be prepared to gossip with Mrs Finnigan about the strange death of Mr Obigal''s sheep, I doubt a Master Thief is going to go around freely telling people about the locations of strong-boxes in private homes.

Just food for thought.

Timkin

##### Share on other sites
Hi there,

first of all, great idea. I see a few major problems with this though.

1. An NPC''s knowledge should be limited to prevent NPC''s from becoming "super-knowledgable" after having played for a long time. An NPC could have six memories, for example, and if an NPC learns something new, he should forget his last memory.

2. All the events in the game which can be remembered by NPC''s would have to be clearly defined. They could be stored in a data structure, something like this:

Eventtype | Location | Cause | Interest

The orc raid on Happytown would then look like this:

Eventtype: Raid
Location: Happytown
Cause: Orcs
Interest: 50

Interest could be the probability of NPC''s sharing their information. Unless you want NPC''s to tell you something like this: "Raid, Happytown, Orcs!" The data structure should hold extra grammatical information, to make NPC''s tell their story in correct english.

##### Share on other sites
Whoops, just realized that most of what I said has already been posted. Sorry

##### Share on other sites
Hello all,
Gollum here. Sorry I haven''t replied to any of this; I''ve been sick.
Fist, let me say a couple of things. I''m a newbie as far as programming in C++ or any "deep" language; my area is databases. I''m trying to implement this in Python, so if possible, I''d like code suggestions to be as generalized as possible.
Secondly, I did go back and find a couple of great threads on this subject, which discussed many of my own ideas, and a lot more. Timkin was one of the main contributors.

Here''s what I have done so far:

1. Created a routine to fill a python dictionary (sort of like a hash table?) with gossip items. These are constructed (currently in a random fashion) from what I''m calling "tokens" (see my above post). This will eventually go into a database.

2. My NPC''s are each given two pieces of knowledge. The function could be changed to give more starting knowledge based on intelligence.

3. There is a routine to compare the two NPC''s knowledge lists (arrays for you C people) to see which ones are unique to one NPC, and trade one piece of knowledge to each other.

Very simple, but it works, and I always program incrementally. My next steps will be to have the knowledge transfer randomized a bit, and to only have it happen when the NPC''s run into each other (currently, they don''t live on a map or anything, though I have another prog with maps that I can put them into).

My main ideas now are these:

- The knowledge should be contained in a database. I''m going to have to learn how to interface Python with MySQL.

- I have read (and it makes sense) that if knowledge spreads too easily, it will reach an equilibrium, where everyone will know everything. Different solutions have been proposed for this. One is some sort of "decay function," which would implement memory loss. I have no idea how to write that. Ideas, Timkin? My current plan is pretty simple: Have facts classed in a couple of different ways. One classification will be the type of people who know certain facts. This will usually be by profession. For instance, a baker will never know that the MoorHaven theives'' guild is at 101 Evil Street. So, a baker can''t learn knowledge that is classed as "treacherous," or whatever. The second class would be whether a fact is forgettable or not. Some stuff would be universally unforgettable - no one will forget that a war happened, for instance. Other things will be unforgettable to certain individuals, because they happened locally, or to a member of their family, etc. Then, all of the stuff that _is_ forgettable will be ramdomly pruned every so often. Is that what you mean by decay, Timkin?

- The third point, and maybe most important, is the way I plan to have NPC''s get info from their environment. For the most part, I''m not going to have them do it actively. I''ll have certain types of events (wars, battles, NPC deaths, changes in the price/availability of goods) generate facts through a function. Then, a second function will look through the new facts and decide who gets them. Make sense? Of course, I am miles away from having a working world with events to generate these facts, but give me time ...

- And semantic nets. Guess I''ll hafta go learn ''bout them, too. But learning is what this is all about, after all. Any advice, Puzzler183? Could you post your first semantic network as an example?

Anway, if you guys are interested, espcially you Python people (though the code should be pretty readable by most anybody), I''ll post this once I have random encounters and slightly randomized knowledge transfer ...

Still wanting any ideas,
Gollum