FiveM Scripting #9 - Player Identifiers & Frameworks (Tutorial)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys it's alpha and in today's video i'm going to be showing you how to make a um steam and other identifier logger 45m which is the first part of a short mini series within my 5m tutorial series um on how to make a framework in case you aren't entirely sure what a framework is a very popular one in the roleplay community of 5m is esx so basically a framework is a collection of resources that work together and primarily use one main like base resource as the um as like a main resource to help the functionality of all the others um so yeah if you know what esx is you know what a framework is and basically we'll be showing you a couple things on how to make your own framework in the next few tutorials um so today it's just going to be logging like identifiers from different users on the first time they log in so basically it will check the database when someone joins the server and if they've if this is their first time joining in their identifiers aren't logged it will log them so what we're going to do is we're going to head to our resources folder and we're going to create a new directory today not in any of these i'm going to call it a framework obviously in square brackets because it's going to have quite a few resources in there and then this is going to be the initial resource so i'm going to call this one framework in it because it's going to be the initial you know the base resource um and then inside of here we're gonna need the usual things such as effects manifest lua and we're also going to need a server developer so what we're going to do now that we've made those two is we're going to open visual studio code and what we're actually going to do in visual studio code is we're going to go to explorer up here and we're going to open the folder of our server data and if we select the folder as you can see here it shows all of our stuff like our server.cfg and then our resources just here this is something that i've only just discovered and it's actually very useful so i'm going to be doing that um if you want to do it as well go for it i've also just realized that i've misspelled manifest so i'm gonna rename that okay perfect so as you all know by now it's gonna do the usual stuff that we put into an fxmanifest.lua so fx underscore version game awesome the description of this resource is the initializing or the book so we've got server script so we're going to have multiple server scripts referenced here so we're going to need to um server underscore scripts plural and then do an open curly bracket then professional name if that bracket is but the the curly one and then we're gonna do server.lua and then a comma at the end of that line like so and on the next line we're going to do at mysql dash async flash lib slash and then this this part has some capitals mysql and so basically this is going to be using the mysql.lua file inside of the lib folder which is inside of the mysql async resource which we've used in a previous tutorial i believe it was tutorial number three um basically this is just so we the um commands of the database we're just going to save that and then we're also going to open the server.lua and this is where we're going to be doing most of our coding today so i'm going to be adding some comments along the way just so you know what everything does this section as you can see will be handling when a player is connecting um so we're gonna add an event handler for this f2h handler function inside of the parameters for the function it's going to be name set kick reason and deferrals and then this second uh close bracket can go down and then have an end for it and then inside of this event handler we're just going to define some variables i'm going to create some find them later so we're going to do local source and this one's just going to be source do local identifiers plural and this one's going to be get layer identifiers and using source whose identifiers we're getting i'm gonna do local steam id so this is the identifiers that we're gonna be grabbing so we've got steam id uh license uh discord 5m and ip obviously if you don't want to grab any of these you don't have to include them so if you don't want to grab someone's ip if you don't discord their 5m i don't have to but i'm just going to be showing you how to grab all of them just in case you know whatever you need them for um and then just below that we're going to be i'm just going to space it let's place it and then we're going to be defining the variables as the user's identifiers just here and then we're also just here we're going to be checking like obviously if the user has steam open or not all right so yeah just here we're going to be um doing 4k uh comma v this is a list in ipad so not not really a list but it's um like going through the list of all of the identifiers that's what i mean um in ipads and then obviously identifiers because that's the list that we're going through doom oh that's cool and then inside of here we're gonna do f string dot match and in brackets b comma and then in quotation marks steam then theme id is equal to v and then we can do a print uh just to say basically that the steam id has been grabbed then what i'm going to do is actually print out the steam id this will print to the console just it's basically uh you don't need to do that that's just debugging see that it's actually working and then we're gonna do elsif string.match the license so we're going to do this for each one so we've got steam id now we're going to license then discord then 5m then then ip oh i need to do that in quotation marks and then what i'm also going to do is do license with a colon because there's two types of licenses there's license and license too when i identifiers are grabbed we don't want to use license too we just want license so i'm going to add a pull on there just to make sure it's getting licensed without license to and then so this one will be licensed equals v and i'm sure you can assume what the rest of it's going to be so it should be lcf and string.match it's going to do the same thing for each of them i'm just going to skip ahead for this part and then just show you this part once it's done so that's all of them so i've got obviously steam id license discord 5m and ip and then we've got make sure we put an end on the end of that as well and then once we've done that we can go outside of these two ends but we're still within this last end and then we're going to add another comment just here because this section is going to be checking if the user has a steam id so basically the way we check that obviously because we've grabbed it now we'll do if not steam id then and then we're going to do deferrals dot done and then in brackets and quote marks we're gonna do you need to open theme and this will basically give the user a message uh that they need to open steam before they can play and we're gonna do else after that hold on a minute let me just add back that and there we go we also are going to need to add an end here as well so and basically what's happening here and yeah within this else so obviously if they don't then it'll turn they need to open steam if else if they do then um it'll do deferrals dot done okay yes there we go and then below that uh what we'll do is we're gonna do another print statement just for uh bug fixing i'm gonna put steam id is being fetched and basically what this is gonna be doing is obviously because we've detected that they've got a steam id we're going to try and fetch it out of the database so women checks if the user's name a is and what we're going to do it executes a i'll actually fetch from the um sql database so i'm going to do my sql dot async just make sure that your capitals are lining up with my capitals here uh otherwise it won't work and fetch scala basically what this does is this the this grabs the first um basically the first piece of data in the list um so basically the first like id or steam id from wherever the steam id matches to one that we've got so what we're going to do is in quotation marks make sure also your syntax here is correct with mine so all the capitals and all that uh select one from we're gonna do user underscore identifiers and in all caps where and then not in caps theme id equals and i'm going to need to do at beam id and then after this quotation mark but still within the closed bracket we're going gonna do a comma and then an open curly bracket and then take this down to the next line and then in square brackets we're going to do in quotation marks at steam id and outside of these square brackets we'll do equals d what we grabbed earlier up here and then what we need to do is just after the close curly bracket but still within the main bracket we're going to do a bomber and then function brackets result like so and then send down this bracket to the next line i'm actually just going to do an end there and then actually within the end we're going to do if not result then we'll see that's getting this result just here so it basically if we did find this dmid we get a result if obviously if we didn't find a result then we will do print theme identifiers into like so and then below that we're going to run another um command for the mysql so i'm going to do my sql dot async and then dot execute like so and then in brackets we're gonna do insert into then lowercase again user identifiers again and then in brackets we're going to do steam name beam id license discord 5m ip and then outside of this bracket oh hold on go back to the end and outside of this bracket that's in there in the quotation marks we're going to do values and then inside of some more brackets we're going to do at steam name omar comma at license basically for all of them discord and then just outside of the quotation mark but still within the final bracket we're gonna do a comma we're actually gonna take this onto a new line and then we're going to do in an open curly bracket we're going to do a open square bracket as well and then we're going to do quotation mark team name out of the square bracket equals get layer name and then source like so and then we do the next thing and we're going to need to do this for all of them of course of um and basically once we've done all those we can go back to the next slide to the line below sorry need to go back in indented again to the same indentation at the line above and basically what the reason that didn't indent is because we need to add an end here like so um but before we do that end we're actually gonna do an else and below that we're going to do okay well first of all just before the else we're going to do a little print statement just to say uh all inserted so print into fires that's it into base though and then else steamready found because basically if if that isn't found then obviously it does this but if it does anybody so and then that's basically all of the code within the server.lua so you can save that and then we're actually going to need to make another file um in this we can still wake it in here it doesn't need to be in here but it's probably best to make it within the resource folder um because let's say in the future you have like reset your computer or something but you've obviously backed up your your server data you might need to remake your database um so having the code to make the table that you're using is very useful i'm going to make one just here called framework dot sql and then basically we're going to open that video as well and then the code that we want to do now this is a different syntax from lua so just make sure that you've got the exact same text as what i'm doing uh because the syntax is totally different and if you do it wrong type the wrong symbols or whatever it might be code not work at all so on the first line we're going to do create database if not exists and then we're going to have to use tildes which are not quotation marks this is a quotation mark and this is a tilde obviously they're very similar as you can see so the first ones are tilde second one is a quotation mark quotation marks will not work you have to use tildes if you don't know what tilde is um on most keyboards it's the key below escape um if it's not there for you you might have to just copy and paste one from the internet obviously you can just copy it and like paste it like so um but yeah if you do have it then you can use it so inside of this we're going to call the database framework obviously if you've followed my um episode three my tutorial number three on how to make a mysql database uh you might have a database called 5m if so use the database 5m i'm just going to use framework because i've reset my pc since then so i don't actually have that database anymore so i'm just going to call this one framework and then on the next line do use framework obviously once again if you are using by them database from my previous tutorials we'll let that instead so then we're going to use that database framework and then we're going to create able and we're going to call it user identifiers which you may recognize from here because obviously that's the table that we're referencing in the server.lua so it has to be called user identifiers and then in open brackets i'm just going to drag that next one down and then we're going to do all the different fields within the table so we're going to do steam name and then this one's going to be so the data type is varchar which is variable character and then we need to fill field size so that's like the maximum length of the data inside so i'm just going to do like 40 characters i feel like that's a good length and then the default value we're just going to do not null quickly and then we're gonna do a comma for the next line i'm just gonna copy and paste this line and then change it because i don't wanna type that out every time um so i'm gonna do this a couple of times like so and so the next one's going to be steam id this is basically all of these in here so obviously we'll steam id license all of that yeah we got steam name steam id then we're going to do license discord 5m p so once you've got all x of those then we're going to do one more line where we say primary key and then we're going to do steam id because basically if you're if you're acquainted with databases you already know what this means and if you don't a primary key of a table is the the field where no single value will be the same but obviously because every user has a different steam id none of them will be the same this basically will be the primary key because obviously discord let's say uh there's two people sharing a computer and they share a discord account but they have different steam logins they'll have different steam accounts theme ids but they might have the same disk id obviously we can't guarantee that that would be different um but for each steam account this could be a different steam id so that's why that's the primary key and then what we need to do just on the end is add a semicolon you need to do that for all of these three lines just here that i've just highlighted because the syntax for sql is it needs a semicolon to end the instruction and once you've done that we can just save it and that's all of the coding that we need to do today before we can actually run the code we do need to actually open up the database so obviously you do need to run xampp which you would know if you've watched the third tutorial if you haven't you need to install this go back to my third tutorial and follow that so obviously we need to start up mysql and then also we're going to want to open id but obviously what i'm going to do is just run this and this will open hide the sql for me oh no i'm just going to open that instead okay open with i don't know okay i'm just gonna open it from here then and here this go file i'm just to find it there it is so here you can see the the code that we before and then we're just going to run that and now once that's run we can just go on the left and then right click and refresh as you can see that's just created the database called framework if i open that up we've got user identifiers then we can go to data just here label layout and obviously we've got all the different fields got steam name stream id license this 5m and ip the steam id has this key next to it because it is the prime key um so if that's all working for you the database is done correctly and we can actually go back to our server.cfg and we can actually run the um resource in here so i'm actually going to do is obviously it's got to be below my sql async because we're using that i'm actually going to do ensure and then we're going to run the whole framework folder so basically this is something you can do in 5m where is if you've got a folder with loads of resources in them uh you need to have the square brackets but you can actually run all of these the the resources in that whole folder by doing this doing the name of the older web rn so if resources so framework here all of the resources that are with that that are within that uh we'll just start by just executing this one line so something else i just realized that we need to do is we do need to go down here towards the bottom and we actually need to set the steam web api key because basically you need to set this before you can get users steam id so you can just go to this website just here i'll have it linked in the description and register for your own web api key and you can just put it in there i'm just gonna grab my one and put it in there another thing you're gonna need to do is uh on your server.cfg in on the set mysql connection string obviously this would have been if you've done it previously with my um mysql tutorial the database will be framework so if you are using just this tutorial obviously you need to add this into your server.cfg but obviously if you did the tutorial from episode three you will be using database 5m so see if you have changed it to framework you need to change that or if you have in here it made it a database if not it's 5m change that you can leave that as 5m something i just realized is on line 17 if you've done the same lines as me this sign just this line just here prints them id grabbed just after the quotation mark you need to add a comma now that we've made those small changes now that we can see started resource framework dash initialize uh obviously if the if you're still having errors you might just want to do some bug fixing it should just show an error message of what the issue is that's how i fixed all the issues that i just showed um but now it's starting up i'm actually going to jump into by them and show you how this works so now that we've got fibromyalgia i'm just going to show you um obviously on here on the database we've got all of the different fields uh but obviously i can even refresh and you can see there's no like data within that so basically the point is that when we connect to the server all of this should be logged with my data so if i just press here and then i can show you the console as you can see steam id grabbed and steam id is being fetched and because i've never connected to the server before steam id not found inserting identifiers into the database and then obviously now that it's done it identifiers are inserted into database so now what i can do is if i refresh this you can see that all of my identifiers are actually database um now if i connect to the server again it won't log him again because obviously it will search and it will find them so it'll be like oh okay he's connected before that's fine we've got all of his information already um but anyone that does connect to the server obviously it'll grab their information um you may be wondering oh why do i even need this information well basically if you're planning on like you know making a framework and making a server loads of people will join um obviously you want to grab things like that ip and their steam so if they break the rules or anything you can ban them um obviously you can use either the steam or the ip or you can use both for like added protection on the ban or you can use them for totally other things it's completely up to you to up to you and um obviously this is only the first of many episodes regarding frameworks um but obviously if you enjoyed please leave a comment uh you know suggesting what else i could do regarding frameworks or just anything 5m related uh if you do need support join my discord which is in the description uh please do leave a like share it with your friends and um thanks for watching i'll see you in the next one
Info
Channel: Alfa
Views: 747
Rating: undefined out of 5
Keywords: ultimate, best, the, most, insane, minecraft, gta, call, of, duty, zombies, online, offline, glitch, cheat, money, out, map, new, working, feb, aug, mar, jun, jul, may, real, no, fake, downloads, ads, pc, xbox, one, 360, ps3, ps4, wii, siege, 2020, funny moments, utub, alfa, fivem, scripting, tutorial, 2021, server, client, resource, citizenfx, esx, vrp, essentialmode, cruise, control, speed, detection, vehicle, hud, FiveM Scripting #9 - Player Identifiers & Frameworks (Tutorial), frameworks, ip, discord, steam, steamid, logging, database, mysql
Id: 7O-upCG3wds
Channel Id: undefined
Length: 28min 43sec (1723 seconds)
Published: Sun Nov 28 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.