FiveM Scripting #2 - How to Reduce Server Lag (STOP DESYNC)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys it's alpha here and welcome back to my 5m scripting tutorial series this is episode 2 and this episode is going to be all about reducing your server's lag so you may not have actually seen my previous ones you may be coming here new to my channel because you're a server owner or developer and um your server's got a lot of lag and i'm gonna be showing you how to reduce that um if you've been following the series so far and you haven't actually got a fully fledged out server yet you can still do this because it can help you in the long run to have much less lag so what we're going to be doing is going to our server directory so obviously in tx data obviously yours may maybe in a different directory but this is where mine is and then we're going into our resources folder and then we can go into my scripts you could be just doing it here or we could actually make a new one so i'm going to call this one utility because this is a utility resource on reducing server lag so inside of utility i'm not going to make the folder for the actual resource we're going to call this one remove all ai because that's what we're going to be doing in this script removing the ai because obviously there's a lot of air traffic and pedestrians in 5m servers and that causes a very large amount of lag so we're removing them or just reducing them depending on what you want to do and that will very much help with server lag so now we're going to make a new text document and then change it to a lower file this is fxmanifest.lua and we're also going to need a client. no server.lua needed in this script there we go first we're going to edit the fxmanifest.lua and we're going to put the usual stuff to make it into a resource so fx version cerulean game uk five author you can put yourself into alpha description a script to remove slash reduce ai to reduce server lag version and now we're going to do client script or not slide client there we go client.lua and we can save that and close that now we're going into the client.lure okay now we're going to be making a thread so that would be citizen dot create thread and then function and then no parameters needed in those brackets for the function now i'm going to do end just before the close bracket for the for the thread and then inside of this thread we're going to do while true do and indented inside of that is citizen dot wait this is just um you know pausing the script for a certain amount of milliseconds so we're just gonna do zero milliseconds so this is every tick it will just wait you do need to have at least um you do need a citizen.weight in inside of these world trues instead of threads otherwise it will just happen too often it would actually break your server i'm just going to add comments so you guys understand what these things do actually leave a little gap and then we're going to do another comment there we go i'm gonna do set traffic density and then here you can put anywhere from 0.0 to 1.0 0.0 totally removes traffic and then 1.0 is the maximum amount of traffic there you go just a little comment to make sure you understand what it means and then we're gonna do set pad density as well this is for the you know civilians walking along the streets i'm gonna set mine to zero as well you don't have to do zero if you don't want to you can just reduce it put it up to 0.5 or whatever you want but i'm going to totally be removing them now something with these scripts is sometimes you will still see some civilians or traffic driving around um i'm guessing this is just because it sometimes slips up and still lets one spawn or it's because um another resource is forcing that ai to spawn um there's nothing you can really do about that it still does a brilliant job at reducing server lag so now we're making a new function for setting the traffic density and then we can add an ends to that and i'm gonna make another function below that called function setpad density and then obviously we've got the the um parameter of density which is referenced up here so these will come in as density there you go so now we're going to go back to traffic density and inside of that we're going to do debt parked vehicle density multiplier this frame quite a quite a mouthful there you go and then it's going to be density and the next one's going to be set vehicle density multiplier this ready i'll make sure i don't misspell any of these yep looks good and then the last one for this function is going to be set random vehicle density multiplier this frame and density inside of brackets again so that's all the three things we need for traffic density and then inside of ped density we're gonna need set head density multiplier this frame and then density inside of there as well and then obviously the last one is set scenario head density multiplier this frame and then density in the brackets of course that's everything we need so these two are going to be reducing your pet density and these three gonna be reducing your traffic density so then obviously the only thing you'll ever need to um configure in this file if you ever want to change it it's just these two values here so now we can save this and that's literally everything for the resource on reducing server lag but that's not the only thing you can do to reduce server link i'm now going to jump into the server and show you what else you can do but before we do that we do need to start this in the server.cfg so i'm going to go out of the server the resource name i'm actually going to copy the name so i can paste it into the server.cfg go out with resources into the server.cfg and then just below my my first resource i'm going to ensure remove all ai just save that and close that now we can actually go out and start up the server there we go we can actually see here started resource removal ai so now it's working just fine now we can actually boot up 5m and jump into the server so now we're going to press localhost and join the server so here we are just spawned in and as you can see there are no vehicles on the road and there's no peds walking along the sidewalk so we can see that the script has worked obviously still got some parts of the map loading in for me got a slow computer but um yeah all of the ais are gone and this will drastically improve server performance but another thing you can do if um if you want to do more than that is you can press f8 to go into the client console and you can go to tools performance resource monitor and then you can you know drag it to make it bigger and this will show all of the resources in the server and then you can sort it by resource name you know how many uh how much it's using the cpu the time the memory and the streaming of assets so if you want to see what's the most impactful resource is you can sort it by cpu msec and then the top one is the most impactful one so as you can see jumping around in there is removable ai just there and it's it's actually got a very low response time 0.05 0.04 that's actually quite average for a chat not for chat but for a resource and so that's quite a good one none of these resources are actually using a lot because they're all just very basic resources but if you've got loads of other resources in your server they can actually be very impactful so you can use this to check which are the most lag inducing resources and you can either optimize them or remove them so that's a good tool you can use um but hopefully this helps with redu reducing your server lag if it did please hit the like button share this with your friends leave a comment and uh just be subscribed to keep up with my vlogging scripting series and you can always join our discords in the description if you need to ask a question to me as always thank you for watching and i'll see you in the next one goodbye
Info
Channel: Alfa
Views: 17,465
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, how to reduce server lag, server desync, laggy server, fix, script, resources, FiveM Scripting #2 - How to Reduce Server Lag (STOP DESYNC), fivem laggy server, gltiching around, network lag, remove ai, resource monitor, texture loss, falling through world
Id: CYguBjRMH68
Channel Id: undefined
Length: 10min 26sec (626 seconds)
Published: Thu Feb 18 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.