FiveM Scripting 25 - Vehicle Mods and Upgrades

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] become a patreon gentleman today and receive a ton of perks including just school rose early access content private support channels code snippets and more join today at patreon.com jjs what is it guys my name is zuo from java today we're going to be talking about vehicle modifications and upgrades for vehicles we're gonna be changing different properties for cars in the game so i have the code that we're gonna write in the description below it's this github this is the resource that we're gonna make and let's get started so let's create the resource i'm first of all on my server folder here to go to the resources folder and create a new folder and call it vehicle and that's what what the resource is gonna be called so i'm gonna open this vs so to you know create a resource now we have to instead of it being resource down low we have to change it to FX manifest duo that's what they changed it to so if you're familiar with underscore underscore resource table was they change that so i'll get used to this now so now what we want to do is in here let's declare an FX version and this version will be called bodacious okay and then the the game is GTA 5 that's another variable game is GTA 5 and then we're gonna make multiple scripts so defined scripts and this will be an array table and this is gonna have client Lua that we will make and we're also gonna be doing more with that so let's create that client Lua just like that and we're gonna be working in there laters but first we need to set this up so I have this zip right here that I downloaded this folder has the data that we're gonna use this is just raw or this is just a static data I'm gonna just drag that into there this what's called this is if you want to look in here this is just the same thing as this data folder in the github repo so if you want to follow along you can copy what this is is pretty much just has all the values for you know if you want different colors for things without like looking up their values it kind of just says everything here so it's just like a little dictionary here for you if you want but yeah so I'm just gonna copy that in there and now I want to do is kind of allow all of these to be and the scripts on its gonna do data which is the folder and then slash all the Lua files on the asterisk means all Lua files or the asterisk it means everything and then we want everything ending with the dot Lua file so it's gonna count all this as a client script which is what we want so now let's actually it started with writing the client script so this will be called client Lua and in here what we want to do is start off with register we're gonna be creating a command called vehicle so it'll be slash vehicle and in here we're gonna use source and function and it'll be the source and this function so then now what we want to do is create or we're not going to we're gonna be using the arch so let's create a kind of like a switch case statement so but in lua so let's do a local category is equal to arms one so the first parameter or the first argument will be stored in this variable category so what I'm trying to do here is I'm trying to do if I want if I do such vehicle I'm gonna try to do like vehicle spawn and then the car so we're gonna we're gonna make this category first so I'm going to do if category is equal to spawn which is categories of first argument so spawn then we will then we will spawn the car so let's do that logic now so if it's equal to spawn then we want to get the car parameter like I said here I'm gonna do local vehicle is equal to arcs to because that's the second parameter and let's get a let's apply it car paint to the car now so I'm at a local car paint is equal to colors and this variable record colors it's in the data folder and under paints so you can see that colors is this variable so you can pick up any of these that you want for me I'm gonna do pure gold one because I like how that looks so this is under the metal category for this and then pure gold so yeah you can just write 158 if you want that that would work too but this is just this looks better it's more user-friendly like then then just having a bunch of numbers that you don't really know so I'm gonna do metal and then in here pure gold gold right yeah that's perfect okay and then that will be that'll this pretty much just just that will just resolved into 158 that's what that's gonna do um and then let's get the vehicle or let's create the vehicle so local VIP is equal to spawn big short for vehicle of course and we need this has two parameters the first parameter is the vehicle name that we have got from the second argument and the next one is if you want it to be persistent so I don't even get to show you this function this isn't functions da lua we didn't get to write this together but it we've used this command before so spawn V it's a Karn persistent if you want this the second printer it's persistent if you know if you go away usually a car that is not persistent will despawn so if you want it if you want the car to de-spawn and you'd write false or if you wanted to stay and you go away come back it'll stay there and we won't respond or won't do spawn this you want that to be true so I don't want my car to de-spawn ever so I'm just gonna make it true so now we want to do is let's set the color so sets the vehicle on get both colors and this is a native and the first parameter is the vehicle that we just created so this vehicle it just spawns in a vehicle but it also returns the vehicle so we can use that as like a vehicle handler so we can just do that and then we can just car paint and then car again so this native right here has three parameters the second parameter is the primary color I'm pretty sure their perimeter is the secondary color so you can mess with that if you want but that's how that native works and I'm just gonna make it both pure gold because I don't really care it's hopefully it'll work anyways like it's probably it's fine it can be the same so let's also create a new category now so I'm gonna do else/if category is equal to customize so in here we're going to we're gonna customize the car so we're and to be more specific we're gonna just change some of the body parts of the car so to do that let's first to get our vehicle so local fit is equal to where I can spawn in our car we're gonna assume that the pet is already in a car so to do that we're just gonna get vehicle head is in get the player head ID and then it's false so that's just gonna be the vehicle and then we want to excuse me so before we actually customize our car we have to use this native called set vehicle hit and pass in that and it has to be zero so this pretty much this native has to be called it has to be called before you modify your car it will not nothing will like happen if you do not call this native before you do any of that so we need to call that before we actually apply our new mods so let's actually do that now so I'm gonna make a for statement and I'm gonna loop it ten times and I'll show you why we're doing ten specifically I'm gonna do ten and then or zero to ten and increment by one and and oops so in here we're gonna loop through the first ten mod types so the first ten mob types my upgrade style Lua is not in order actually I don't have all the mod types but the first ten are pretty much just body upgrades that's why this this we're calling this category customized we're gonna look through every single body upgrade and the first ten I've noticed are the body types so we're gonna apply all body mods to this car so that's why we're looping through ten you can do a total of fifty if you want which we'll look through every single mod whatever like modification there 50 total but the first 10 terms of body features so let's get um what's it called so let's actually get the best mod here I'm gonna get the best mod it's not I call this variable best mod because it's just gonna get like the last mod available for a car so I'm gonna do get number or getting numb the cool mods and then this is a native and the first parameter is the vehicle handler of course and then the mod which is this number that will be incremented by 1 for every loop and what this does is just this will return the number of mods you can have for each mod type available for the car that you have so pretty much I'm gonna do that but -1 because I've noticed that if you just subtract him by 1 you can really tell the different like body features applied like when I when I did without -1 you can tell like I just have minus 1 because it's easier to tell that the mod worked or the like the application won't it will work anyways but this is just like a lazy way to parse it if you want so yeah now let's also actually set the vehicle mod and to do that we do Z circle mod and then vehicle that's the first parameter my type that's the second parameter and then best mod is the third parameter is also another one false I forgot which parameter this means is probably doesn't mean anything but the best mod so the mod type is the mod it's just the type of a mod so let's say 1 or 0 the mod type 0 means spoilers so if it's 0 and then it says get the number of so let's say we're at the zero iteration of this loop it'll say 0 and then this get number of vehicle mods will return probably like 4 or something depending on the car and that's the number of mods available so the number of spoilers you can have for this car it'll return the last number and then minus 1 sort of like I don't know it depends on the car but I just said that just so you can visualize what I'm trying to say here so yeah now let's also do let's let's make another category so do else--if category equal to extras so cars have this thing called extras and we can toggle all of them so let's do that I'm just gonna copy what I wrote up here because we're gonna be using that a lot the local vehicle thing so now what we want to do is we're gonna iterate 20 times so ID is equal to 0 20 and then do it's cause yeah and then let's iterate so there's so what i'm doing here actually is I'm iterating 20 times through all the vehicle extras so there could be a total of 24 you know every mod but there's probably like three or four extras available for each car so we're just gonna do if does extra extra exist and the first panders vehicle then the second parameter is ID which is this variable right here and then if it does exist then we will then we will actually set the vehicle extra which is V and then the first primary's vehicle the second one is the ID but then this one is 0 or 1 1 means turning it on zero means turning it off we're getting rid of it you know that's that's what that means so once we do slash vehicle let's say like we do slash vehicle extras then then it's gonna loop 20 times it'll see what kind of extras the car has it'll turn every single extra on for the car and you'll be able to see it visually once that is yeah but once that's done and now what we want to do is let's create another category so let's see where did I end this right here so I'm gonna do that right here I'll sniff category we're gonna make a repair command or kind of like a repair thing then I already ended it so it's fine but so in this repair command what we're gonna do is get this vehicle again we're gonna get the vehicle the pet is in and we're gonna repair the car so it's this one's pretty easy you just do set vehicle fixed and then the second parameter oh no there's only one parameter like that but now we also have to set vehicle engine out to vehicle and then a thousand point zero cuz this is a float you need to have that decimal in there or I'm pretty sure it will not work it's night I think this second parameter for the set vehicles the 70 vehicle engine health requires it to be a float type and that is the float type so that would just fix it this commands is just gonna fix it and yeah that's pretty much it let's also do um let's make a little thing for opening our doors so category is equal to doors and then then we will we're gonna so this commands just gonna basically toggle our doors so I'm gonna get our vehicle again and local open this will be a boolean and what this is gonna do is get a vehicle door angle ratio and then this is the vehicle and it's 0 so we this is what this is gonna do is this is gonna get the door angle ratio this is just gonna this logic right here is less than 0.1 okay so this logic is gonna be a boolean if it's open then it'll be then it'll be true if it's closed then it'll be false just like that that's what that logic is and then if it's open then we will loop through every single door and open it or if it's yeah if it's open then we will loop through every single door so let's do that for I is equal to there's a seven and increment by one and then do then we will set the equal door open and vehicle I false and false so what this is gonna do is just open the door if it's open that I just realized that really doesn't make sense I guess that was just an error on my part so you could change this to close I'm just gonna keep this open for consistency but my bad for that but if it's open but if it isn't open then we will have an else statement here and we will do set vehicle doors shut oops and then vehicle is the first plain room the second one is false so if it's let's just say this is not open I'll just change it real here so I could just say closed so if doors are closed then we will open them if they are not then we will close them so just like that does that mean that I think that makes sense so that's pretty much it for that part now we're gonna get into the fun stuff which is actually upgrading so let's do that right now uh house else if category equal to okay sorry about that so if category is equal to um what we're doing we're doing upgrade if category is equal to upgrade then we will we're gonna do a bunch of stuff in here so let's get the local hoops I mean to copy that and we're gonna get the vehicle Pet is in right now and what we're gonna want to do now is let's let's set the cup let's change the color to red something really know the school so I'm gonna do local color is equal to colors which we is a variable from the paints Lula right here yeah so we're gonna we're gonna get what are we doing we're gonna do red so we're gonna do colors dot matte and then in here is red let's go that wrong so Matt there we go so colors done that you can see in here Matt and then we're getting red right here which is just 39 you could just technically speaking you could just do that but I'm gonna make this look more sense make it look you know just better in my opinion easier to understand what the 39 means so now what we want to do is let's give it some specific upgrades so I'm gonna do I'm gonna create a table here local our selection is equal to the table here so we're gonna have we're gonna set armor just like that is equal to we're gonna give armor armor upgrade 100% so we're gonna give ourselves 100% armor for the car just what'd I just do okay comma and then let's give ourselves the best engine upgrade to so engine is equal to EMS upgrade level four so these are specific values we're gonna be looping this through so it'll be like parallel if you go into upgrades da lua and you could see we're gonna do like engine upgrade you can see we're gonna get level four right here so I'm just making sure it's the same you know wording and whatnot and so that's that we're gonna give ourselves transmission I probably spell that wrong the transmission is equal to race transmission and then what we're gonna do is get rid of that and we're also gonna give ourselves the best suspension okay okay I thought I'm smelling song not so I'm also gonna give us a new horn so orange is equal to sad okay just like that and you can see actually if I copy this and go into upgrades I can find it right here so we're giving ourselves horn the horn that we were gonna want is sad trombone so I'm just gonna copy that word-for-word and I'm also gonna give us what are we gonna get we're gonna give us some brakes brakes is equal to race brakes and I'm really good at this okay race brakes and then we're also gonna give ourselves some xenon lights so to do that we're just gonna do lights is equal to scene on lights and then we're gonna give ourselves turbo to turbo and then turbo is equal to turbo tuning so the way I'm structuring this is let's say we want you know we're gonna want these lights and you go into upgrades you can see that lights right here this is the category and I'm making that string equal to that and then we're gonna loop through the types part of that and we're gonna get the xenon lights and the index is equal to true this is this this value it's gonna be the value that we set and you'll see how when we iterate through this how this works so let me just see if I made any mistakes spelling you're just gonna copy that oops I just come back I just fixed formatting okay take mess up anything I'm good okay so we're fine um so now what we want to do is actually we're just gonna iterate through these we're just gonna iterate through them now our selection with our selection and upgrades dot Lua so to do that we're gonna do so before we actually do anything we need to do set vehicle mod kit vehicles than zero you have to do this before you apply any mods and then so let's let's now look through the let's loop through this table right here so to do that we're gonna get the key and the value so for K comma feet in the pairs of our selection and I do okay so now what we want to do is I'm sorry I'm back not by the way so now we want to do is we're gonna enter or loop through this our selection and while we're gonna do that we're gonna create a local mod type is equal to upgrades of K tap type and you can see mod type is gonna be using this upgrades down lua you can see it right here upgrades of the category K dot type and dot type is the mod type which is the number like I said before the first ten types are like body features so this is the type so now I want to get the local mod itself is equal to upgrades of K dot types of V dot index and I'll go back to and show you so let's say we're getting armor we're gonna get dot types of the value which is let's say we had you know we had the armor upgrade of ten dot index which is gonna return for so that's what that means that's what the mods gonna be and that's that's what we need to do and now what I'm gonna want to do is usually you would do or is it set vehicle mod but since we're using some toggle vehicle mod to in functions Lua that's not it functions that little I created a function that will apply the vehicle mods so if the mod type is boolean so like I know turbo yeah turbo tuned tuning has boolean you can't set billions in the set vehicle mod native so you need to use another native called toggle vehicle mom so if it's this is what this functions is gonna do and we're gonna be using this function instead link in the description for all these all this stuff so we're gonna be using this because if the type of the mod is bullying then we have to use this native so let's do that now I'm gonna do apply Bicol mod and then when you're using V so I remember this is not a native this is a custom function that is using natives so yeah so the first parameter is vehicle the second one is mod type and then the third one is just mom just like that and and and then outside of here let's give ourselves the color that we just talked about up there sets vehicle [Applause] colors.they that's the first parameter and the second parameter third parameter are primary and secondary colors I don't really want a secondary color don't care and yeah that's pretty much it for that so remember color variable is matte red we're just gonna make it in that red that's what the car is gonna be and then let's give ourselves some headlights so remember lights uses the toggle vehicle not in set a set vehicle month so toggle vehicle mod is a vent and then the second parameter is upgrades of lights dot type that's the learner type is the what's called mod type that is using that index so that's the second parameter which is mod type for toggle vehicle on and the third parameter is the mod itself so that is a different index so we're gonna be using what's called what we're gonna be talking about that after we set this so we need to do that so set it to true because we're giving ourselves the delights I'll show you lights is just true we need to set that to true and then once we do that once we equipped the xenon lights then we will do set vehicle xenon lights but its allure that's a native and first thing is vehicle the second one is upgrades this will be the color that we want so I have this colors will be defined in this upgrades that Lola so lights dot zine you know I had had light colors of red dot index what that is is lights dot xenon headlight colors and we're gonna give ourselves the redhead light color so that's how you do that I spelled that wrong by the way I said colors I don't even know but make sure you make sure spell that right so I had like colors just like that and that will give us the funny looking colors for that so that's pretty much it for this script I'm going to go into the video now and run this show you how this works okay so I'm in my server now and let's go ahead and spawn in the vehicle so I do slash vehicle spawn let's get the Fudo because that is a highly customizable car so we got the food out here and let's give it the let's give it the first ten upgrades so customized customized vehicle customized and you can see that we got a spoiler we got some new fender upgrades we got carbon hood or something like that and you could see this that exhausts changed and yes so I think the speed is gonna be the same now but let's do such vehicle extras let's see if there are any extras I know this car doesn't but I know a car that does have extras the contender and there there we go this won't actually work let me try again there we go if you do extras it'll get rid of that extra I guess that's like inversed but let's do let's go back into this photo here and let's do slash vehicle repair so I'll be getting scuffed up a bit and we crash it right here you can see it crashed I'm doing such vehicle repair just like you know brand new I'm gonna do so what else is there there's there's doors that's vehicle doors this should open every single door of our car let's just close the back up and let's do such a vehicle up right now upgrade and this should make it mad red the headlights I don't know why the headlights are not that color but you can see that you know it's a lot faster now and let me check why this isn't working ok so it seems to me that I've made a mistake here this is supposed to be Capital red make sure it's case sensitive when you're doing this stuff so I did lower case red so now that it's upper case red it should give me it let me restart the script not a restart vehicle just like that's and I'm gonna do vehicle upgrade and now we have the red headlights that looks really like that looks bad but I mean you know this is for demonstration you could see that we have all the upgrades now for this car and you've given it initially you saw how it spawned in golden golden car with pure gold and now we have given its other properties that's pretty much it for this video hope you guys enjoyed it thank you for being patient on me it's been a while since I've uploaded last time and thank you for the patrons also supporting my content and I hope you guys enjoy this video I'll be making more videos there's a lot more vehicle stuff to cover and I plan on covering that stuff too so hope you guys enjoy the video and thanks for watching
Info
Channel: Jeva
Views: 33,601
Rating: undefined out of 5
Keywords: Fivem, zua, fivem scripting, fivem coding, fivem lua, how to code, lua, gta v modding, gta v scripting, gta 5 scripting, gta 5 modding, fivem roleplay, fivem rp, vehicle mods gta, vehicle gta, gta mod, gta v car mods, car mods, car paint, cars, gta 5 cars, fivem setvehiclemods
Id: 6LYL2A5UShQ
Channel Id: undefined
Length: 33min 59sec (2039 seconds)
Published: Sat Jul 11 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.