FiveM Scripting #3 - First ESX Script (LUA)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
to go over one doing this video I'm gonna be making a money washing script it's going to take place over two episodes long probably we'll see how it goes but I just want to break it down into two episodes hopefully and I just want to show you guys how someone that would be actually scripting you know I'm a code for you know ESX would actually think how the process would be I'm not you know advanced in this I don't know what too much about it I all I know is I've been scripting for a couple years according for a couple of years I've been scripting for a year or two in lua but i've been calling a java script for a couple years anyway and c-sharp and you know etc so what all the boring stuff i wait let's get right into it hey and welcome back to the episode 3 of the scripting series let's say we're gonna jump right into ESX and i've been thinking about it and I feel like it's the best option mainly because at this point or I can a point where we know the basics there was at the very basics and I feel like the only way of learning how to do ESX is by just going headfirst into it so I will be teaching new things along the way and obviously new stuff I'll be teaching you natives and all that but I feel like it's best if we ever teach you it on ESX level to get into this we're going to do something different this time normally we create the files but it's it's a lot easier there's this thing called a boilerplate out there it's called ESX boilerplate and it's just the base you need to start off ESX at the very basics very bare minimum maybe for ESX and so to make sure this works you do need ES underscore extended installed in your server I'm just tons of videos out there to you know do it so I'm not gonna go over but if you go to the link in description you're gonna find a link that brings you to this github page down here it's gonna call it be called es X underscore boilerplate so what you want to do is you want to go down to here I'll go over it here and you want to click on a clone or download if you don't have the application to run it I'd recommend downloading it true the zip obviously so generally hair save so I'm going to go up here and I'm going to just actually want to open it and winner are no I'm going to rename this to I'm gonna rename this as script are gonna be making in this episode so I'm gonna rename this to money while washing well I'm making this for my server so I'm gonna do money wash okay SRP - money wash the reasons SRP is because on my server it's costing or roleplay and we have the initial I saw a piece so it's just like um a little you know prefix first so open up SRP money wash now and you want to see client server editor config effects manifest our lua license and read me so you don't need editor config license and readme so you can just lead them straight away so i'm gonna open up the FX manifest just to show you guys what's inside so FX manifest has opened up and you can see up here it says FX version is Adam Ant now the most recent version is bodacious so we're going to we're going to update it to bodacious just to keep updated the game normally you're gonna see in the template that we show it we show and you know earlier videos the game was already are free which is writer emption to be confusing but yeah on GTA 5 but we only need GTA 5 in this case we're only colton for GTA 5 and then here the boilerplate description like we don't force so I'm going to Sonora roleplay money washing system so there's one more too many to add when you get into more complex scripts it's um it's generally a good idea to have a config file in case it's layered under old you want change you know details about it like a button to press or you know times right so what we want to do for a config is we wanna go on to your folder and here not in the client not in the server the root directory we're gonna create a text document make sure you have extensions on like I shortened it very first video I'm gonna call that caught it config config Lua so now we have to go back into effects manifest and depending on where you're gonna use this you know you only need to put it in word you know one or the other but we're gonna be using it in board so we're gonna put it in port to them as far as no we're gonna be using a board I'm not really sure but I'm definitely using server scripts so I'm just gonna put in bosses it doesn't you know it doesn't affect it now because this is in the root directory all you have to type is config a config dua and then ensure your a comment next to it otherwise it will not work because this basically tells us the code that this is a separate file from this file and the code is only expecting one argument it's not expecting to so you know if you write if you wrote that it wouldn't work because it's only expecting one argument and yeah so basically we have server scripts config so we just want to bring this down to client as well and one thing is very important to make sure you have to make sure that the config that Laura is on the top of everything namely because the server may not live were the client made aliyah they're going to be dependent on what is inside the config Lua okay so in this tutorial well in this part of the tutorial I'm gonna focus on the client side and what I want to do is I want to have a place for the character to go to and they're gonna have a notification so I'm gonna do a treaty text saying press e to wash your money or launder your money and then it will take your dirty money and it will take a percentage off and give it back to give the rest of the percentage off to you as if like attacks you know so to do that we're gonna have to start off a claim because we need something to send to the server we need to be able to talk to the server file so we're gonna head over to the plaint lua so mean and open with a visually hot and you want to see this this is different than what you would have seen before now save this make sure I save and this is different what you would have seen before this is called a sax player data and then it's a create right so basically says well ESX is not like what is X is equal to nail it's going to get the shared object ESX which basically means it's going to get a directory of ESX so you can use all the ESX functionality and then when the player is loaded in it will say that the the player dial up here is equal to the X player so player died that job is equal to job all right so you can set the job using this because this gets your player that his job and then you can equal to whatever job you need so this is guy setting server-side functions client-side and this is actually something I haven't used frequently I've only really discovered a recently to be honest and I'm gonna be using to optimize my scripts more but I need to get look into a bit more because I'm not professional at this and not you know an expert this I'm only been calling and buy them for like a couple months now really I started a year ago by stopped so I wanted to call in for like two months now already but I want to share what I know so far yeah so from what I want is I want coordinates of where the of where the money-laundering place is going to be so to get these coordinates I want to make I think called command like we discussed this so register command I'm going to type courts because I need the courts it will be sash chords and game and function end so what I wanted to do is I want to just print out in the console of the entities cords so we're going to get was it I think it's get entity hordes and player head ID I think that's it and then we're going to print it out printing basically means it just there's a console in five mf8 console and this will just write out your cords into the FAA console we're gonna go into game now to get the cords at location all right guys we're in the game now and I have my location for where I want the money Washington P so it's just in here and I would like it to be mm-hm where I want to be back here I'd probably make more sense to have it here nope before anyone says anything I obviously know money you know money laundering money Washington's not done in a washing machine but like you know I think it's a cool time at all so I'm gonna use it yeah so you don't do is you want to because is your cron should work so find the area where you want to launder the money I want to be here I want this to be the area where you go to launder money so I'm going to soak what's up slash chords then press f8 you should see this vector free this is your coordinates and I just copy it and bring it back into division city called all right now I'm visually called I have my config file opened because I'm doing this in a config and to start the config we want to type this config equal to and the car D brackets know one thing you might you may not notice is we don't have local before config that is because from my research I've done I'm not to be sure before my research local makes the variable in a localized scope meaning it only works in that script or function or whatever you declare it it means they'll work wherever wherever in your files it will work because it does not have a look it's not localized it's a global scope so now we have the config object or hash created anomaly show or what to call it I'm working config dot okay so config dot location equal to I'm gonna put paste in my vector okay so basically what this does is says config is equal to location and location is equal to chapter you know vector that's what it means boy it just it looks nicer to have it this way you know it looks more neat look smart ID so we're gonna go back to the main file now alright so now we're in here we do we no longer needs this so we're going to or move it or comment it up what I'm going to remove it so now go to the comment section below and you will see this function in the comments it's copy and paste it and I'll explain at the hair but you shouldn't need to know all this reason being is because you're probably just gonna end copying and pasting it the entire time you don't need to know it but if you want to know what you can you can look into it I'll just explain it very briefly so what this does is it gets the coordinates of the of the you know the text and then here it unpacks the your camera coordinates and I'm pretty sure relative to your camera coordinates it places the text so look you know rotationboys Allah here are sets the text scale I'll talk about a minute set text font so that is in GTA lose a couple fonts that you can use just some that's cursive some that's you know big blocky characters and whatever I'm using for because I think that's the nicest looking one set text proportional I just put that to one text entry set text entry to string has to be string has been all caps set text centered it's just some explanatory if you want to be Center it's a text color this is just making a white and it just preface this it just cuz white does not mean a it can't be yellow in certain parts we go over that a minute but you see set at them you know the default it will be white and add text component string so this is adding the actual like the detects itself and that is text because we are bringing the text variable in and then draw the text on the coordinates XY are relatives your camera and in fact or the factor is just defining relative to how long the text is how White's did rectangle should be and then that's a strong rectangle behind the text to give it a bit more of a an outline you know so it stands out more now that we're inside this we want to make a citizen dot create thread and everyone do function in parentheses and an end as you don't before now this is not create right it uses a single-core try it on your computer that's all you really know for now in the future you can look into more optimization I'm just after fighting about some optimization with this so I need to know more before I can teach you guys more so just you've found in while true we've done this before while true do and so we're making an infinite loop and we do a citizen dot wait now with the text it's really weird how it works but sometimes you can go you can wait all the way up to five milliseconds all the times it has to be one or zero but we can test so I'll do five or not before other for because five sometimes is a bit weird but four is usually a sweet number to go by so we can do draw 3d text all right on the X Y Z so we need the XYZ and to get the XYZ we defined it we would find it here in the in the contract what we do is this represents X is four persons one deserves NZ right so to get this all we need to do is type config dot location actually because we're gonna be using more than one so all going to do is go here and go to the top just before the Wildtree loop make sure it's before while true loop because we don't want it to run every single time there's no point for that because it's not moving it's not moving so we do local ah look location is equal to this no I really wanna like I need to preface this and you have to you know understand this the reason why we're not putting in a word root of because if we do it will it's like repeatedly every four milliseconds run this cord and it's not needed so it will cause your delay will cause like unnecessary like it's not needed so it's just it's just a more optimized way of doing it in here we can remove this and here we can draw the text so we can do location lower case because I said location or case it's variable name isn't location dot X because I'm getting the X then location dot y and location I'm not a Zed and so on so no we want to do this string so in the string I would like it to say press e to wash money now when we do this in game it's going to be press e to wash money and I want to put emphasis so what I'm gonna do is I'm gonna do that the tilde key so tilde to to the keys and then in the middle I'm going to type up boy for yellow yellow you know why or if you do is r RB right but I want to make up yet oh so yellow is white has to be surrounded by 2 tilde keys because that's just the way that code works no after II I want to do W that's white some people do G because yeah they use a grey bar you know wait for me and then here I'm going to do wash money and I'm gonna remove this force up now this will basically say white disappear white and suppress this will be yellow and this will say e and then this would say be warned this will say 2 and this is B I want say wash money so no let's just see if it works save it and put it into your game so I made one quick mistake I forgot to do to scale so we just want to do comma I might go to is 0.4 so no we're gonna bring us a game press f8 go to console and type restart SRP - money wash and now you're gonna see this it's a pressie to wash money like we said earlier now the issue with this is if I go all the way over here I can see this and that does not look very secretive to anyone I mean you're walking out here going to the shop and you see wash money to be interested and what it means so what you want to do is we want a distance and we want to check how far the player is from the distance and if the player is a certain limit from the distance it will wash the money it will sorry sure the text wash money so because this is inside of a tread and its way in every four milliseconds we do not need to wait for less I can just way too fast for any player right so all we need to do is make another Traxxas and not create tread and a function end okay so up here we're going to make a variable I don't going to do is near go fast because default it would be false and here we're gonna do a while true do and I'm gonna do citizen not wait and let's say 500 milliseconds half a second and then what we do is we type alright so you wanna type if V dist and in parentheses now up here we want to type local player local ped is equal to player Pet ID because we're gonna be using multiple times what we're going to do is we're gonna say if V list and under hair right do a local chords because we will also be using course multiple times sorta get entity chords and head because calling this instead of this so local pet so back to it again if it is cords and comma and what we want to do is want to do config dot location is less than if the distance between the chords and the location like don't your player chords and the location is less than a certain number so I'm gonna do in config file okay so everyone changes in the future so config dot distance distance is equal to my gold who's really about five to eight ish maybe so all the eights just to see what it looks like what usually is for as far as I know it's so config dot distance then and so what says is if the distance between the player and the text is less than eight meters then what we'll do is we'll do is near is equal to true and here we'll replace the end one else so else and then is near is equal to false so if the player is less than or equal to the distance is near as true else if they're greater than that it would be false up here instead of while true we type of oil is near all right so I made a little error some reason it does not want to take in the if is near is equal to today's equal to true so why boil a snare is equal to true do so all you just need to do is instead of typing instead of having this while is near put it back to a boil true do and in here you want to type if is near then end okay all right so now reset your script and then start walking towards your place and you don't see the text now you do now personally for me it's a bit too far so I'm gonna change that to maybe five and yeah so we're gonna go back into the just to decode and make the changes so changes to five no what I want to do is I want to check down here if readest chords the config dot location is less than 1 then end so basically I'm checking here as I'm saying if the player is less than a meter from the location it will you know it will do whatever so just a test is we're gonna do a print hello I bring this back into the game alright never run into the game you can look in the console it's very clear if I go to here right on it it would say hello hello hello hello and so on but if I go back out it won't say hello so not that right ok good that's what you want so now what I'm gonna do is I'm going to listen for a key price and when the key price does something it will you know it will react to it so go back into the go back into the Leisure Suit accord alright so now that we had this done what you want to do is you want to go up here to where it says Susan not wait for and we want to type this alright so I made a small mistake up here we're not using the variable chords because we moved off and since we are only going to be using it in here once I think it makes sense to just to do is core sorry get entity chords paid we can use paid because you defined actually we can use ped so what we'll just do is player ped ID all right so that is that is that we can actually what we can do is we can use pet because we can define head up here so we can use pet alright no we can bring back into the game alright Mary our everything restarted if you press E you will see testing e testing now Nora is not printing it's just doing it when I press E that's all gone alright face this video is gonna be pretty long so it will be broken into multiple parts right now we have the client side done for the most part and the next video we're going to do the server side now what we're going to do in the server side is we're going to do tax okay I'm gonna check the players so checked players inventory and see if they have dirty money and then what we're gonna do is we're going to wash the dirty money if there's enough dirty money in here we're gonna wash dirty money and then it'll give back to the player with tax taken off of but it might have enough money because what we're going to add robot other system where once every ten minutes it will add money into the money under so players can't abuse the fact that they can wash money basically it would have to be a timed thing it has to be something that you have to plan out and you have to make sure there's enough money in here before you can wash it anyway so that's it for this video next we always call me tomorrow I hope you guys like it and yeah all links will be in the description below and this is the first of many videos on ESX I hope you guys are ready to learn a lot by es X and a good time
Info
Channel: opod
Views: 27,866
Rating: undefined out of 5
Keywords: fivem, fivem roleplay, fivem scripts, fivem server loading screen, fivem server vehicles, fivem resources, scripting, fivem server install, fivem server, grand theft auto v, fivem tutorial, fivem server tutorial, fivem scripts tutorial, grand, grand theft auto, grand theft auto 5, fivem texture mods, fivem server installation, lua, lua tutorial, lua intro, what is lua, lua scripting, lua programming, lua 2020, lua guide, ESX, essentialsmode
Id: sZzoq71Q9nI
Channel Id: undefined
Length: 25min 15sec (1515 seconds)
Published: Tue May 12 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.