RekZ Posted May 7, 2020 Posted May 7, 2020 I have been looking for ways to lower the impact that mod loading has on the client, would it be a good idea to separate the mods by tables and load the mods every 5 seconds ? local WeaponsModels = { ["AK"] = { {FILE="AK/Weapon1" , ID=00000}, {FILE="AK/Weapon2" , ID=00000}, {FILE="AK/Weapon3" , ID=00000}, {FILE="AK/Weapon4" , ID=00000}, {FILE="AK/Weapon5" , ID=00000}, {FILE="AK/Weapon6" , ID=00000}, }, ["CPL"] = { {FILE="CPL/Weapon1" , ID=00000}, {FILE="CPL/Weapon2" , ID=00000}, {FILE="CPL/Weapon3" , ID=00000}, {FILE="CPL/Weapon4" , ID=00000}, {FILE="CPL/Weapon5" , ID=00000}, {FILE="CPL/Weapon6" , ID=00000}, }, } function load() if not getElementData(localPlayer,"login") then setTimer(load,10000,1) outputChatBox ( "Reload" ) return end setTimer(function() for index, weapon in pairs(WeaponsModels["AK"]) do engineImportTXD ( engineLoadTXD ( "models/"..weapon.FILE.. ".txd", weapon.ID ), weapon.ID ) engineReplaceModel ( engineLoadDFF ( "models/"..weapon.FILE.. ".dff", weapon.ID ), weapon.ID, true ) engineSetModelLODDistance( weapon.ID , 100 ) end outputChatBox ( "Mods AK" ) end, 1000, 1 ) setTimer(function() for index, weapon in pairs(WeaponsModels["CPL"]) do engineImportTXD ( engineLoadTXD ( "models/"..weapon.FILE.. ".txd", weapon.ID ), weapon.ID ) engineReplaceModel ( engineLoadDFF ( "models/"..weapon.FILE.. ".dff", weapon.ID ), weapon.ID, true ) engineSetModelLODDistance( weapon.ID , 100 ) end outputChatBox ( "Mods CPL" ) end, 5000, 1 ) end addEventHandler ( "onClientResourceStart", getResourceRootElement(), load ) Admin and Owner of the Pro Chile Community :3
Addlibs Posted May 7, 2020 Posted May 7, 2020 Have you tried engineSetAsynchronousLoading? That will make mods load in their own time instead of freezing the whole client to load before continuing. Of course this means mod loading will be slower, but it won't freeze the client. Previously known as MrTasty.
Moderators IIYAMA Posted May 7, 2020 Moderators Posted May 7, 2020 (edited) 13 hours ago, RekZ said: would it be a good idea to separate the mods by tables and load the mods every 5 seconds I have no idea if engineSetAsynchronousLoading works as Addlibs replied. << I truly hope this solves your issue to be honest But the loading process of that function probably doesn't include the reading of the mod files. In case of loading things in general, I recommend to align the process operation with the user his FPS. Because when you are loading a mod, you are blocking everything, so you can't go to the next frame until it is finished. > That is why loading 2 or more mods on a single frame can cause frame drops. > Large mods will cause frame drops, that is inevitable. If you load a mod every 1, 2 or 3 frames, you will balance performance with processing speed. This example is for loading a mod every frame. Speedy , but with performance impact. So more frames between each execution is better for performance. local table = {{}, {}, {}} function test () local item = table[1] if item then table.remove(table, 1) else removeEventHandler("onClientRender", root, test) end end addEventHandler("onClientRender", root, test) Edited May 7, 2020 by IIYAMA 1 Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now