DarkByte Posted August 13, 2016 Share Posted August 13, 2016 Hello there, I want to make a custom downloader with downloadFile. I found a table on forums but how to loop through it to check all the files to download? {"txd", "mods/m4.txd", 356}, {"dff", "mods/m4.dff", 356}, {"txd", "mods/sniper.txd", 358}, {"dff", "mods/sniper.dff", 358}, Link to comment
DarkByte Posted August 13, 2016 Author Share Posted August 13, 2016 My code: local downloadFiles = { {"txd", "vehicles/tampa.txd", 549}, {"dff", "vehicles/tampa.dff", 549}, } for _, downFile in pairs( downloadFiles ) do downloadFile ( downFile[2] ) end addEventHandler ( "onClientFileDownloadComplete", resourceRoot, function ( file, success ) if ( success ) then for _, downFile in pairs( downloadFiles ) do if ( file == downFile[2] and fileExists(downFile[2]) ) then local txdalp = engineLoadTXD ( downFile[2] ) local dffalp = engineLoadDFF ( downFile[2], downFile[3] ) engineImportTXD ( txdalp, downFile[3] ) engineReplaceModel ( dffalp, downFile[3] ) end end end end ) function checkIfPlayerAlreadyHasDownloaded() for _, downFile in pairs( downloadFiles ) do if ( file == downFile[2] and fileExists(downFile[2]) ) then local txdalp = engineLoadTXD ( downFile[2] ) local dffalp = engineLoadDFF ( downFile[2], downFile[3] ) engineImportTXD ( txdalp, downFile[3] ) engineReplaceModel ( dffalp, downFile[3] ) outputChatBox("replacing") else outputChatBox("client has no carmods, and has triggered the download!") for _, downFile in pairs( downloadFiles ) do downloadFile ( downFile[2] ) end end end end addEventHandler("onClientPlayerSpawn",root,checkIfPlayerAlreadyHasDownloaded) Made it now, but it gives me errors. http://imgur.com/a/pWs7u and it's not showing the text replacing only when im respawning it outputs 2 times outputChatBox("client has no carmods, and has triggered the download!") Link to comment
Walid Posted August 13, 2016 Share Posted August 13, 2016 i don't recommend you to use DownloadFile "onClientPlayerSpawn". Read the note : This function may cause performance issues with client and/or server. Link to comment
DarkByte Posted August 13, 2016 Author Share Posted August 13, 2016 I replaced it with onClientResourceStart. And I always get these errors. Link to comment
Walid Posted August 13, 2016 Share Posted August 13, 2016 I replaced it with onClientResourceStart. And I always get these errors. You are using fileExists to skip downloadFile, but fileExists does not check the file content. downloadFile automatcially checks the existing file first, and will immediately trigger onClientFileDownloadComplete if download is not required. Simply If you are only using downloadFile to download mod files after other resources, then do not use downloadFile, and instead set '-1' in the resource meta.xml Link to comment
DarkByte Posted August 13, 2016 Author Share Posted August 13, 2016 280 mbs for mods, no Could you fix my code? I got a lot of errors Link to comment
Walid Posted August 13, 2016 Share Posted August 13, 2016 280 mbs for mods, no So the The solution is: 1) Remove fileExists(). 2) Always call downloadFile for files with download="false". 3) Only use the file after onClientFileDownloadComplete is triggered. Link to comment
DarkByte Posted August 13, 2016 Author Share Posted August 13, 2016 Still got same messages in debug. local downloadFiles = { {"txd", "vehicles/tampa.txd", 549}, {"dff", "vehicles/tampa.dff", 549}, {"txd", "vehicles/blistac.txd", 496}, {"dff", "vehicles/blistac.dff", 496}, } --[[for _, downFile in pairs( downloadFiles ) do downloadFile ( downFile[2] ) end]] function checkIfPlayerAlreadyHasDownloaded() for _, downFile in pairs( downloadFiles ) do if not ( file == downFile[2] ) then outputChatBox("client has no carmods, and has triggered the download!") downloadFile ( downFile[2] ) end end end addEventHandler("onClientResourceStart",root,checkIfPlayerAlreadyHasDownloaded) addEventHandler ( "onClientFileDownloadComplete", resourceRoot, function ( file, success ) if ( success ) then for _, downFile in pairs( downloadFiles ) do if ( file == downFile[2] ) then local txdalp = engineLoadTXD ( downFile[2] ) local dffalp = engineLoadDFF ( downFile[2], downFile[3] ) engineImportTXD ( txdalp, downFile[3] ) engineReplaceModel ( dffalp, downFile[3] ) else outputChatBox("returned") end end end end ) Link to comment
Walid Posted August 13, 2016 Share Posted August 13, 2016 try this local downloadFiles = { {"txd", "vehicles/tampa.txd", 549}, {"dff", "vehicles/tampa.dff", 549}, } addEventHandler( "onClientResourceStart", resourceRoot, function () for _, downFile in pairs( downloadFiles ) do downloadFile ( downFile[2] ) end end ) addEventHandler ( "onClientFileDownloadComplete", resourceRoot, function ( file, success ) if ( success == true ) then for _, downFile in pairs( downloadFiles ) do if ( file == downFile[2]) then local txdalp = engineLoadTXD ( downFile[2] ) local dffalp = engineLoadDFF ( downFile[2], downFile[3] ) engineImportTXD ( txdalp, downFile[3] ) engineReplaceModel ( dffalp, downFile[3] ) end end end end ) function checkIfPlayerAlreadyHasDownloaded() for _, downFile in pairs( downloadFiles ) do downloadFile ( downFile[2] ) end end addEventHandler("onClientPlayerSpawn",root,checkIfPlayerAlreadyHasDownloaded) Link to comment
DarkByte Posted August 13, 2016 Author Share Posted August 13, 2016 It's replacing, same errors in debug and every time i spawn they replace Link to comment
Walid Posted August 13, 2016 Share Posted August 13, 2016 It's replacing, same errors in debug and every time i spawn they replace 1) Check your meta.xml file. 2) Check mods path. 3) Try using outputDebugString to see what the problem is. Link to comment
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