Champa Posted July 26, 2016 Share Posted July 26, 2016 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) EDIT: 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 Quote Link to comment Share on other sites More sharing options...
Boz Posted July 27, 2016 Share Posted July 27, 2016 Hey, good to see some future multiplaying 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] = []; lobbies.push(lobby); // 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.