Dealing Damage, Death, GameState Score | 12 | 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 guys welcome back to a new video for my multiplayer Bean Battle Royale tutorial Series so in the last episode we set up the health bar widget uh we actually created the whole widget we also corrected a couple of things so for example the counter on the top right whenever we now actually go ahead and enter the match instead of displaying two of two players it will then just display two survivors we also made sure that the characters are always relevant so that they can still see each other at Great distances so right now we see two survivors can then jump out and then the client can go over here like I said we also worked on the relevancies that they can still each other at Great distances so even if we were to let this airplane go all the way to the end here and then have this server Bean jump out we can still see the server Bean as you see right now you can also see him actually on the airplane so even though he's Way Beyond the 150 M curing distance we can still see the character which is important in the Battle Royale because you should be able to snipe players across this huge Maps so right now we're going to jump out and then if we do the parachute then very small you can still see me parachuting all the way off there in the distance so okay uh and then we basically set up the health bar widget uh which now displays 100 out of 100 health and then what we are going to be working on next in this video is making the actual logic so that characters can get damage so uh let's just get started right away so to do this first of all I want to make a little utility folder so we're going to click on blueprints new and let's call it utility uh and then inside of here we're going to be putting some uh we're going to be putting some actors with which we can easily test things such as for example the damage that we're going to be working on right now so inside of the utility folder we're going to right click make a blueprint class of the actor type and we're going to call this BP uh let's call it damaging or damage actor so this one is just going to be like a little Collis box that if the players run into it they will actually receive something damage so to do that we're going to open this guy up go to the event graph and then yeah let's leave that for what it is but also uh we see that if we hit play here that the game automatically starts unless we hit play test it with one player so in order to test we can either test here properly with one player and we would have all the time that we need before getting put into an airplane or we can also just go to the uh testing level that we had from a previous video and then inside of the testing level we can simply assign the core game mode here or we could also as I said in the first video as well we could also just make a specific uh child game mode so we could basically make new children and put that inside of a testing folder uh and that way we can basically make sure that the gameplay logic is not running so that we are not going to be spawned inside of an airplane but right now the core class is fine because all we need to use is the character here and then this core player controller let's see if that differentiates no so we do need to start using this player controller as this one already contains logic to set up our gameplay UI so we will actually uh right now here make a folder and call it testing this will be our testing game mode and we're going to make it a combination of this player controller this character this game mode this game state so first of all the core characters what we're going to be duplicating here let's call it BP test character and then we're going to drag it into the test folder now a core game mode we're going to duplicate that as well and let's just call it test GM and let's put this one into the testing folder as well this game state is what we want to use so we're going to call it test game State put it in here too but then for the player controller we do want to use the gameplay PC so this going to be the test PC CU that already creates our widgets that we want so now we're going to click save and there we go uh and then over here in the level we obviously need to assign the test game mode and then if we hit play we see that we have a character without any of the UI so how come well we set up the game mode here uh but we still need to obviously assign these classes to that game mode so right here we're going to select our test character this guy then for the game stage we're just going to drag it in like this and the player controller drag it in as well then if we hit play we see that we indeed still have all of the UI but that there's no thing like trying to spawn us inside of the airplane so that is fine now that we got this we're going to be working on that utility actor that can damage us so in here we're going to click on The View boort click on ADD and get ourselves a call box so here we go then by default if you drag this into the world like this then if you hit play you won't be able to see it so if you now hit play let's put it full screen then we don't see it but for testing purposes we do want to have this one be visible so with the Box selected we can set hidden in game off so that we can see it in the game and we can also adjust the line thickness to let's say two so that it's better visible basically and then the default skill let's set that to something like two as well cuz it was a pretty small box right now now what we want this box to do is that we can actually make it the default scene route H compile and save and then with the Box selected we can scroll down here and we will see a couple of events so so the first event that we want to use here is on begin overlap so what do we want to do on overlap well we want to damage the actor that is overlapping so basically on engine already has a function for that so if you right click here we can type in apply damage and there we go and then we see that this only runs on the server that's what this actor uh that's what this icon here specifies so what we're going to do to ensure that it only runs on the server and that we won't be wasting logic is that we're just drag out of here type in switch Authority switch has Authority and then plug this one in here so what do we do right now if um if something overlaps then this volume will just try to damage it um and it we only need to do that on the server so on the client these boxes will also exist inside of the world and the client will also be able to see these boxes but we only want the server to actually deal that damage so on the server we're going to actually do something with it and what are we going to do the other actor is going to be the actor that will be damaged and then the damage amount we're going to drag off here promoted to variable and let's just call this damage amount and then if we hit the little I here then we can adjust this in the world so if we then do compile save set the default damage of let's say 10 then there we go now the damage instigator we could say hook up like an instigator here uh but we don't need to set that up for this and the damage caer is going to be our self so this is the actor that that does the C damage basically so now that we do that we basically made this actor so that it can apply damage to any other actor that would imple implement the damage events so how do we implement the damage event so that our character can actually start to respond to that well if we then head over to the core character here uh so anywhere here in the graph we can just right click and type in damage and then if you scroll up you'll see the these damage events so we want the event any damage and this is basically the response event then as we see yet again that executes only on the server so that's why the server icon is there so this will run on the server and not on any client so if you want to basically replicate this down to the clients then you you're going to have to use replication or you're going to have to use multicast events or running on on the owning client so if you want to do like sound effects so let's say your bean get shot and starts to do a sound effect that it sounds like it's hurt then basically you're going to have to multicast that Alpha since we are on the server right now so what do we have now the damaging actor if we walk into it it damages with an amount let's say 10 but then here in the world I can select the damaging actor and set this damage to be way higher so like 20 or 25 I see that the lines are still a little bit thin so if we select this guy let's just make it like four and then make the default let's make it five because it's pretty PR small box right now there we go that's a bit better easier to work with so yeah this guy sends the damage through using this default ARR event and then here the damage comes true so any actor that you would implement this event on can in that case then get damaged so it will automatically interface to any actor and not to and it does that by basically plugging in this over here so even if you would have like uh let's say a squirrel NPC squirrel running around in your game uh running around in your game then if the squirrel would be the other actor would just be plugged in here now if on the squirrel you would have installed this event any damage then yes even the squirrel would do something over here so what do we want to do over here well we basically just want to get our health and then we want to uh subtract out of here so we're going to do a minus and subtract so the damage will be out of here and then we can say that we can clamp this so we type in clamp float then the maximum value is our Max health and the minimum value is zero so what does what do we do here we basically make sure that we cannot go below zero Health that's why we clamp the outcome because it might be the case that you are at 10 health and that you get 30 damage by a head shot but then still we don't want to go below this so first of all we want to basically then set this and there we go and now we do see that previously we set this to be a rep notify variable so that we have the opport Unity to code something here uh and then what we can also do is instead of doing the multicast off of here to do cosmetic sounds or to do blood splatter is that we can also do that in here so here we could also handle sounds or blood splatter since rep notifies also handle on basically on the server and on all the clients and rep notifies are more preferred than rpcs you can read that in the unre engine documentation check out cact center right now steam in early exist it's a very fun multiplayer video game G 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 you and enjoy the rest of the video [Music] bye so wherever you can use repap notifies instead of rpcs it is recommended to do so as they are more optimized for the server performance but here we go so we now basically set it um right now I'm not going to use anything from the repap node F so I'm actually going to switch it to replicate it and then also delete its rep notify function over here hit compile on Save uh and let's go ahead and give this little test so I got 100 Health if I then run into here then I got 90 Health then I run into here again 80 70 60 Etc and that's automatically replicated and properly working so also if I do two players listen server hit play then I get my two characters I put my server on the right client on the left so the client can run in here and it can also receive the damage and then the server can run in here and also Rees the damage so what are we going to use this damage event for well later on in the series in not that long actually from now we're going to be having guns and then players can shoot each other and that will also go over this interface event so the gun will basically do a line Trace shoot a line try to see if you actually hit another player and then apply the damage using the event or more basically interface function over here uh and then in the character what we want to do here is if the character is dead we obviously just want to make the character disappear so uh what we are going to do right now is if the health so we're going to drag off of here I say if it is uh less or equal than zero which is means dead then we're going to basically say that we are dead so in that case we're going to destroy the actor and then if we go ahead and test this out then what we see here is if the client here is standing here and the server here then the server will basically run run run so yeah we got to do this a couple times and then this is the final hit so here we go boom and the server is dead and then the client here can do the same and then the client is dead so that's great that's how we can kill people but now that we can kill people we also uh go want to go back into our actual level so let's go back into our Battle Royale and then we need to make sure that all of our widgets work properly and get updated as well so what we're going to do here is in the case that people die we want to basically subtract the amount of current players um so what are we going to do we're going to fly over to our Battle Royale level and then somewhere here we're going to drop the players and then we're going to put our utility box into the world here but this time let's make it do uh 50 damage per hit otherwise I'm going to have to run through it so many times and then what what's the test going to be here well in the top right corner we see two out of two players once we actually start dropping out of the air it will say two survivors so now we want to see if that number will actually go down if we hit that so if we go ahead to the widget and then open up our player count then we can basically go to the event graph go to the function here get player amount text so what is the logic right now if the match has started uh then we can basically say we got the current amount of players is the number of survivors so apparently we are reading from the current amount of players variable that exists inside of the gameplay game state so to do uh so to change the gameplay game State variable every time that the player is going to die we're going to have to basically decrease that so here we got the gameplay game state so if we open that guy up then we see this variable over here current amount of players and apparently it just gets set whenever the players are connecting here and that's it so after that point we're basically going to want to subtract an amount of players so to do that we can then drag in the current amount of players and we're going to be setting it here so how are we going to set this amount of players and how are we going to have this amount of players communicated down to the client well the client basically already knows if we check inside of the player count widget here is basically already bound so it will just keep reading the most up to-date data so all we're going to have to do right now is basically subtract players from here whenever they die so to do that we could either just make a custom event here and then communicate using a custom event to this blueprint so that would look something like this custom event um and then uh player died we could call it something like that so each time a player would die we would basically subtract one and then that we would set as the new value so we could basically just call this actual event here so back inside of the character we know that we are already on the server so before we destroy the character we can basically do get game state and then we can cast to our uh game play game State and then out of here would be that event player died so this would work and then we could hook this all up and have our logic be like this uh but what we can also do is that we can use an interface event so that we don't have to cast like this and that's what I prefer it keeps everything a bit cleaner so to do that we're going to go ahead go into our interface folder and we see that we already already set up an interface for the game State previously so if we uh open this one up then we can basically add a function here and let's call this notify player Def and we're also going to put this under the uh well not match low we're going to put this under let's say um let's call this something like the match State something like that so we're going to notify the player that then we're going to hit compile and save and then what we see inside of the game State here here if we open up then the interfaces and then under match State we then can double click this uh interface event or function and then we can hook it up like this so now this comes from an interface and then we can select it all hit C and let's put a comment around it decrease the amount of uh Sur Force let's just call it that so how can we communicate to this interface event well back inside of the character interfaces are easier I and more clean to use because casts they can they got all of these noes right cast filled cast succeed then you have to cast specifically and then you cast to a specific event you can double click the event and it will take you there with interfaces it you cannot do that but interfaces are more easy because right now we can simply type in this name notify player Dev so if we drag off of the game State we can type in notify player Dev and then we see the the message here so if we click that then this is all what it looks like for an interface event so if we do this one over here then this is it and then after we notified the game State we want the player to actually destroy itself and does die so now if we hit compile and save then we can go ahead and test this out so we got two players here and my two beans are in the airplane so now we need to get these two guys uh to the middle of the map there so let's Precision them so that we can jump out so I can jump on the right perhaps yeah so I'm going to just jump and then I'm going to use a little bit of my parachute and let go okay there we go now we want this guy to jump out and little bit of my parachute and voila okay so I did put the Box a little bit High I hope we can hit it so first we're going to have to server dice so on the top right it now has two survivors so if I just jump in and then jump in again boom then it says One Survivor and the guy actually destroys himself then this guy is going to do the same so one and two and there we go and then we see that now it does not subtract a Survivor so why did it not do it for the client well let's have a little look here yeah so we just made one big oopsie here we basically set minimum player amount but obviously this variable needs to be the current amount of players so we made a big oopsie this needs to be this variable there we go that makes more sense of course right guys so now we hit compile on Save sorry about that but this is basically what it needs to look like so the current amount of players get the get subtracted and then we get this so let's try it again okay so let's try that once more now that we use the correct variable so we're going to jump in here jump in here we see one Survivor left and then jump in here and jump in here and then we see Zero survivors left so uh typically you don't have zero survivors left you obviously you have one and at that point you would then basically see that uh well you would see who the winner is but this is just to Showcase that uh we can now get damage and that we can then communicate that people are dying to the game State okay so that's nice so now we know that we can basically kill people and then if people die we can communicate to the game state to see that there's actually less people in the game um so next up we see if people die they still got all of their heads up display they still got all of their UI so what we want to do is that we actually want to remove that UI as soon as a player dies so for that what we can do is that we can go to our uh gameplay player controller here and then inside of the gaml player controller we can remove these events we could code something called uh iness event imp process and this basically gets called whenever we lose control or unpossess a pawn so in the case that our Pawn gets possessed we can then basically say okay uh that means that we died in this case in our specific game so uh in that case we can remove the gameplay hoods so we can then get the gameplay hood here and say remove from parent there we go we can then hook this up hit compile save and there we go then if we hit play again test it out once more so there's the spot let's hop out parachute a little bit and here we go to this guy H out just jump straight down parachute a little bit and there we go so the server kills itself boom boom it gets destroyed and removes its UI and now the client here where's the thing here it is so now the client jumps in boom boom removes it UI all right so that's very nice so there's now a lot of things that we need to start working on in our game so first of all oh well we see that we got this little error here it says is not trying to read property with your blueprint Hood so yeah basically what that means is if we go over we can actually click it here uh what we didn't do is that we need to basically rightclick validate and hook this up now why do we need to do this uh well what we see here is that we create um this widget here uh and that basically uh uh so we create the widget here on the local player only so the server only has it for themselves and then the client only has it for themselves but this event in process basically basically fires on the server and the clients so for the server the server basically properly removed its own uh parent here but then when the client imp possessed then the client fired this event and tried to remove its own parent and it did successfully but then the server also tried to remove uh the widget for the client which it can't because the server never created the widget for the client so it was removing an invalid widget it was basically just trying to get from this variable which was set to none and that means access node none which we can read here inside of the uh error access none trying to read property which your blueprint hit so that's what's going on so if you just validate it and then the server runs this then we know that it works properly and yes for you guys that are smart out there we can obviously also put this in here to ensure that only the local player would do it and since we know that the local player has this reference set to a valid reference we could then also simply just drag it in like this and remove this and hook it up like this so you can do that however you like uh I prefer this method of just validating it quickly and then everything is correct and you get no errors um all right but now we do see that we need to start adding a lot of stuff to our game so first of all obviously we want to be starting to looting we also want to get uh like the ability to actually start shooting we need to have like different types of guns perhaps and um ammo stuff like that we we want the whole zone right the actual battery Zone to be able to come in uh we want perhaps a kill feed so if players start dying we want a little kill feed so we can see what's going on in the match uh when we die we are now just static at that location where we died so when we die we might want to become a spectator so it's becoming a a whole big list right now of things that we want to do we also might want to be able to pick up Health packs because in this project I added these little Health packs here so there's a lot on the list right now and I'm not sure exact exctly where we should now continue but let's see guys I mean leave it down in the comments what you guys would want to see next and then I can actually start working on that I think it would be nice right now at this point it would make sense if we would start to implement a little kill feed and then after the kill feed I think we could start doing something like spectating and after that we can then basically start working on uh if there's one Survivor that then you obviously have to say this is the winner of the match so we have to work on some match flow logic and then after that we might finally start to add some guns I guess I think that's the kind of road that we're going to go down but leave it down in the comments what you guys want to see next if you enjoyed this episode then please give it a like And subscribe uh and be sure to check it out on the patreon where you can download the full project file and mess with it yourself appreciate you guys and I'll see you guys in the next one [Music] bye [Music] love
Info
Channel: Kekdot
Views: 4,720
Rating: undefined out of 5
Keywords: Blueprints, Unreal Engine 5, Unreal Engine 4, Steam, Multiplayer, Game, Marketplace, Lobby, Game development, Unreal Engine, UE, Multiplayer game, Host game, Sessions, Lobby system, Advanced, Tutorial, Server browser, Sessions Steam, Ready up system, Online, Multiplayer Unreal, Replication, Replicated, MMO, Subsystem, Game Engine, Solution, Modular, Devlog, Listen server, Dedicated Server, Seamless travel, GameMode, GameState, PlayerState, PlayerController, Widgets, RPC's, Steam advanced session, Plugin
Id: _tKKbrExhwQ
Channel Id: undefined
Length: 26min 11sec (1571 seconds)
Published: Mon Oct 30 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.