spAik Posted June 10, 2014 Share Posted June 10, 2014 Hi, i want to download files in the background. For this I first found the mta 1.4 function downloadFile. As I dont use 1.4 yet, i used the communityresource downloadFile. It works. But if I use it with ipairs it just downloads all files at once, which causes big lags on my local svr. So I just want it to start downloading the first file which is not yet in the client resources and then stop the ipairs loop after the first result. Is that possible? local Files = { ":admin3R/client/images/warning.png", ":admin3R/client/images/error.png", ":admin3R/client/images/question.png", ":admin3R/client/images/info.png", ":admin3R/client/images/dot.png", ":admin3R/client/images/search.png", ":admin3R/client/images/dropdown.png", ":admin3R/client/images/colorscheme.png", ":admin3R/client/images/empty.png", ":admin3R/client/colorpicker/sv.png", ":admin3R/client/colorpicker/cursor.png", ":admin3R/client/colorpicker/blank.png", ":admin3R/client/colorpicker/h.png", } function downloadFiles () for i, data in ipairs(Files) do if not fileExists(data) then downloadFile(data,data,500) end end end addEventHandler("onClientResourceStart", getRootElement(), downloadFiles) addEventHandler("onClientFileDownloadComplete", getRootElement(), downloadFiles) Link to comment
qaisjp Posted June 10, 2014 Share Posted June 10, 2014 "return". Below line 20 put "return" It stops the function. Link to comment
#DRAGON!FIRE Posted June 10, 2014 Share Posted June 10, 2014 if in local yes u get lag .. bcs Local is bad local Files = { ":admin3R/client/images/warning.png", ":admin3R/client/images/error.png", ":admin3R/client/images/question.png", ":admin3R/client/images/info.png", ":admin3R/client/images/dot.png", ":admin3R/client/images/search.png", ":admin3R/client/images/dropdown.png", ":admin3R/client/images/colorscheme.png", ":admin3R/client/images/empty.png", ":admin3R/client/colorpicker/sv.png", ":admin3R/client/colorpicker/cursor.png", ":admin3R/client/colorpicker/blank.png", ":admin3R/client/colorpicker/h.png", } function downloadFiles ( ) for i, data in ipairs(Files) do if ( fileExists( data ) ) then return else downloadFile( data, data, 500 ) end end end addEventHandler( "onClientResourceStart", root, downloadFiles ) addEventHandler( "onClientFileDownloadComplete", root, downloadFiles ) Link to comment
qaisjp Posted June 10, 2014 Share Posted June 10, 2014 if in local yes u get lag .. bcs Local is bad local Files = { ":admin3R/client/images/warning.png", ":admin3R/client/images/error.png", ":admin3R/client/images/question.png", ":admin3R/client/images/info.png", ":admin3R/client/images/dot.png", ":admin3R/client/images/search.png", ":admin3R/client/images/dropdown.png", ":admin3R/client/images/colorscheme.png", ":admin3R/client/images/empty.png", ":admin3R/client/colorpicker/sv.png", ":admin3R/client/colorpicker/cursor.png", ":admin3R/client/colorpicker/blank.png", ":admin3R/client/colorpicker/h.png", } function downloadFiles ( ) for i, data in ipairs(Files) do if ( fileExists( data ) ) then return else downloadFile( data, data, 500 ) end end end addEventHandler( "onClientResourceStart", root, downloadFiles ) addEventHandler( "onClientFileDownloadComplete", root, downloadFiles ) You clearly do not know how to script so get out unless you're asking for help. Ignore him. His code is wrong. Link to comment
Moderators IIYAMA Posted June 11, 2014 Moderators Share Posted June 11, 2014 @# ZĀ!ـحF ๛ wrote:if in local yes u get lag .. bcs Local is bad YOU ARE BAD, HA! @spAik cheers for 1.4 when it comes out! local Files = { ":admin3R/client/images/warning.png",--1 ":admin3R/client/images/error.png",--2 ":admin3R/client/images/question.png",--3 ":admin3R/client/images/info.png",--4.... ":admin3R/client/images/dot.png", ":admin3R/client/images/search.png", ":admin3R/client/images/dropdown.png", ":admin3R/client/images/colorscheme.png", ":admin3R/client/images/empty.png", ":admin3R/client/colorpicker/sv.png", ":admin3R/client/colorpicker/cursor.png", ":admin3R/client/colorpicker/blank.png", ":admin3R/client/colorpicker/h.png" } local downloadIndex = 1 local downloadTimer local downLoadFilesInTime = function() local result = false repeat local file = Files[downloadIndex] if file and not fileExists(file) then result = downloadFile(file) -- downloading ? true/false end downloadIndex = downloadIndex+1 -- count up 1,2,3,4..... until result or downloadIndex > #Files -- if those conditions are true, it will stop looping. if downloadIndex > #Files and isTimer(downloadTimer) then killTimer(downloadTimer) end end local downloadFiles = function () downloadTimer = setTimer(downLoadFilesInTime,1000,#Files)-- a timer for downloading end addEventHandler("onClientResourceStart", root, downloadFiles) addEventHandler("onClientFileDownloadComplete", root, downloadFiles) Link to comment
#DRAGON!FIRE Posted June 11, 2014 Share Posted June 11, 2014 No .. i just fix it if FileExist return else and i know his code is wrong. !! 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