Spawning the players + Match Countdown | 07 | Multiplayer Battle Royale | Tutorial | Unreal Engine 5

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys quick heads up before I start the video the link down below takes you to my patreon where you can download the project files for this video also get access to my premium tutorials and in-depth courses where we build games together from start to finish check out my patreon below gain direct access to years of experience so that you can start working on your dream game tomorrow hello everybody and welcome back to a new episode of my multiplayer Bean Battle Royale Series so in the last episode we set up this whole uh Island here so that's great but if we take a look at a typical Battle Royale then you would see water around the island but most of the times like in in a game like pubg so player own Battlegrounds you would see a separate Island and that is basically where the players spawn on then on that island you would basically have a have a have like a threshold so you need to have like 100 out of 100 players and when the 100 out of 100 players have connected to the session then a countdown starts of like 60 seconds then players can run around on that little island uh punch each other and after the 60 seconds the plane spawns in players will be in the plane fly over the island and start to drop in so uh that's what we're going to be working on in this video not on the actual plane and the players dropping in but we're going to put some water around the island to get a little separ island and we're going to get started on the match flow logic so that we actually have a count of how many players are in the session then when the minimum amount of required players are met so in pubg it's 100 out of 100 but here for testing purposes since I can only test with like two windows I'll say if two win if two players are in the session then we're basically going to start our 60 seconds countdown I'll make it into 15sec countdown and then basically we are ready to uh at that point start working on the events such as the plane actually coming in spawning in and things like that so uh let's go ahead and do that so we're going to click up here and then we're going to click on shapes plane drag the plane over here we're going to then set the skill to the plane of a to a very large number so let's do something like 4,000 by 4,000 and then we are going to reset here so we're going to reset the location so that it's in the middle so this is basically if I oh if I were to make this water then this is where all my water would be the little white Parts here so yeah now that we got the plane in here then I'm going to introduce you guys to my new water material so if we go over here to assets then we can click on materials and then water so so this is the new water material that I have set up for you guys so if you're interested in uh checking this out and download the project on patreon where you can get access to it so we're going to drag the water on the plane and that will give us some actual ocean over here so as we see we now have an ocean and then if we take a look in the landscape since some parts of the landscape are a little bit lower than others we also have some water entering into the landscape right now so over here we see some glitches appearing since the mesh is at location zero so what we're going to do is uh well we're going to change the mesh to be a little bit lower here we go set it to like minus 100 and that should fix these glitches so now we do have some nice natural water here inside of the landscape automatically and that's perfectly fine so we're going to keep it like that and then if we take a look over the edge then we see that we got our ocean water here but the landscape is not really touching with the ocean water so we're going to quickly go ahead and fix that by just simply putting the landscape a little bit lower but as we see we kind of reached the edge of the landscape already so what we're going to be doing is we're going to click here on the landscape tool go over to manage and then click on ADD and then we're going to add some more border around our uh landscape here so we're just going to drag out here now one strip over here put the camera speed higher and just go all the way around the island so there we go uh and then this one we're going to remove it so we're going to click delete on this one uh and then so this part here we basically going to drag this under the water and then we're going to smooth it out so that we get kind of like a coast uh or like a beach so that this actually goes into the water like that that will make sense in just a little bit and then what we need is that little separate Island where players will actually spawn in so we're going to make that over here on the left so to to make that we're going to need some landscape here to work with so something like this looks fine to me let's put this like this all right then next up we're going to go into the sculpting tool and we need to drag this underneath the water so to do that we're going to select the sculpt one and then we're simply going to hold shift and click to make it go lower like this and now once we are a little bit under the water then we can say that we use one setting called flatten to basically drag that lower level so this lower level water all the way flat all the way over here so now we can get this landscape underneath the water uh and now let's just go ahead and make sure that everything that needs to be underwater is put [Music] underw okay so now that we put most of that under water we kind of get to see what the point here is so we get our Island back again and it starts to make sense then we got this extra piece of land that will be the starting Island so we're going to sculpt this now so some shape like this would work for me then we're going to click on smooth and we're going to smooth out these edges a little bit to give it somewhat of a nice slope into the water like that and there we go so that gives us the little starting Island over here and we're going to smoothen out the edges of the actual Island all the way [Music] around all right so that gives us our beautiful island so this is going to be the actual B Royale Island and this is that little side Island so for little side Island we're going to give it a bit of a more natural look as well quickly and then we can continue from there [Music] and then we want somewhat of a flat terrain over here for the beans to actually have some normal play area to spawn on now we're going to quickly smoo that out a little bit there we go now the edges of this island I want them to be uh painted with a little bit of a kind of sand material I don't really have a sand material so we're going to be using a little bit of dirt so I'm going to be painting some dirt like this to kind of make a little Beach [Music] area now we're just going to make some starting area here for the [Music] beans there we go then uh now that we're finished painting it we're going to go over to the actual Island here and paint some beaches here as well so this little part I think it will be funny if we kind of have a peach here on this corner so we will leave this corner like that now we go back to this little island and give it some final trees and some [Music] rocks and there we go so now we got ourselves the little starting Island and the mainland so that's great now that we got that we can close all of our folders let's hit save all now we're going to be removing our player spawns that we had over here so we're going to select them all over here remove them and then we're going to head over to our starting Island here and this is from now on where we will be using the player response so we're going to put our camera speed back to four click here and then click on basic and then over here we're going to drag in some player starts so we're just going to be putting some random players respawns all across here so since it is a battle Roy we want plenty of them so here we go if we hit play We spawn at a random player spawn and that's it so now we're here at this little island so now that we got our spawning Island we're going to be working on some logic that we can actually get the game state to keep track of how many players are in the session then when that minimum amount of required players are met we then want to start counter and the counter is then going to be ready for us to install the event to spawn the airplane get all these players from that Island into the airplane and then give them the ability to drop out over the island so let's go ahead and set that up so for that we're going to click here on blueprints then we're going to go over to game mode and then we see our core game mode so this is the game mode that we will be using for the game playay and then since we uh also want to be able to test our game easily in the near future then we do not want our game mode to automatically keep checking all the time if we are actually at the minimum amount of players and from there on uh basically start the countdown and spawn Us in an airplane so we also need a game mode to actually keep testing so what we're going to do is that we're going to make another game mode class and then we're going to make a specific folder in which we code the classes for our game play and in that gameplay class we are actually going to be setting up this logic so to do that we're now going to be starting to creating some children off of these core classes here so um we need another class right now which is called the game State class now the game state is responsible for keeping track of the state of the game it is a replicated class that lives both on the server and on all clients so if we have replicated variables there then uh they can easily be read by all clients so variables such as score or if we run a replicate events down to all of the clients we can also easily do those types of things with the game State class so for example if somebody dies and we want to have a kill feed that says another player died and then the total amount of players that are still alive left um then those types of events can easily be handled by the game State since it can replicate down to all the individual clients so right here we're going to do right click and then we're going to go to all classes and type in game State and then we don't want the game State base but we want the actual game State class the game State base is intended better for single player and the game State class as it says over here behaves like a multiplayer match based game so this game State here is better suited for multiplayer so we go ahead and click select and call this BP uh GS which stands for gam State on for core hit save all and there we go so now that we got that we're going to make that sub folder that we're going to call gameplay so now we're going to be making child classes out of all of these core classes to be for our gameplay folder so we're going to right click and click on create child blueprint and then this character we're going to call it gameplay _ character and then the core game mode we're going to call it gamep playcore GM for game modes the game State we're going to call it BP um game State B we're going to call it BP gamepl GS for game State and then the player controller BP gam play player controller PC so these ones we're going to drag them into the game gameplay folder and there we go so why do we not want to code to functionality in here well like I explained then we would have that logic that would automatically start checking things counting down start executing events and we don't want that because we do want to have some type of a testing mode as well so when we're going to be working on the guns later we don't want to test that type of stuff here inside of the Battle Royale level or looting and loot grates and such so we do want to keep our separate testing level here where we will simply be using the core classes or perhaps we will start to make another folder called testing which we will then U make new child classes again specifically for testing in which we will not have these gameplay events installed so for now we're going to go back to the Battle Royale level and start coding our gameplay class here so we're going to go and open up the gameplay game States we're going to make it bigger and then next to the gameplay game State we're also going to open up the gameplay game mode so for those of you who don't know what a game mode is well a game mode is basically u a class that exists on the server only it is a class which defines your game mode so it contains all of the other classes here so that's why it's also separated from the other core classes so we got a game mode and the game mode determines the default Pond determines the hood class used but determines the player controller used the game State and the player State now do keep in mind the game mode only exists on the server so replication from the game mode down to the clients is not possible so you can only use server side logic here but the game state does exist on the server and on all of the clients so this one can be used to code replicated logic so why are we going to use the game mode right now well basically if we take a look over here under the functions and then click on override then we see some very useful functions that the game mode offers by default so for example we see this function called on poost login and we see a function called on poost post log out and if we Hoover over it it says notification that a player has successfully logged in and has been given a player controller so this event basically notifies that we get a new connection into our session and then the on log out event notifies us that a player is disconnecting besides that we got a couple of other handy events so we can use the game mode to also start a match and to end matches but for that we're going to be using custom logic now the game mode is also responsible for uh handling the starting of players and spawning players so the reason why you spawn automatically when you assign a character here and hit play is because that is by default installed inside of the game mode and it is handled by these types of functions such as find player start choose player start and spawn default Pawn 4 so these types of functions you can overwrite them to basically code your own custom logic in here or to use these by default but we're going to be using our own custom logic and when it comes to the spawning here then the the default uh class here that spawns on the island is perfectly fine for us so we're not going to need to adjust these functions over here so be sure that if you click these function and you're not going to use them then click them and remove them because otherwise you're going to be overwriting them um so what we need is when a player connects to our session this is fine that the player responds on this island like that and then getting the player into the airplane we cannot easily set that up using functions such as these ones so we're going to have to code that all ourselves but what we are going to use is that event on poost login so we're going to type in on poost login and we're also just going to quickly type in on log out to get the connection and disconnection so I'm going to right click it and um this we call it connecting player and this we call it disconnecting player so each time that a player is going to be connecting we basically want to send a little notification to our G state in which which we're going to be checking how many players there are and if that amount is equal to the minimum acquired remount to start a match so what we're going to do is we're going to create a variable inside of our game State here and we're going to call it minimum required players and then we're going to set that to be an integer hit compile on Save and we're going to set it to let's say two players now next up what we can do is since we know that the game mode exists on the server only we can easily basically cast to our game state to call events here so let's say that we call an event here and we call it check if ready to start so we could call this event here check if ready to start now from the game mode what we can do is that we can either type in get game State and then from the get game State we could cast specifically to the C uh cast to BP game play game State class so we can specifically cast to this class and then we can call the event that exists there so now if we drag off of here we can Tye and check if ready to start so we could do it like this or we could start using interfaces and interfaces are a lot easier to use a lot more friendly in my opinion because uh well it cleans up a lot of an unnecessary blueprint logic um and we don't have to start calling specific events here so if we're going to be using interfaces then we can more easily start to communicate so I'll show you what I mean by that by creating one so first of all inside of the blueprints folder here we're now going to be creating a new folder going to call it interface or let's call it actually interfaces and then we're going to right click here go to blueprint and then here we see blueprint interface so they can only be found here they cannot be found if you type in here interface uh so here you cannot find them so we're going to write click go to blueprint and then here click on blueprint interface and we're going to call this BPI game state so this is going to be our general game State interface so if we open this up then what does it give us well on the right here it gives us an overview of the functions that we're going to be coding in here and then on the left here we see a readon graph so interfaces are literally only intended to interface with other classes so we can simply send messages and data across or we can use it to retrieve data so we can either input data to send it through from one class to another or we can output data to retrieve data from one class to another but we cannot actually code in these classes themselves interfaces are simply just a form of communication so now that we made the the interface then we're going to be implementing it over here inside of the game state so we're going to click here on the game State remove this function click on class settings and then over here on the right we see that we currently have no interfaces installed inside of our BP gameplay game state so to change that now we're going to click on ADD and then we're going to type in the name of our interface called BPI game State and then we see that it's added we also see that the function appears here that exists inside of this interface and then we're going to hit compile and save so what type of function do we need here well we want the game play game mode to basically communicate an event to our game state that we notify when players connect and then when the game state gets these notifications the game State can each time uh execute a check to see if the amount of players that are in the session are greater or equal than the minimum amount of players if that check is indeed met then we can start the countdown event which will then later on in the next video hook into us actually being able to spawn inside of that airplane check out cact center right now stamen early exis it's a very fun multiplayer video game cheaper than the Starbucks coffee so if you want to have a good time with your friends or strangers click that link down below and I appreciate every single one of of you and enjoy the rest of the video [Music] bye so if we go back to our interface then we're going to rename this function to make it say notify player connection there's just going to be a notification that a new player has connected so inside of the game State we can now see that event over here and we can actually also categorize the events to keep better track of it so inside of the interface here we we can then basically go over here to category and then we could call this something like match flow so this is a function that we are going to use to basically control our match flow so now we're going to hit compile and save go back here again and we will see that it is now properly inside of this category then over here you can either right click and implement or you can simply double click it to get the event into the graph so how does this event then get called by our game mode well for that to occur we can simply go to our game mode and then we can simply type in the the name of the event or function so notify player connection so we're simply going to right click and type in notify player connection and then we see that there's a type message so that's what we need so we're going to click this and then we get our interface here and then what's the big difference between the casting and the interfaces well if I was to have a custom event here and call it do something and hit compile and save then what we see is that with a cast we basically need to get our object first so the object that we want to cast and communicate to is the game state so we're going to type in get game State and then we need to be specific about the game State class that we actually want to communicate to so for that we type in cast to BP gameplay game State now this is a very specific onetoone blueprint communication and then we get this uh pin out of here containing all of the data basically the reference of the the gameplay game state so out of here we can then type in do something and then what makes a cast easy well we can in this case simply double click and it takes us to that event with interfaces we cannot double click so if we double click this it will simply take us to the blueprint interface over here but we cannot actually see what the end point is so it will never take us to the actual location where we implemented it and that is because interfaces are one to many communication so whatever we plug in here as a Target is what it's going to be Comm communicating to and then when in our level we have installed our gameplay game State then when we call this function called get game State then it will automatically know that this is the game state that is active in the current level as we have set it up over here under the game mode settings and that is basically why it would then properly communicate so we can literally just get this get game State function and plug it into the Target and that's it so every time that someone somebody's going to connect we're going to basically get the game State and communicate the notify player connection event so now we're going to hit compile and save and then over here can remove this one and then we can run a little print string off of here that says hello uh or let's make it say player connected and there we go now we hit compile and save then if we go back here in the level then we see that we still have the core game mode selected so what we need now is the gameplay game mode and then for the gameplay game mode we're going to open it up and we're going to set it up to contain the correct classes so we can either do that here inside of the gameplay game mode if we click on class defaults and set them up over here or we can do it directly in the level here so we basically want to swap out the core character with the gameplay character then we're going to have the gameplay game State as the game State class and our gameplay player controller as the controller class we're then going to hit save so let's go ahead and give that ATT test test so if we hit play on the top left corner we then see that little print string firing player connected so then we're also going to quickly test it with two players as a listen server and we will see player connected and player connected so now we get two notifications that a player indeed has connected so now with that set up we can then start to code the rest of the functionality off of here inside of the game play game state so we're going to drag in our minimum required players and then we're also going to right click and we're going to be typing in Num players and then what this gives us is a default function uh with which we can basically see how many players are connected in the session so if we are to do a print string and then make it say 15 then we're going to plug this in here to see if it works so if I hit play with two players it will say one and then it will say two so now that we got that we can then basically just start to make our actual logic here and what that is is is is this greater or equal to the minimum amount of players if true we want to do something and that's something that we want to do is going to have to be communicated to the UI of all the players where we will have to start account down so now we need to go ahead and set up some UI so we're going to close these classes and keep the game ST open so for that we're going to go here to the widgets class and then inside of the game widget we're going to be creating a new widget which we're going to call Hood so we're going to call it WB uh let's call it gameplay _ Hood so that's going to be our headtop display and now we want to add this to the player screen as a full like canas widget so we're going to open up the panel put the canas in here and then when looking at a battle royale then we basically want a lot of unique elements inside of the UI here so on the bottom right here we would want something that shows us our current weapon and if we need to reload in the top left we might want to see our HP bar or here in the bottom and then uh for now we want like a counter up here that shows us how many players are in the session uh and then when the players are met we then basically want to see the countdown starting so for that we're going to make a separate blueprint and we're going to call it wbore player count and then we're going to make one more and we're going to call it wbore match start countdown so first of all we're going to be working on the player count here so we're going to open it up and it's simply going to be some text so we're going to drag in some text we're going to set this to be desired on screen so we can see the actual size of it and then we're going to scale it a little bit because 24 is pretty big so let's make it something like 18 and what we want this to say is something like one out of two players something like that would be fine now we're going to click on the text and give it a variable name so we're going to call it player amount _ text and set it to be a variable hit compile and save and go over to the graph okay so now that this is all done we basically need to set up the widget blueprint player count to actually update so the default value here I changed it to say Dash slash and then the minimum amount of required players uh so yeah let's go ahead and set that up so to set that up we basically need to go back to our game State and what we want to do here is that we want to set the number of player state to be a replicated variable so that the clients can read this value so what we're going to do here is that we're going to drag off of here click promote to variable and we're going to call this current amount of players then we're going to hook it up over here and we're going to set it to be replicated so then we hit compile and save and there we go so every time that we notify that we have another connection we're going to be basically pulling the amount of player States and we're going to be updating this replicated variable over here now of course players can also disconnect so when the players are on this island over here they can B basically be connecting but also disconnecting and we need to take that into account as well so what we're going to have to do inside of the gameplay game mode is that not only the event on post login event connects to this one but also the on log out so instead of making it like that we're just going to duplicate it over here so when a player logs out then we also want to send a notification and then we want that notification to also basically update this variable over here now we're not going to touch this logic just yet we're just going to make it so that the player count is not going to work so with this replicator variable here we can go over to the widget blueprint player count we're going to go over to his graph and then we can set up the logic over here so we're going to type in event con construct and then off of event construct we're going to type in get game State and we're going to cast to our EP gameplay game State and then we're going to have this widget save a reference to it so SBP gameplay game state is fine we're then going to hit compile and save and then we're just going to set it up very easily here so we're going to go over to the designer we're going to select our text and with the text selected we can then go over here to the text category and we can then see that there's an option to bind and then off of bind we see s blueprint game state which is the reference that we just set up and then out of here we can get a couple of things and one of those things is the current amount of players so if we click over here then we can basically bind this value to the current amount of players so what would it do right now well if we go ahead and hit play then we see that it says one and it says two so both on the server and on the client we now get that replicated variable but we don't want it to just say one and two we wanted to say that extra text that we wanted it to display as well so we're not going to Simply bind it like that but you could do that what we're going to do is that we're going to clear the binding so we're going to click on remove binding and then we're going to create our own little binding so we're going to click here click on create binding that gives us a function here which we're going to just clean up a little bit we're going to make it say get player amount text and then what we want this binding to do is we want it to get the blueprint game plate game State reference so the variable so we're going to right click it click convert to validated get so um basically what are we doing right now well we're binding this text here to basically uh the value from the game State and binding occurs on tick so because it occurs on tick we need to basically validate this variable why do we need to validate it well if we do not validate it and run this on take then it can also go off of not not valid so if we are going to drag uh so if we're going to drag values out of here and this variable is not valid that's going to cause us some errors and why is it not valid well on event construct it first needs to execute the cast so there can be a couple of ticks where we basically don't have this set as a valid reference yet because of that we will simply validate it we're then going to drag out of here and type in get current amount of players next up we're going to type in string append and then we're going to plug the string append into here and then we're going to basically uh format it the way that we want it so the current amount of players would go here now we're going to get it slash and then we're going to get the minimum of required amount of players so that's going to be two and then next to that two we're basically going to do space bar players then we're going to hook that is Val it up and there we go now off of the is not not valid we can also type in something there so if we copy paste the return Noe and do is not valid then we can simply type in slash two players so this way we know when it is not valid we can then hit compile and save and hit play and then we see one out of two players and two out of two players so now we got a proper replicated player count up there on the top right then instead of hardcoding this amount of uh minimum required amount of players we can also hook that up to be dynamic installed inside of the game state so let's do that so back to the game State here we can then click on the minimum required amount of players and we can set that to replicate as well and then back inside of our widget we can also get out the minimum amount of required players and we can hook that one up here so that everything is nice and dynamic and then for this text over here we're going to have to change the formal a little bit because we no longer know if it is exactly two so what we're just going to type in is a little n players in case we don't have a reference okay so there we go so now we have a proper player count widget we can un hit play test it once more so one player and then two out of two player so they both properly updates okay so now that we see the correct player amount then we need to start to code our final event which basically makes sure that when the minimum amount of players that that are required is met that we want to start the countdown to start getting these players over to the actual Island so to do that we are going to go into our uh Hood class first of all and then uh we previously made a little widget here called match start countdown so we need to add that here to the screen now so we click on browse on the hood it takes us to the correct folder and then here we see that widget I'm talking about so widget blueprint match start countdown so we're going to open this widget up and then what we need in here is just a little bit of text so we're going to drag in a text we're then going to set this widget to be desired on screen to see the actual size and then the text let's make it say something like uh 15 seconds now we don't want it to be this massive or actually well it is a countdown so it can be quite massive because it is pretty important so we're just going to keep it like that we're not going to give this variable name so we're going to call it countown text countdown _ text and promote that to variable hit compile and save and there we go now we need to add the match start countdown to the gameplay Hood widget to be here in the middle of the screen so if you go down to the user created category we then see our match start countown we drag it in we set size to content and then we anchor it to the top of the screen so hold control and shift to Anchor it to the top of the screen so we do control left click shift left click then on the Y let's put it 100 100 down and there we go so by default we don't want to see this time because now if I am to click Start then we immediately see the 15 seconds just standing there and that is not what we want so we basically want this countdown to be gone uh or we could have it say by default we could actually have it say something like waiting for players to connect so let's make it say that actually so back in the match start countdown we will just call it waiting for players dot do do so that's actually a good default text so by default everybody would then see waiting for players we then go to the Hut then we see that the widget hasn't updated here so that's a little weird on our engine bug so we remove it again and then anchor it to the top of our screen again then there we go so by default everybody sees waiting for players and then what we want to code is that if the minimum amount of players is met it starts a countdown so to do that first of all we need to go into the little widget here and click on the graph and we need to have a custom event which we will just call update widget and then we want to set the text for the countdown widget here so set text and that's basically it so that this will basically uh have some data coming through probably a number and then we're just going to be updating the widget here so to do that first of all we need to go to the game play game State here and then we need some kind of a variable that is our countdown so inside of the game State we're going to click on variables and let's just call it match start IND thecore countdown and it's going to be of the type integer now we hit compile and save uh and let's make the default variable here 15 so we want it to start at something like 15 and now we do want this to be a rep notify variable so what is a rep notify well a replicate variable as we know is a variable that basically sends data down to the client each time that there is an update so if you check your class default settings then you can see here that the game state is by default replicated and then here we see an update frequency so this game State updates 10 times per second so when we have a replicated variable it will uh attempt to 10 times per second send its data down to all of the clients uh and then there is another variable of a replicated variable which we call a rep notify variable now when we click that we see that a function gets created here uh and what is a rep notify well in in short a rep notify basically sends a notification whenever the value of the variable changes so in the case that this value on the server goes from 15 to 14 then an automatic uh function is also executed and that function is executed on both the server and on all the clients so we can now d double click the variable or we can double click the function here on the left that gets created and then we can start to code something here up to our choice when whenever we get that notification that this variable has changed its value uh and remember this executes on the server and on all of the clients so since the game State also exist on the clients then we can easily have some logic over there that would communicate on our client to our client site match start countdown widget and that's exactly what we're going to be doing here so uh basically whenever the minimum amount of players is met then we go off of the true here and we only want to do that once so we're going to have a do once here and then uh why do we want that to occur once well let's say that the minimum of required amount of players is equal to 10 uh then we basically just want to start the match countdown and keep it started so even if a player would then leave which would make it nine people in the session but uh then then then we already say we have already started started so we're just going to keep it at started so to fire this off where when the minimum amount of players is met then we're going to set this match start countdown to 15 let's do it like that so then we started to 15 so let's set our default value here to minus one and this will make sense in just a little bit uh and then we need a custom event in the graph here and we're going to call this countdown match uncore countdown and there we go so when we set the notify to 15 we want to have some codes so the code here is inside of the rep notify if it is equal to 15 then we basically want to start the timer event so the timer event is match countdown so when it is equal to 15 we start match countdown and then we want a match countdown event to take it over from there so the match countdown event in that case is going to get the current countdown it's going to subtract one so we're going to do minus one and then it's going to set the variable again and then we will run down the logic in a little bit and it will all make sense so uh basically yeah we're going to subtract one and then set it and then we're going to check if to see if it is equal to zero or not inside of the variable itself so what are we going to do well the minimum amount of players is met we set it to 15 that fires off the rep notify the rep notify then says hey I am equal to 15 CU look the default value is minus one so it changes to 15 it then says match start countdown we then start to decrease it by one that means that uh and then we set it again here so that means the rep node 5 fires again and at that point we're going to go off of hey it is not equal to 15 cuz right now it is 14 so here we're going to have to do a check to see if it is equal to zero so here we're going to say is equal to zero and then once it is equal to zero then we basically want to do something here so so once it is equal to zero we're going to basically start the event that the players need to go into the airplane and Spawn from the air so for that we're now going to use a print string and say uh started match and let's put that on our screen for let's say 15 seconds and we will make it green uh and at that point we also want to basically stop the whole countdown now if we haven't uh met zero yet then we want to basically continue the countdown so then we call the countdown event again so if we run through the logic once more we get the minimum amount of players met we start the countdown to 15 this starts the countdown makes it go to 14 that means it is no longer 15 no longer zero we go over here it becomes 13 Etc then eventually it hits zero and it says started match so there we go but now we need to get this match start countdown variable all the way into the widget here so each time it needs to update the widget so how are we going to do that well we're basically going to make ourselves a little function here and we're going to call it update uncore match start countdown widget and then inside of the function we're going to type in get all widgets class uh not only on the top level but just throughout the entire uh game then the widget that we want to get is our match start countdown widget now obviously each player only has one of these widgets so we can simply type in get and get the widget at index zero but uh we're just going to use it for each Loop now so we're going to for each Loop off of all of the found countdown widgets and then we're going to call that update widget event now what do we want to send uh to that widget here here we basically want to send the current timer uh value so we're going to make a variable here called Uh current time and that comes through here then we want to set it here so what we're going to do is string append we will then plug that in over here so the current time goes in here and then we just type seconds after it that's basically what we wanted to do then we hit compile and save and there we go now also here if the current time hits zero then we basically want to remove this entire widget so for that we're basically just going to go off of here and then we're going to say is equal to zero if that is false then we keep updating it if it is true then we're going to say remove from parent then we just want this widget to basically remove itself from the screen of the user okay so that's it for this logic then we want to go back inside of the game State uh then obviously here we need to add a 1 second delay in here because otherwise it's going to execute this all instantly so for us to have proper countdown we need to wait one second and then distract another one and update the variable then we wait one second again distract another one update the variable and then how do we actually update the widget well we made this function over here that will update the widget so in here we need to plug PL in our match start countdown just like that hit compile and save and then this function we need to properly set it up over here inside of the rep notify so if we open up the rep notify grab this function then basically each time that we do the match countown we want to call the update event here uh so the update event can actually be called each time like this so every time that the variable changes we just want to update the UI and there we go guys so that sums it up now we hit compile and save so then let's go ahead and test this all out so we're going to go and hit play and then we see the match countdown here so we see that the left the client is a little bit out of sync with the server here and how does that happen well be that's because the client and server both execute the countdown logic now so we don't want that so back here inside of the event graph we want to make sure that it's only the server who is responsible for setting this countdown logic CU otherwise these timers are going to be out of sync here so to do that we can go inside of the rep notify and then when we start the countdown here only the server needs to do it but the server also only needs to do all of this logic so basically the server needs to do all of this logic except for updating the widget because that we want to occur on the server and on all the clients so to make sure that the server only does this part we can then drag off of here inside of the rep notify and type in switch has Authority and that means that Authority is basically equal to server remote means client so we only want the server to execute this part and the clients are fine with updating so now if we hit play and we see connecting and then we see a timer that is perfectly in sync so there we go so we're counting down very excited cuz they're about to enter the Bale CU they are about to enter the Bale so two one and then in the top left corner we see that the server says started match and there we go guys so that's it for this video uh now we basically realized that we see a player count if the minimum amount of players are met we see that a countdown starts and then once the countdown starts then the server basically uh once it hits zero we see that the server says started match that is the event that we need for our next video in which we will then start the airplane to uh have the airplane fly over the island and then players will basically uh be able to jump out and start playing the Battle Royale now in the next episode we are going to be working on actually having that airplane spawning in and having the players flying out of that so that's going to be very excited uh I also seen a lot of comments asking when I'm going to actually connect it to steam so uh actually I might do that one episode before we start working on the airplane but we'll see I'll decide that tomorrow all right guys that's it for this video I hope you liked it if you want check out the project then be sure to download it on our patreon it's all available right there uh appreciate all of you guys and see you guys in the next one [Music] bye
Info
Channel: Kekdot
Views: 5,985
Rating: undefined out of 5
Keywords: Blueprints, Unreal Engine 5, Unreal Engine 4, Steam, Multiplayer, Game, Lobby, Game development, Unreal Engine, UE, Multiplayer game, Host game, Sessions, Advanced, Tutorial, Server browser, Online, Multiplayer Unreal, Replication, Replicated, MMO, Subsystem, Game Engine, Solution, Modular, Devlog, Listen server, Dedicated Server, GameMode, GameState, PlayerState, PlayerController, Widgets, RPC's, Player, Blueprint, Chat, Battle Royale, Shooter, Third person, First person, Loot, Spawn, Create, Find, Join, Destroy
Id: YqLrPEt_tms
Channel Id: undefined
Length: 47min 55sec (2875 seconds)
Published: Tue Oct 24 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.