Khaikaa Posted February 18, 2018 Share Posted February 18, 2018 Hi guys, today I'll try to teach you how to make a minigame lobby. First of all, sorry about my bad english, also this is so far to be the perfect way to do this, feel free to share your opinion and help optimizing this system. I didn't added any picture yet because it took too long and I have to go to bed(because I'm dying lol) and maybe I made some mistakes. I'll check this again tomorrow and hope I'll add some pictures. If you find any mistake or if this don't work for you feel free to say it here and we'll fix the mistakes together.   http://www.ascensiongamedev.com/resources/filehost/c5373f4fa41a56220582e554e5eb8b41.mp4 http://www.ascensiongamedev.com/resources/filehost/c5373f4fa41a56220582e554e5eb8b41.mp4   How will this lobby work?  There will be a npc on the map which will offer us playing a 4 player's minigame. When we accept, a countdown will start. When the countdown finish, all ready players(1-4) will start the minigame.   What will we need to do this?  - A map event (the npc who will offer the minigame access) - 3 common events - A few switches and variables(both player & global)   ok, let's begin!   As I said before, we'll need some switches and variables. For this example we are using this ones:  Player variables  onLobby: This variable will store the lobby ID where the player is. 0 when no lobby. We use this as a variable instead of a switch because we may want adding more minigames in the future so we won't create hundreds of switches. leaderFromLobby: This variable will store the ID of the lobby we are leaders of. 0 when we are no leaders of any lobby. We use this as a variable instead of a switch for the same reason of the previous one.  Global switches  minigameIsReady: This switch will store the information about the availability of the minigame. If the minigame is ready to start, it's value will be true. minigameIsRunning: This switch will tell us if the minigame is currently running(so players will need to wait until minigame ends). minigameLobbySolving: This switch will tell us if we need to solve the minigame lobby(for example, when the lobby's leader leaves).  Global variables  minigameLobbyPlayers: This variable will store the number of players ready to play the minigame(i.e. players who accepted playing the minigame and are waiting until countdown ends). minigameLobbyCountdown: This variable will be used as a countdown and, when its value is equal to 0, the minigame will start. We create this variable with a default value equals to 45 (as we decided our countdown will last 45 seconds).   We now will create the map event. We need to define a few things:  This event should offer access to the minigame only when there are 4 or less players ready to play and when the previous minigame round has finished. Also, after asking to the player if he wanna play and his possitive response, we need to check again if there are less than 4 players ready. The first player who accepts playing the minigame will become the lobby's leader.   First of all, this event must tell us if the minigame is waiting for players or if it is currently running, so we create a conditional branch using the minigameIsRunning switch. If minigameIsRunning is true, we'll tell the player that he must wait and we'll end the event process. If minigameIsRunning is false, we'll go to the next step.   The next step is knowing if the player is already a ready player or not(because a ready player shouldn't be able to acces the lobby "twice" and a ready player may change his mind before minigame starts and want to leave the lobby). We create a new conditional branch which asks if our onLobby variable's value is equal to 0. If not, we create another conditional branch which asks if our onLobby variable's value is equal to 1. If true, we ask the player if he want to leave the lobby and, if he wants to, we change his onLobby variable's value to 0 and we substract 1 to the minigameLobbyPlayers. If false, the player is in another lobby, and as we don't want a player to be in 2 different lobbys at the same time, we denies him the access and finish the event.         As the minigame isn't running and we are ready to access this lobby, we now have to know if the lobby is full of waiting players or not. We create a new conditional branch using the minigameLobbyPlayers. If its value is greater than or equal to 4 we'll tell the player that the lobby is full and he must wait until one of the players leaves or until they finish playing the minigame. If its value is less than 4, we'll go to the next step.  We'll ask the player if he want to play our minigame using a show options block. If the player says no, then nothing will happen and the event will finish. If the player says yes, we'll need to check again if the lobby is full or not(because lobby could become full while the player decide if playing or not). If the lobby is not full, we'll go to the next step.        As the minigame isn't running and the lobby isn't full of players we now need to know if there is a lobby leader or not. We are creating a very simple lobby system, so we will asume that the first minigame's ready player is the leader. If a player becomes the lobby's leader and leaves, the lobby will be solved. So if we are the first lobby player, we'll become the leader. For doing this we'll create another conditional branch using, again, the minigameLobbyPlayers variable. If its value is equal to 0, then we'll set our onLobby and leaderFromLobby player's variables to 1(as 1 is the ID of our minigame. Also we need to add 1 to the minigameLobbyPlayers variable. Else, we'll only set our onLobby variable to 1 and we'll add 1 to the minigameLobbyPlayers variable.   The whole event should look like this:     (The cut code)   Ok, our map event is now ready.    The next step is creating our first common event. We'll name it MinigameCountdown.  We need to define it's trigger as autorun and edit its spawn conditions. It will spawn if our player variable leaderFromLobby is equal to 1(so it will start when someone becomes the lobby's leader). First of all we set the minigameCountdownVariable to 45(this is to prevent the countdown to start in a inadequate value). After this, we'll create a label called "loop"(we'll see why we do this later). Now, we create a conditional branch using the onLobby variable: if it is equal to 1, then that means that the leader is still on the lobby. If not, then the leader has left the lobby and we have to solve it.  If the leader is still on the lobby, we create another conditional branch. This one will ask if the minigameLobbyCountdown is greater than 0 or not. If it is, we substract 1 to that variable, wait 1000ms and go to the label "loop"(so we repeat this all until the countdown ends). If it is not greater than 0, then the countdown must finish and the minigame must start. For doing this, we set the minigameIsReady to true, wait 500ms and set the minigameIsReady to false again. Finally we set the leaderFromLobby variable to 0 so this event don't start running again.  Ok, but what could we do if the leader leaves the lobby before the countdown ends? Well, on the "else" statement of the conditional branch we created to check this, we set our minigameLobbySolving switch to true, wait 500ms and set it back to false again.       With this all, we check each second if the leader is still on the lobby. If he is, the countdown will end and the minigame will start. If not, the lobby will solve(so a new lobby can be created). As you can imagine this is not a strong enough system because if the leader disconnects the lobby may break and it may be necessary a manual restart.   Now we'll create our second common event. We'll name it StartingMinigame.  We need to define it's trigger as autorun and edit its spawn conditions. It will spawn if the minigameIsReady switch is true. The only thing we have to do is checking the players onLobby variable. If it is equal to 1, then they will teleport to the minigame map and start playing. Also, we'll set the minigameIsRunning switch to true. If not, we won't do anything. Don't forget to set the minigameIsRunning variable to false when the minigame ends!       Finally, we'll create our third and last common event. We'll name it LobbySolver.  We need to define it's trigger as autorun and edit its spawn conditions. It will spawn if the minigameLobbySolving switch is true. The only thing we have to do is checking the players onLobby variable. If it is equal to 1, then we set its value to 0(so we kick them all from the lobby).       If all of this is correct, the lobby should work properly. This is not the best way to do this, but is the way I do at the momment. Do you think there is something improvable? Was this usefull to you? I hope this help someone.  Good luck!   Xeno, Capivarinha, emptyaccount and 2 others 2 3 Link to comment Share on other sites More sharing options...
Khaikaa Posted February 20, 2018 Author Share Posted February 20, 2018 Updated the tutorial(fixed some mistakes) + added some screenshots & demonstration video. If you find some mistake feel free to say it and I'll fix it. Lancelot 1 Link to comment Share on other sites More sharing options...
emptyaccount Posted February 20, 2018 Share Posted February 20, 2018 Ooh this is great! thank you  Link to comment Share on other sites More sharing options...
Matho Posted August 1, 2018 Share Posted August 1, 2018 @Capivarinha, take a look at this tutorial. Â @Khaikaa, thank you for your contribution, it seems pretty nice, will test and edit this post. Capivarinha 1 Link to comment Share on other sites More sharing options...
Capivarinha Posted August 1, 2018 Share Posted August 1, 2018 3 minutes ago, Matho said: @Capivarinha, take a look at this tutorial. Â @Khaikaa, thank you for your contribution, it seems pretty nice, will test and edit this post. Thats nice, let's add a test version of it on ASN. Â @Khaikaa, thanks for contribuition, bro! Link to comment Share on other sites More sharing options...
Matho Posted August 8, 2018 Share Posted August 8, 2018 EDIT -- can't I delete my post? XD Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now