Jump to content

Multiplayer queue system for matchmaking


Recommended Posts

I'm building an mp game that needs to have some sort of a queue system (eg League of Legends, CSGO, Dota2...)

So my question is how to implement such ?

I mean the core concept (I'm not looking for done code, even though some code would be welcome)


I have created a lobby system where you can invite players and if they accept their id is put into the lobby array and the lobby id is returned to them on client side. So the problem now is when the lobby creator hits the start queue button... How to find other lobbies that combine 8 players (2 teams of 4) but leaves the premade players in the same team

Link to comment
Share on other sites

Hey, good to see some future multiplaying :P

You can create your lobbies as an array of length 2 : lobby[0] is team 1, lobby[1] is team 2 (4 players in each array).

// list of lobbies
var lobbies = [];

// new lobby
var lobby = [];
lobby[0] = [];
lobby[1] = [];

// When a player comes, put it in the correct team
lobby[0].push(id);  // team 1
or lobby[1].push(id);  // team 2

// When you're ready, search for another lobby to complete
// iterate over lobbies and look free space in team 1 and 2
for(var i=0; i<lobbies.length; i++) {
  var lobby = lobbies[i];
  if(myLobby[0].length <= (4 - lobby[0].length)
    && myLobby[1].length <= (4 - lobby[1].length) ) {
    // Match found !
    // mix your arrays here to make only one
    // and search again with this new array if there is free space

It's my first though about it, good luck with that :)


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...