Page 1 of 1

Check arbitrary NPC conditions

Posted: Fri Sep 23, 2022 8:46 am
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?

Re: Check arbitrary NPC conditions

Posted: Fri Sep 23, 2022 11:54 am
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:

Re: Check arbitrary NPC conditions

Posted: Fri Sep 23, 2022 1:45 pm
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.

Re: Check arbitrary NPC conditions

Posted: Fri Sep 23, 2022 3:13 pm
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.

Re: Check arbitrary NPC conditions

Posted: Sat Sep 24, 2022 3:00 am
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!

Re: Check arbitrary NPC conditions

Posted: Sat Sep 24, 2022 8:47 am
by Tony Li
Glad to help!