Jump to content

Is this possible?


Rotti

Recommended Posts

Hello,

I have a lot of carmods on my server. But if a new Player connects he has to wait very long until the carmods are downloaded.

So is it possible that the carmods will download after he has logged in?

So that the new player connects, everything will download, the login gui comes, he logs in and then the carmods begin to download so that he can play while the carmods are loading.

Link to comment

No, it isn't. There is a list of functions and events in the description of the resource. The syntax of the function downloadFile is the following:

boolean downloadFile ( string filePath, string savePath, int interval ) 

  • I added a symbol before 'boolean' because the function only returns a boolean value (false) when something doesn't go right, like the arguments are invalid.
  • filePath - This is the path (including file name and extension) to the file you want to download.
  • savePath - This is the path where the file will be saved (client's computer - root path is %MTA_FOLDER%/mods/deathmatch/resources)
  • interval - This is the interval, in milliseconds, between each client event trigger (basically this is the interval between each data sending). Setting a very low interval is not recommended.

Edited by Guest
Link to comment

Well, call the function for all files in the resource.

The function copies the file content to the client's computer (I don't recommend using this for client scripts, instead use the cache attribute in the 'meta.xml' file) - the good thing here is that it's faster and there's no download bar on the screen.

Link to comment

ok ok its a bit difficult to understand for me.

will it work if i have a folder on my server where the script and the meta of the carmods are. And i have a folder where only the model files of the carmods are. Then i tell a resource that it should download the files on the computer off the client, in a folder named like the folder on my server.

Link to comment

ok i just want to ask:

How does it works?

How can i do that?

in my foulder is

the script.lua

the meta.xml

infernus.txd

and infernus.dff

so i think the infernus.txd and the infernus.dff must be downloaded

can you give me an example that will work?

and should i change something in the meta?

Link to comment

  • How does it work? It opens the file and sends the bytes of the file (content of the file, in an "easier" English) to the client by parts (sending big files in one time would lag and probably give the very known "Network trouble" error infinitely). Then the client saves the bytes into a new file with the same name and extension in the cache.
  • How can I do that? Use the function downloadFile from that resource. I showed you the syntax in a reply above. Create a new script file (client side) and (optionally)add the cache attribute in the 'meta.xml' file for it (search the wiki about that attribute if you don't know where to put it or what it does). Inside the file, write for example:
    downloadFile ( "infernus.dff", "infernus.dff", 1000 ) --first argument passed is the path to the file in the server, second argument is the path to where the file is going to be saved in the client's cache, the third argument is the interval between each event triggering (where it passes the data to the client). 
    

Here is an example:

addEventHandler ( "onClientResourceStart", resourceRoot, 
    function() 
        downloadFile ( "infernus.dff", "infernus.dff", 500 ) 
        downloadFile ( "infernus.txd", "infernus.txd", 500 ) 
    end 
) 
  
addEventHandler ( "onClientDownloadComplete", root, 
    function( strFile ) 
        if( ( strFile == "infernus.dff" ) or ( strFile == "infernus.txd" ) )then 
            --load model 
        end 
    end 
) 

I guess this was clear now, tell me if you're getting any problems.

Edited by Guest
Link to comment

You can remove them from the 'meta.xml' (not totally sure, but I guess only client-side file functions need them added to the 'meta.xml' file to be able to load them). In case it doesn't work removing them, add them again and use the download attribute with value false in each script.

By the way, I added an example in my last reply.

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...