Check arbitrary NPC conditions

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
hidingso
Posts: 26
Joined: Sat Sep 25, 2021 2:07 pm

Check arbitrary NPC conditions

Post by hidingso »

Hi Tony, hope you are doing well!

I am currently working on my generic NPCs. That is, NPCs that hold no big purpose in the game besides making the world feel alive.

My NPCs patrol around and can have different states (crying, dancing, talking etc.).

Is there a simple way to simply check for the NPC state? I was going to write a custom sequencer script, but don't see it working since there is seemingly no method of sequencer scripts to return a value.

As I stated, these NPCs are really generic. I wouldn't want to assign a unique actor for each NPC I have roaming around.

Any tips on my situation?
User avatar
Tony Li
Posts: 22143
Joined: Thu Jul 18, 2013 1:27 pm

Re: Check arbitrary NPC conditions

Post by Tony Li »

Hi,

Write C# function(s) to check -- for example, a single GetNpcState() that returns a string ("crying", "dancing", etc.); or, if you prefer, multiple functions such as IsCrying(), IsDancing(), etc. Then register them with Lua and use them in dialogue entry nodes' Conditions fields.

More info:
Other notes for generic NPCs:
hidingso
Posts: 26
Joined: Sat Sep 25, 2021 2:07 pm

Re: Check arbitrary NPC conditions

Post by hidingso »

Hi and thanks for your reply.

Is there any other way to check the state besides the GetNPCState(string NpcName)? I believe I would have to pass some kind of argument to specify the NPC I am interested in. Or is there way to just call GetNPCState that would always target the current NPC I am talking to.

I am a bit worried about performance if I have lot's of gameobjects or NPCs roaming around.
User avatar
Tony Li
Posts: 22143
Joined: Thu Jul 18, 2013 1:27 pm

Re: Check arbitrary NPC conditions

Post by Tony Li »

You don't have to pass the NPC name. You can check DialogueManager.currentConversant to get a reference to the NPC. The call to GetNPCState() would be pretty fast. The built-in Lua implementation is written in C#, so there's no C++/C# barrier to cross (with associated overhead) or anything like that.

If you're running simultaneous conversations, you may have to adjust that approach slightly.
hidingso
Posts: 26
Joined: Sat Sep 25, 2021 2:07 pm

Re: Check arbitrary NPC conditions

Post by hidingso »

Tony Li wrote: Fri Sep 23, 2022 3:13 pm You can check DialogueManager.currentConversant to get a reference to the NPC.
This worked perfectly, thank you so much!
User avatar
Tony Li
Posts: 22143
Joined: Thu Jul 18, 2013 1:27 pm

Re: Check arbitrary NPC conditions

Post by Tony Li »

Glad to help!
Post Reply