Godot Multiplayer made EZ | Ep. 1 Server Framework

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello i'm mike and today i'm going to teach you how to create the basic frameworks of a godot server and client it's going to be just the bare bones minimum of what you can create but with it it can be modified and used for any purpose that you have i'm going to try to do my best and explain everything down to every piece of code that i write i'm going to try to anyway and i hope you all enjoy let's get right into it so the first thing that we're going to want to do is create a new project so we'll name it um i'm just going to name it oh my goodness if i could spell name it this easy multiplayer youtube and then put it fine it's like the place where you want to put the file uh project files and the first thing we're going to do is remember in the editor brand new project we're going to remove those because they're just those are just blue so the first thing we're going to do is create a node 2d and rename it scene manager and what this is and we're going to save it and what this is going to do is this is kind of like your base like a base node that you build everything off of so we're going to put a script on to it um we're not going to put anything in here yet um we can go ahead and put just the ready function in there just for the sake of doing so um and the next thing that we're going to do is we are going to create a new script and we're going to call it server.gd of course and we're going to open it and we need to define a few variables first so the first variable we're going to need to make is a network variable um variable we're going to name it network and oops we're going to assign it a network multiplayer e-net and we're going to give it a new instance and so the next two things that we're going to need um i'd if they're variables but i pass them as constants because they're usually things that we're not going to change so the first constant that we're going to need is the ip address and it's a string you pass it as a string and dot 0.0 oops 0.1 now this is not a ip to a server it is a localhost ip address so that means that it'll run we can have the client and the server run on the same machine and it'll work and the next constant we're going to do is the port number and this can be anything from i think to like 65 000. um but i personally i like to choose oops over 85 and that's just i don't know it's just what i usually use when i make a game um okay the next thing that we're going to do is create a new function the ready function and we are going to you be calling network dot cr oh wait just for reference print we're going to output some text to the debugger or the output module here and so we're going to print server starting that way we can have some visual feedback when things happen um okay so network dot create client so what this does is it's a built-in function into networked multiplayer e-net and it just basically creates a client so you pass your ip address that you want to connect to and then you pass the port number and that's pretty much it there's two other things that we need to do we need to get tree dot um set network here and we're going to do network now the reason why we do this is it's i'm pretty sure it's not completely necessary but it by but oh my word my words but basically what set network peer does is it sets the base route or the base scene as like what is able to call um what is basically like the network that can be reached from this server script that's basically what it does i've tried to read it up and that's what i can understand from the best of my understanding that's why we have the scene manager otherwise i think you would have to call this every time um and i'm not even sure that because i think you have to create a new network like you have to do something every single time that you change the scene or something and so that's why having a scene manager is a lot simpler and you just have everything built upon this as children of it of the scene manager okay so then one more thing network oh my goodness i can't spell network.connect we need to connect um connection oh my word i can't remember they don't autofill except for the first time so connection succeeded and we're going to let it call it on our self and then we'll call the method connection um made and then okay and then next thing we'll do is call the function okay and then basically what we're going to do here is print oh my goodness i can't spell print connected to server what am i doing server starting i'm thinking of creating the server that's what i wanted to put i'm an idiot so don't mind me okay so basically that's done so if we run it we have to select the main scene which is going to be our base scene manager and while oh you know what i forgot to do the window i forgot to go to project settings and turn the server into an auto load and i'm actually going to make that all caps that way it's easier to do not do but easier to reference let's say if we're in c manager if we're in some other script and we want to do it we can go server and it's all capital letters dot whatever and you can call functions and get variables from that script okay so now we are ready to play the thing and it will say connecting to server but we're not actually connecting because we haven't set up a server yet so we're going to stop here and now we are going to go and create a new project open up the thing new project um easy multi easy server youtube we're going to browse oh no that's wrong wrong directory oh snap i actually did this slightly wrong it's like fuller create folder and then we're going to actually do this in opengl too because it doesn't require as many resources even i don't think it matters when it's on a server like a linux server so i don't know okay so again we're going to delete these because they're unneeded and it's just bloatware we're going to go and create just a node not a node 2d just a regular node and rename it server we want to save and we're going to add a script to this okay and so we also have to define these variables network is network multiplayer unit dot new and then constant now we don't have to send an ip because this is this is the server itself and so it's not connecting to itself so we do need to make a port and it is going to be the same port number as the other one and then we're going to create we also need a maximum players or actually connections that's the better way to put this now this can also i think this can go all the way up to 1024 if i'm not mistaken that's how many players you can connect onto one server but of course there are hardware limitations usually but anyway so now that we have that we're going to create the ready function and we are going to get network dot create server and then we're going to name the pass in the port and the maximum connections oh that needs to have an s because i would drive me crazy and the same thing network dot oh no no no no no get tree dot set net work here network and then we need to make we're going to send we're going to define two functions peer connected and peer disconnected and that will show um client server side which peers have connected by their user id so connect oops connect oh my word my bad connect appear connected to self calling this in ourself and appear appear disconnected okay so now we're going to define these functions okay and when these functions are called they actually pass the id so we're going to the connection id it's the id that it's like the specific id number the server when a client connects to a server it the server gives each connection a spec special id until that is disconnected and it's completely random it's just a bunch of numbers so we're going to just for visual feedback print um user and then we're going to pass in connection id connected and then we're going to take this and copy that paste it here and we're just going to put a disc connected here and so okay let's go ahead and do that now we have some visual feedback so now if we play it we can select undo there so now we have server started so starting server server started but the thing is we cannot because of how good o works we can't without changing some editor settings we cannot have both of these um running on the same time same thing because it's kind of like on the same thread i think it is i don't know but it's real easy to fix so we're going to just export the windows the server and we're going to easy server youtube go put it in not my dev exports and we're going to save it here and let it do that and so now if we go to here the exports we now have easy server youtube and so now here is our server is this is just like a visual thing this is only what you would have like if you put it online and jump and so now if we go here and we play connecting to servers connected to server so if we show the server it shows user all these numbers connected and so if we stop this and then we see it oh my goodness why did it not oh there we go i don't know it takes it a second to do so but and so we know we're connected if we do this we stop it'll disconnect eventually yeah there we go but see it was the same but you can see here it was the same computer i mean it was even the same instance really because it was the engine that it just assigns a one two three four five six seven eight a ten different number randomly so yeah and that's uh one way that we'll get into another video of how you send information like server to client to or from like client to client or from client to server but yeah i hope that i hope that um shows you how to set up a basic server and in the next video i will teach you how to send information from client to server and server to client thank you very much hope you have a good day bye
Info
Channel: EZ Godot
Views: 112
Rating: undefined out of 5
Keywords: godot, multiplayer, server, tutorial, ez
Id: Uyv877p-kP8
Channel Id: undefined
Length: 14min 43sec (883 seconds)
Published: Mon Nov 22 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.