Splitscreen Matchmaking

Options
You all know Halo, how up to four of your friends could all play online via one console. How the matchmaker could take your up to 4 friends and matchmake them into group of 16 or so. Can PUN do that? Take 1 "client" that has up to 4 "players" and matchmake that into a room that would be looking for 16 "players?"

Comments

  • DandS
    Options
    Hello

    The way to do it is explained here under Play with your friends > Matchmaking Slot Reservation

    At least that's how i did it, have a good day =D
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited November 2017
    Options
    Hi @TheAmbientBeard,

    Interesting question!

    Hi @DandS,

    Thank you for your contribution but could you give more details, and maybe share/promote your game here so we get a better idea and maybe add it to #madeWithPhoton showcase.

    The tricky part is how to represent a local player.
    Local/couch multiplayer (co-op/versus) is fun but maybe not so obvious.
    Especially if you want to combine it with "internet matchmaking/multiplayer".

    Related discussion (thanks to forum search with keywords "split screen"):
    http://forum.photonengine.com/discussion/6654/is-there-support-for-multiple-local-players
    http://forum.photonengine.com/discussion/6885/adding-a-local-player-to-the-server
  • DandS
    Options
    Hi @JohnTube

    Sorry for not being more specific, i didn't have time to write a long answer back then so i though i would at least give some pointers about my own solution.

    for now i'm making a 4 player game that you can play online, or offline on one machine, (typical party game with 4 players on one screen, overcooked/ smash bros, whatever, not sure if i can be specific) when playing offline, additionnal players can join the party by pressing start when the game is in the game mode selection menu (like in rocket league for example). This adds them to an array of 4 players with each entry corresponding to it's player number (so player 1 is in PlayerArray[0], player 2 is in PlayerArray[1] and so on)

    the players in my array contain various data like their name ( if this was a released game i guess it would be the Xbox Gamertag / PSN account name / Steam name, for now i use PhotonPlayer.UserID when playing online), their hardware controller number, and all the game specific data i would need to display in the game, like how many lives they have left, which character they selected, which skin and all that stuff.

    when the game starts i go through the PlayerArray and spawn a character for every entry in the array. Every character spawned this way gets a reference to their corresponding slot in the PlayerArray (which again stores their lives, a lot of their settings, and also the number of the controller they should get their input from) and that's it, local couch multiplayer.

    Now when i play online, i have this exact same array, the player creating a room gets assigned to the first slot, if he has a friend that joined in the menu before the creation of the room, that player gets the second slot just like in local ( they're still in local actually, they didn't join a room yet, even if they are connected to photon) and when i create the room, i check the array for all the occupied slots and for each players after the first i add the name of the first player to the expectedUsers parameter of CreateRoom (plus a number eventually, like in rocket league again, like the "main" player is DandS and then the other gets called DandsS[1] then [2] and so on, use a character that's forbidden in your taget platform's names instead the brackets, so that you now no player that's actually called DandS[1] will pop randomly in the game and ruin everything), this way the friends in local are occupying a slot in the room like any other networked player

    Then another player connects by calling JoinRoom, if he also has others players with him they will be added to the expected users for the matchmaking. On the master client with the OnPhotonPlayerConnected callback i assign that player to an empty slot in my array of players, and check the expected players list to see if there is other players with the same names( + a [x]), and if there is i also add them to another empty slot in my PlayerList, then i send that array to every player in the room for them to update it. when each client receives the array, they check the newly received array for their own names, check their local outdated array to get their hardware controller number and assign it to their slot in the new array (where the local player with joystick 1 can become the networked player number 3 in the array). then every player in the array that is not local is flagged as a non-local player.

    when the game starts i go through the PlayerArray and spawn a character for every entry in the array that is not flagged non-local. Every character spawned this way gets a reference to their corresponding slot in the PlayerArray (which again stores their lives, a lot of their settings, and also the number of the controller they should get their input from) and it works, for me at least.

    Sorry if this isn't clear enough, i know i'm not really good at explaining my work without actually showing it, i might have messed up in my explanations too (also as a french guy my english obviously sucks :) ), but i can't just dump the whole code here

    I hope this answers your questions, i can't promote the game for now as it is not released, sorry about that.

    also there's this thread on the subject from a while ago.
    http://forum.photonengine.com/discussion/comment/33417#Comment_33417

    Have fun =D
  • DandS
    DandS
    edited November 2017
    Options
    Hi again,

    i had to make a similar feature for the game i'm working on ( a 4 player party game, like overcooked, smash bros, that kind of stuff, not sure i can be specific yet)

    what i do is that all my players are referenced in an array of 4 PlayerData, which contains stuff like their name, their Hardware controller ID (from the Rewired plugin) and lots of other game specific stuff like the character they choose, the skins, the number of lives...

    When in the menu, each player after the first can press start to join the "party" (like in rocket league for example) and they get added to one of the 3 remaining empty slots of that array, then when the game starts, i go through that array and spawn a player character for each slot in the array that is taken, each character gets a reference to it's player slot in the array, and that's how the character knows which controller to get input from, how many lives it has left, what number he should display above his head, what name, whatever. that's for the local multiplayer part

    when playing online, i just have that array synchronized between the different clients (it never gets modified once the game starts except for when a character dies and its life count gets reduced so it's not expensive on the network) whenever a client joins a room, he looks into his PlayerData array for every additional player in his party, and for each of them adds the name of the first local player (which happens to be the PhotonPlayer.UserID of the client) to the expected users in the createRoom or joinRoom functions, with a number to differentiate them (like if the first "main" player is DandS, then it adds DandS[1], DandS[2] and so on to expected users)
    On the master client whenever a clientjoins the room ( OnPhotonPlayerConnected) I check the expected users property from the room to see how many names contain the name( the PhotonPlayer.UserID ) of the client who just joined, and I add that many players to the PlayerData array, then i send that array to the other clients so that they can update theirs.

    this way every player character in the game is referenced in the PlayerData array that exists and is synchronized accros all clients, then all i have to do is assign locally the correct hardware joystick to the correct player in that array for each characer in the game. I set every non-local player in the array to have no hardware so i'm sure they can't be controlled by a random local guy who would just come and plug his controller mid game, and everything works fine.

    when the game starts instead of spawning every player in the PlayerData array, i just spawn the local players with the photonNetwork.Instantiate method, this way everyone spawns their own characters.

    Sorry if my explanation isn't clear, i'm no good at explaining my code without showing it (also as a french guy my english obviously sucks :) ) and i can't throw my code on the internet just like that...

    Have fun =D
  • DandS
    Options
    something weird seems to have happened when i edited my post, making it disappear, so i rewrote it (kind of) and now the old post came back, sorry about that, the first one is better i think... don't know what happened really D=
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hey @DandS,

    Thank you for the write up (twice) and your time!
    Yes sometimes vanilla forum does such issue, it holds comments for moderation I think due to quick edit or long content, I'm not sure.

    Interesting solution.

    I hope it works well for you.