knash94 Posted December 20, 2011 Share Posted December 20, 2011 (edited) Download functions Ever wanted to make background downloads? Such as a car model but without making your client downloading that model as soon as he joins the server and delay his play? With these download functions you can make it possible to download such models in the background without any need of any meta config, just place the file into the resource and make a script using these new functions to make this possible. Resource requires permissions in the admin acl so it can read the files, simple add object "resource.download" into your admin group acl. Client functions: downloadFile (string fileFromServer, string saveAs, int interval) -- Interval is how long between each time the server sends the client some data, I'd reccomend this being at about 200 to avoid lagging the server. getClientFileSize (string theFile, string type) -- Types: "MB", "KB", if blank will return bytes. Server functions: getServerFileSize (string theFile, string type) -- Types: "MB", "KB", if blank will return bytes. Server events: onDownloadFail --Parameters: String serverFile, String clientFile onDownloadComplete --Parameters: String serverFile, String clientFile onDownloadPreStart --Parameters: string clientFile, int interval, bytes fileSize, int transferTimes Client events: onClientDownloadPreStart --Parameters: string clientFile, int interval, bytes fileSize, int transferTimes onClientDownloadComplete --Parameters: string clientFile onClientDownloadFail --Parameters: String serverFile, String clientFile Example of usage. addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function () exports.download:downloadFile("sometexture.txd", "infernus.txd", 500) end addEventHandler("onClientDownloadComplete", getRootElement(), function (theFile) -- Right now I made a mistake which I'll fix later which makes it so you see the whole path of the file, for example :/your-res/infernus.txd instead of infernus.txd if theFile == ":/your-res/infernus.txd" then local theTXD = engineLoadTXD ( theFile ) engineImportTXD ( theTXD, 411 ) end end Please report any issues you have with my script here please, I'll try as quick as I can to fix it ! Download link. Edited December 21, 2011 by Guest Link to comment
Castillo Posted December 20, 2011 Share Posted December 20, 2011 Nice one, keep up the good work mate! Link to comment
DakiLLa Posted December 20, 2011 Share Posted December 20, 2011 Hmm, looks promising. Gonna test it right now Link to comment
knash94 Posted December 21, 2011 Author Share Posted December 21, 2011 Thanks for the comments guys, please let me know if you come across any errors. Also on the return of onClientDownloadComplete do you think it should return something like ":/your-res/infernus.txd" or "infernus.txd", in my opinion with it returning the resource name within it could be handy. Link to comment
ThaD4N13L Posted December 21, 2011 Share Posted December 21, 2011 Nice Job keep up the good work Link to comment
Eht1 Posted December 21, 2011 Share Posted December 21, 2011 I have some questions. 1. I need place download.zip in my resource.zip? 2. I need in my resource.zip add lua file with this code : addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function () exports.download:downloadFile("sometexture.txd", "infernus.txd", 500) end addEventHandler("onClientDownloadComplete", getRootElement(), function (theFile) -- Right now I made a mistake which I'll fix later which makes it so you see the whole path of the file, for example :/your-res/infernus.txd instead of infernus.txd if theFile == ":/your-res/infernus.txd" then local theTXD = engineLoadTXD ( theFile ) engineImportTXD ( theTXD, 411 ) end end ? Sure i will change this code for my script Link to comment
knash94 Posted December 21, 2011 Author Share Posted December 21, 2011 Thanks Daniel, Eht1, Yeah place it in resources and start it up. Whatever code you make, it doesn't have to be used in this resource. You can make a seperate resource and call the functions via that by simple putting exports.download:functionName(args), this was just an example but you can use it as a reference. Link to comment
Sharingan Posted December 21, 2011 Share Posted December 21, 2011 Good job, for sure I'm gonna use it. Link to comment
knash94 Posted December 21, 2011 Author Share Posted December 21, 2011 This not work for me Sorry forgot to add to the post, you will need to add object "resource.download" into the admin group acl, tell me if it isn't still working after this. Link to comment
denny199 Posted December 22, 2011 Share Posted December 22, 2011 I had got the same problem but now it's giving a bad argumant @ "fileOpen", in the resource download mayby you could make a example script and upload it on the community Link to comment
Eht1 Posted December 22, 2011 Share Posted December 22, 2011 This not work there is code for my car : addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function () exports.download:downloadFile("infernus.txd", "infernus.txd", 411) exports.download:downloadFile("infernus.dff", "infernus.dff", 411) end addEventHandler("onClientDownloadComplete", getRootElement(), function (theFile) if theFile == ":/infernus_play4/infernus.txd" then local theTXD = engineLoadTXD ("infernus.txd", 411 ) engineImportTXD ( theTXD, 411 ) if theFile == ":/infernus_play4/infernus.dff" then local theTXD = engineLoadTXD ("infernus.dff", 411 ) engineImportTXD ( theTXD, 411 ) end addEventHandler ( "onClientResourceStart", getResourceRootElement(getThisResource()), replaceModel) Link to comment
knash94 Posted December 23, 2011 Author Share Posted December 23, 2011 I had got the same problem but now it's giving a bad argumant @ "fileOpen", in the resource downloadmayby you could make a example script and upload it on the community you will need to add object "resource.download" into the admin group acl, tell me if it isn't still working after this. I just realised the event might be a bit dodgey (onDownloadComplete), I'll fix it up tommorow, I should of tested this out a bit more before releasing tbh Link to comment
Ezeck Posted December 11, 2012 Share Posted December 11, 2012 When I run the application, the car will not start please send an example of this feature please = / Link to comment
-.Paradox.- Posted April 5, 2014 Share Posted April 5, 2014 Sorry for posting in an old thread but can somebody see what's wrong here? addEventHandler ("onClientResourceStart", getResourceRootElement(getThisResource ()), function () exports.download:downloadFile ("infernus.txd", "infernus.txd", 500) exports.download:downloadFile ("infernus.dff", "infernus.dff", 500) end) addEventHandler ("onClientDownloadComplete", getRootElement(), function (theFile) if theFile == ":/test/cars/infernus.txd" then local theTXD = engineLoadTXD ( theFile ) engineImportTXD ( theTXD, 411 ) elseif theFile == ":/test/cars/infernus.dff" then local theDFF = engineLoadDFF ( theFile, 411 ) engineReplaceModel ( theDFF, 411) end end) Link to comment
Castillo Posted April 5, 2014 Share Posted April 5, 2014 Why don't you simply use fetchRemote? it's way more efficient if I'm correct. Link to comment
Woovie Posted April 6, 2014 Share Posted April 6, 2014 Why don't you simply use fetchRemote? it's way more efficient if I'm correct. This. Link to comment
-.Paradox.- Posted April 6, 2014 Share Posted April 6, 2014 I would like to use it, but i have no idea how to use it...Can you give me an example code? or just a topic that can help me.Thanks Link to comment
Et-win Posted April 6, 2014 Share Posted April 6, 2014 https://wiki.multitheftauto.com/wiki/FetchRemote Every code is explained on the wiki.multitheftauto.com site Link to comment
DKongHD Posted April 6, 2014 Share Posted April 6, 2014 Looks nice, but why you create a timer for every file that gets downloaded? It would be easier with latent events. Link to comment
Woovie Posted April 7, 2014 Share Posted April 7, 2014 Locking this thread to avoid further confusion. The OP is really old, we have actual functions for this now. Link to comment
Recommended Posts