Page 1 of 1

Multiplayer Dialogue

Posted: Thu Jan 15, 2015 4:31 am
by drod7425
I'm working on a multiplayer dialogue project. Four players (each with a different "role") will enter into a dialogue with one or more NPCs. The NPCs will ask each of them questions based upon their role (this is an educational project). Only the player with the corresponding role will be able to answer the question.



Tools I'm using:



Photon PUN

Dialogue System for Unity



I know Dialogue System for Unity was not really built for multiplayer, but I'm more wondering if it would be possible with this system to do what I'm looking to do. Some pointers on where I might start would be great, as well.



Thank you!

Multiplayer Dialogue

Posted: Thu Jan 15, 2015 9:06 am
by Tony Li
Hi,



The Dialogue System doesn't provide specific features to help with multiplayer, but it doesn't get in the way, either.



The UI subsystem is independent of the back-end data subsystem.



For the data part, define a variable named "Role" (for example) in your dialogue database. In the NPC dialogue entry that precedes the player responses, use the Script field to set Variable[Role] to a value that specifies which player should respond. For instance, if you number your players 1-4, you could make this a number variable and set it to 1, 2, 3, or 4 as appropriate.



The UI part is a little more complicated. The "Role" variable doesn't do anything by itself. But the UI can use it to determine which player gets the response menu. In code, you can check the value of "Role" by calling DialogueLua.GetVariable("Role").AsInt.



If you're running peer-to-peer, start the conversation on each node. Create a subclass of one of the standard dialogue UI classes, for example UnityDialogueUI if you're using legacy Unity GUI. Override the ShowResponses() method. Use the same base method (base.ShowResponses()) to set up the menu, but then enable or disable the menu buttons based on the value of Variable[Role]. Finally, add a network-aware method to your class, and set up the buttons to call it instead of calling OnClick(). This method should tell all of the nodes to call OnClick(response), where response is the response object associated with the button. You can read more about subclassing dialogue UIs here and here.



If you're running client/server and you intend to start the conversation on an authoritative server, consider making a custom dialogue UI. It just needs to implement a few simple methods such as ShowSubtitle() and ShowResponses(). ShowResponses() could tell one client to show an interactive menu and the others to show a grayed-out menu, perhaps with an additional message like "Waiting for Player X to choose a response." When the active player selects a response, it should tell the server to call:

SelectedResponseHandler(this, new SelectedResponseEventArgs(data as Response));

where data is the response object from the client.







I realize that's a lot of information. As you get deeper into implementation, please feel free to post here or email me directly at tony (at) pixelcrushers.com with any more questions you may have.

Multiplayer Dialogue

Posted: Thu Jan 15, 2015 9:41 am
by drod7425
Thank you for the very detailed reply! This will definitely get me going.