Using Love hate with the Dialogue System in Multiplayer Games

Announcements, support questions, and discussion for Love/Hate.
Post Reply
njyx
Posts: 4
Joined: Mon Aug 02, 2021 11:56 am

Using Love hate with the Dialogue System in Multiplayer Games

Post by njyx »

We have the asset for Unity and it's great but we've run into one scenario which we're not sure how to resolve. We have a couple of NPCs in one faction with Dialogues attached. In one of the conversations, we invoke ReportDeed(actorNameString, targetNameString, deedTag) which is then evaluated and raises Affinity with that faction (so far so good).

We also have multiple concurrent players in the game - they have distinct names and game object names. Each can engage in the above dialogues taking the role of the player.

The problem we have is that in the dialogue when we want to make the call ReportDeed(actorNameString, targetNameString, deedTag) we need to use the right actorNameString. (for arguments sake "PLayer1", "Player2", ...) so that the deed is associated with the right player.

Is there a way to dynamically recover the name of the GameObject in the dialogue node when calling the Lua? We see the conversation item data object and it has an ActorID but this looks like it is internal to the Dialogue system and doesn't have a back reference to the gameObject.

If anyone has any experience doing this, help would be appreciated!

Thanks!
Steve.

[PS: there is a very clumsy workaround in that one could have the same convo replicated for every player, but clearly that's a lot of overhead.]
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Using Love hate with the Dialogue System in Multiplayer Games

Post by Tony Li »

Hi Steve,

During a conversation, these 4 variables are defined:
  • Variable["Actor"] -- The display name of the conversation's current actor (i.e., the one that invoked the conversation).
  • Variable["Conversant"] -- The display name of the conversation's conversant.
  • Variable["ActorIndex"] -- The index of the conversation's actor in the Actor[] Lua table.
  • Variable["ConversantIndex"] -- The index of the conversation's conversant in the Actor[] Lua table.
If the actor's display name is the same as its Name field, then you can use Variable["Actor"]:

Code: Select all

ReportDeed(Variable["Actor"], ...
If it's different -- for example, if you've set the Display Name field or you're localizing to different languages -- then you can use the actor's Name field like this:

Code: Select all

ReportDeed(Actor[Variable["ActorIndex"].,Name, ...
Both of these solutions work best if your players have Dialogue Actor components. Otherwise their GameObject names should match their actor Name fields.
njyx
Posts: 4
Joined: Mon Aug 02, 2021 11:56 am

Re: Using Love hate with the Dialogue System in Multiplayer Games

Post by njyx »

Great, thanks for the quick response Tony, will try these - looks like they should do the trick thank you!
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Using Love hate with the Dialogue System in Multiplayer Games

Post by Tony Li »

Happy to help!
njyx
Posts: 4
Joined: Mon Aug 02, 2021 11:56 am

Re: Using Love hate with the Dialogue System in Multiplayer Games

Post by njyx »

Hi Tony, thanks again for the info here.

We tried this and the Variable["Actor"] version does return a result but strangely it's identical to the conversant of the dialogue and not the actor that initiated it. Also Variable["Actorindex"] returns nil to LUA. We have the actors in a list in the dialogue database and they are assigned for each dialogue. The dialogues work and flow as planned.(*)

(*)We see this in the call stack

Any idea what might be going wrong?

Thanks!
steve.
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Using Love hate with the Dialogue System in Multiplayer Games

Post by Tony Li »

Hi Steve,

The "ActorIndex" variable must use a capital 'I'.

It sounds like your actor is being used as the runtime conversation's conversant. The Character GameObject Assignment documentation might help shed light on the problem.
njyx
Posts: 4
Joined: Mon Aug 02, 2021 11:56 am

Re: Using Love hate with the Dialogue System in Multiplayer Games

Post by njyx »

Thanks for the ongoing support! Got it, checking this indeed it looks like we had the actors wrongly assigned in the dialogue component attached to the NPC so this now works and it's referencing the actor but we're still confused by the output.

It looks like Variable["Actor"] and Variable["ActorIndex"] both give us the name of the Actor in the conversation (in this case this is "Player"), but we're actually trying to get the Name of of the GameObject or something else unique. The reason is that multiple players can spawn in the game ("Player1", "Player2", ....) and anyone of them can trigger a dialogue. If they do though we want to know which GameObject it is so we can attach the love/hate deeds to the right one.

What happens without this is that the code searchers and returns the first of the players, which is not always the right one.

Is there a way to get the GameObject name or ID? "Persistent Data Name" in the Dialogue Actor component. Is that something that could be recovered since that might do the trick.

Thank you again,

steve.
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Using Love hate with the Dialogue System in Multiplayer Games

Post by Tony Li »

Hi Steve,

Here's an example scene (exported from Unity 2020):

DS_TestActorIndex_2021-08-05.unitypackage

In it, you can click buttons labeled "Player 1" and "Player 2". They each start the same conversation, but with two different actors:
  • Actor Name: Player, Display Name: First Player
  • Actor Name: Player2, Display Name: Second Player
I also used two differently-named GameObjects for the players -- P1 and P2 -- to demonstrate that all three things (Actor Name, Actor Display Name and GameObject name) can be different.

When you click a button, it will show the values of Variable["Actor"] and Variable["ActorIndex"]. For example, when you click the Player 2 button, it should display:

Actor: Second Player
ActorIndex: Player2

If it doesn't work correctly, please back up your project and update to the latest versions of Love/Hate and the Dialogue System to make sure we're both looking at the same thing.
Post Reply