FiveM Scripting 6 - Creating a Speedometer Using Conditionals and Math (Lua)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] what is up guys my name is Zola from Java today roomie will be creating a speedometer using math functions and conditionals so on the link will be in the description below that there are the code will be and then just like in the description and yeah you guys could go ahead and check that out so let's get started with this resource we're gonna go to our server folder and CFX server dyno master resources and let's create a new resource I just make a media folder calling us if you're new to the channel make sure to subscribe if you haven't subscribed yet please subscribe it helps us out and I like the video if you you know find these tutorials helpful it really helps us out and yeah so let's start off with creating our resource download that's 200 stores resource make sure filename extensions are on too by the way really helps you out with those creating files just like that so let's create a new one and call it down you can tell us but I'm gonna see I think that's what I do in the code do but I mean it's a client script so yeah let's get started with finding the cell applying script local script is understand about Lua that's we have to start off with writing out the code now so let's get right into it so it's between a function and call it text because this function is just gonna draw text on the screen so it'll just be really easy so if you were from if you watch the episode where we draw text and saw that works if you haven't wanted to go ahead check it out probably help you and give you some context what we're doing here so set text font 0 therefore what 0 is like normal one is like cursive two is narrow I think three I don't it kind of gets I don't really remember but let me use the one because it's cursive and it looks ugly and type in set text and then zero text like a little big not too big sets text [Music] [Music] content we're passing through that string through this function so anything that this gets passed through will be written out on this function make sure to go ahead check that video because you probably won't understand but you could also just now where you need to draw the text at the coordinates of our screens of point nine which is far side of our screen and then point seven which is kind of down so point nine and then down like somewhere around here it'll probably be so it's just like a little good placement there and we need to end the function and let's start create the thread for it so it'll constantly refresh how fast we're going if we're in a car so yeah we will do that so first create thread pass through function thread end and then create a while through do if you don't know how to watch rubes think we went over it but whatever the condition in in between the while and the Duke are true it'll always run so if I were to just do one is greater than zero that will constantly run but I'm just gonna keep it to true because true is just true all right and in here we're going to need the citizen not wait we're still two mill two milliseconds so every two ticks I think that's what it means it'll run and you it's really important to have this relative resource will just crash you in something so local speed is equal to you get any tea speed this is a native that against the speed of anything so in here this accepts a parameter of what you're trying to get the speed of so let's get the speed of get vehicle head is and then the pad that we're referring to is get player and minus one which is us and because we're that's just what this function requires and then in here I've actually outside you can write or you have to multiply it by either if you're doing km/h it's going to be three point six that's the factor and if you're doing miles per hour I'll just write this in a comment right here block comments are like that and you type it out like that so in here we can type in km/h equal to 6 and then miles per hours factor factor you want to multiply with its two point three or two point two three six nine it's that's just what it is in GTA but this is a native so I'm I'm from America so I'm going to just use miles per hour instead of kilometers per hour so yeah now we need to check we need to write a condition so I'm gonna write a little comment here to check a vehicle just so it doesn't always show our speed you know if we're walking or running you can do that if you want to get rid of this condition yeah so I'm gonna do if is head in any vehicle get Blair ped is one common false so if it's in any vehicle if our pen which is and then this is as false as in any vehicle then I'm gonna write an end for this function because I eat or for this conditional because I always forget to do that and in here we're going to use the function that we created up here text it's a little draw and then math dot blower speed you'd also do math dot seal which goes in here I'll show you how that works so Iraq she wrote it right here let's let's say or let's write a point here so one point two floor functions usually go back one so it goes to its base and it goes so let's say we had minus or point minus 0.2 it'll always go to the the last number before even if it's a negative number so let's say that was point two it go to minus 1 or minus 0.2 it'll go to minus one it was one point two it'll just go to one that's what floor is and even if it's let's say like point seven it'll still go back you should probably wrote that in this color they'll always go back and then let's say if it was one or it was at minus point five it'll always for sealing it'll always go up one so if this was one point five it'll go to two always so it just depends on what you want it's probably a bad diagram sorry but that ceiling usually goes up and floor usually goes down left on the number line and then C then goes right on the number line this is just a good way to visualize it so I like to just do floor you could do ceiling if you want it doesn't really matter it's gonna be a little inaccurate heading there's a round to there which is probably more accurate but I wanted to show you how this works so yeah I'm gonna go up add just to my resources that CFG that we've configured in our one of our episodes start and yeah I'll see you guys in the server in a second alrighty so I just join my server and yeah so I'm gonna spawn in a car from that random table that we did up and not me otherwise it slashed I was gonna spawn a random car here um slash car from that episode that we did about spawning it for random tables so yeah it's a pretty bad place to drive it but uh yeah as you can see that is really loud for me probably not for you as you can see the it works you get the little number on the right you can also set the text color if you check out the text and rectangle video that we draw text and draw rectangles on the screen let's see you could also do a bunch of more stuff with this like I started do like too and then restart it or not I mean to say hi restarts you can see that you get like a little more modern kind of thing you could also just add like what is it after content it could be like mph so if I were to restart it as you can see yeah that's a little off-center if I were to move that to like point eight five and then a space there I actually probably make it point eight yeah you can see that point eight is not good as you can see that that does work how you want it to work hopefully and yeah I mean hopefully this is a really interesting video and it helps you out if it did make sure to subscribe like our video join a discord all those links will be in the description the code will be in the description and yeah you guys enjoy this video and have a good one
Info
Channel: Jeva
Views: 93,000
Rating: undefined out of 5
Keywords: FiveM scripting, Fivem jeva, Fivem modding tutorial, fivem scripting tutorial, fivem how to, fivem how do, zua, jeva, JEVA, wesley, fivem roleplay, roleplay, gta 5 modding, gta 5 scripting, gta v modding, gta, zuacp, wes, jeva discord, discord, discord.gg, yea, math.ceil, math.floor, math, lua, lua scripting, lua scripting tutorial, learn code fivem
Id: 4cGPHJh1G5E
Channel Id: undefined
Length: 11min 6sec (666 seconds)
Published: Mon Nov 26 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.