FiveM Scripting #1 - Creating your first FiveM Resource (spawning & deleting cars)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys it's alpha and this is part one of my 5m scripting series this is creating your first resource in 5m my previous video was setting up a server in 2021 so if you haven't got a server set up already go back and watch that i'll have it linked in the description but if you've already done that then we can continue so the first thing we're going to do is go to our server directory so this is the one we created but because we used the tx admin server deployer it actually created a new directory and it will be called tx data if you go in there and then it should be called something along the lines of this dot base on the end go into that folder and here we've got our resource and server.cfg this is where we were editing yesterday in the uh creating a servo video so we went over the server.cfg yesterday but now we're actually going to be going into the resources folder and we're going to be creating a resource in here so the first thing we're going to do is we're going to create a new folder these are all of the default resources you don't need to touch these just leave them how they are which can create a new folder i'm going to call it something like my scripts make sure that this directory has no spaces in the name because otherwise it won't work so once we're inside of here we're going to create our first script so we're going to call this one my first resource resource and script are pretty much the same thing by the way in case you were unsure so inside of this this is actually our resource folder so everything about the resource is gonna be inside here so something you need for every resource is an fxmanifest.lua if you're coding in lua of course you'll be others for other languages but we're coding in lua so we're going to create a new text document and then grab everything including the dot txt the file name extinction and we're going to type fx manifest dot lua this is changing the file type from a txt file to a lure file once you've done that you can actually open it up i'm using visual studio because this is my preferred code editor and then in here we can actually define the things that we need to actually make it a working resource so we need fx underscore version and then we're going to use cerulean there are a few types of versions that you can use i'm not actually that sure on what they all mean but cerulean works so i advise using that one you're gonna need to define the game so i'm gonna do gta 5 then these are some optional things that i like to put author so that's just you know you you can do a description of the resource and you can do a version and then the things that you're going to need to define for today's script is a client script you can also do server script and other data files but all we need is a client script today and we're going to call it client.lua that's all we're going to need so we can save that and close it now we're going to make another lua file inside this same directory and we're going to call this one client.lua now we can go inside of this one so this is the client-side um operations of this resource uh for this resource there's not gonna be any server-sided operations so we don't need a server.lure we're just gonna be doing uh coding inside of this file today so we're gonna be registering a command so we're going to register command and then open up some brackets the command is going to be slash car because we're going to be spawning in a car so i'm going to do car you don't need to put the slash because when you're registering a command it automatically has a slash at the front so cart function and inside of this you're going to need source and arguments i'm just going to do args and in this second bracket you can bring down a few lines and then put end comma boss you just need this at the end of the register command function now everything inside should be indented so you can press tab to indent and now we're going to do everything that we need for the command so the first thing i'm going to do is local vehicle name so this is the name of the vehicle that they want to spawn in and then we're going to make it so if their vehicle doesn't get loaded it will just spawn the adder i'm going to add comments along the way guys then you understand what everything does there you go the next thing we're going to be doing is checking if the vehicle actually exists uh so these green parts are comments in lua if you do two dashes that adds a comment so just you don't these don't actually do anything in the code these are just to make sure that you understand what each part of the code does so this is just a native is vehicle in cd image it is modeling cd image and then obviously the model name and then if that's not then it will do this just to double check is model a vehicle then we're going to be doing is triggering an event it's going to be adding a message in chat to let the player know that the vehicle doesn't exist you need the curly brackets and then you can put whatever you want really i'm just going to put vehicle not recognized so this will come up in the chat for the player and what we're going to do is we're going to add the vehicle name what they typed in just like that and then what we're going to do is return value and then we can end this if statement so if the vehicle it does actually exist then we're going to load the model then we're going to wait for the model to load so it's just a while statement so why it hasn't loaded we're just going to be waiting uh this number in here is in milliseconds so it's just half a second now we're going to be getting the player's position so we're going to need two local variables for this we need player pen i'm going to use player pet id to get the id of the player and i'm also going to need a local position i'm just going to do plus that's using as you can see i've defined player pad and we're using it in the parameters of this auto shutdown initiated now we're going to be creating the vehicle so we're creating a variable for that as well so we're gonna need the vehicle name and i'm gonna need the position so pause dot x comma pos dot y comma pause dot z and then also we need to get the entity heading which is the direction that your player is facing you just need these true and pulses on the end i'm not entirely sure what they do but you do need them now we're going to set the player head into the vehicle's driver seat now we're going to be giving the vehicle back to the game so this just means the game decide when to despawn the vehicle so you guys don't actually need to put these comments but if you do want to have a greater understanding of what each part does then i do recommend adding them now we're going to be releasing the model there we go so now we need to do is tell the player that we spawned it in we're just going to do another chat message so it's just adding a message into the chat scroll down for you and now we're going to be notifying the player that they have spawned a vehicle so then what we're going to do is stop there and then add in the vehicle name these two dots are actually concatenating the string so it's just adding in you know the vehicle name as text to this message so what i'm going to do on the end is full stop you don't really need to do that but i've decided to so that's all we need for the command car so this will spawn in a car i'm also going to make one more command to delete the vehicle so we can save now just to make sure it's saved and outside of this command so no more no longer indented i'm going to register another command and this one's going to be called db if i delete vehicle so this one doesn't actually need um source or argus inside of the functions parameters because um we're not actually passing any um arguments such as you know the vehicle model name that you're trying to spawn in you're just trying to delete the vehicle wherever you're in still need to end on the false to end the command and then everything inside is going to be indented so now we're going to get the local player it's the same as what we did earlier really i'm going to get the vehicle the player is in a mistake i made earlier was um i put vehicle get vehicle players in it needs to be get vehicle ped is in otherwise it won't work so make sure that you correct that to be get vehicle padded and then we're going to delete the vehicle there we go so that's all we need for the dv command so that's everything we actually need inside of the client.lure now we can close this and we can continue to actually start the command in the server.cfg so we can close that and then we can go back out of the resource out of my scripts out of the resources folder all the way back to the server.cfg now we can open that up and now here you can see these resources will start by default so these are the resources that are in the other folders in the resources directory so what we can do is just go below that and then type either start or ensure i'm just going to ensure and then it's got to be the exact name of the resource so ours is called my first resource you might have named yours something different the name that you're looking for is the name of the folder where your client.lure and fxmanifest.lua are so mine's called my first resource so i've to i've done ensure my first resource that's all you need to do to get the resource to start in your server so i'm just going to save that and now we can close that and now we can actually start up the server so i'm going to go back out and then go into the home hosted 5m server and start up the fx7 ef cfg or exe3 and as you can see this is showing us starting all of the resources so as you can see it's starting you know map manager yarn webpack chat all those as you can see here started resource my first resource so here we can see that there's no errors in starting the resource and it's decided just fine if it says could not find resource and then the name that means that you've mistaken the spelling of your resource or you've got some some mistakes such as like a space in the name you can't have any spaces remember but if it's started up just fine then you should be good to join your server so that's what i'm going to do now i'm going to launch 5m and just like before localhost and this will join your locally hosted server now that we've spawned in we can go into the chat and by doing a slash you can see all of the available commands as you can see we've got slash car and slash dv in there that's because we've registered registered them as commands so if we do slash car and a space now we can put in the model name of the vehicle so let's say we want to do an adder you can do that and as you can see it's just spawned in a car turn off the music as you can see and then we can just drive around the car normally and then if we want to delete it we can do dv which doesn't want to work i see what i've done i need to get vehicle pedis in not uh player is in i need to restart it there we go there we go now it's working so yeah you can do slash car and then any model name as long as it exists and then you can do slash dv to delete it this doesn't only work with vehicles that you spawned in you can do it with any vehicle really as long as you're in it so you could just steal a car from an air and then delete that anyway that is all for today's scripting tutorial uh i hope you enjoyed i hope it all worked out for you if you have any issues uh don't be afraid to join the discord links in the description and i can help you out through there as always if you enjoyed hit the like button subscribe and share with all your friends leave a comment all that and uh thanks for the support i'll see you in the next one goodbye
Info
Channel: Alfa
Views: 41,245
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 #1 - Creating your first FiveM Resource (spawning & deleting cars), spawning car, lua, resource, server, deleting car, /car, /dv, command, walkthrough
Id: vz-eZv_cUGQ
Channel Id: undefined
Length: 17min 45sec (1065 seconds)
Published: Tue Feb 16 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.