Jump to content

Eficient use of triggerLatentClientEvent and fileGetSize?


Axel

Recommended Posts

Hi!

So i am making my custom download system that downloads all my server files (from .ttf to .txd) when the player is online, eg. for images shows a blank image, and after it finishes the download, replaces the blank image with the actual image. The thing is i finished the system and i was using:

        local file = fileOpen( path ) 
            local bites = fileRead ( file, fileGetSize(file) ) 
            fileClose(file) 
            triggerLatentClientEvent(client, 'uploadCustomClientFile', 494304, false, client, bites, path) 

The problem it is that it was using alot and when alot of players were online, it was lagging the server. So i changed to:

  
            local file = fileOpen( path ) 
            local size = fileGetSize(file) 
            local bites = fileRead ( file, size ) 
            fileClose(file) 
            if size > 131072 then -- 1mb 
                size = size/10 
                --outputChatBox(size) 
            end 
            triggerLatentClientEvent(client, 'uploadCustomClientFile', size, false, client, bites, path) 
  

Does somebody know a better method or way of handling the downloads with triggerLatentClientEvent and fileGetSize? I need to use them both becouse the file sizes differ. I don't want the download to be too slow, but it should not consume that much eighter. Thanks in advance.

Link to comment
  • MTA Team

Your method reads the complete file everytime somebody requires it (if you don't save it on your client's disk). Your server blocks until the file has been read. If 3 players connect and request your file then it will block your server 3 times (time outs may occur), because you don't keep the file content in memory.

Link to comment

Well, i save the file to my client's disk and if he needs it anytime when playing, loads from there. But about not keeping the file content in memory, should i insert the file bites in a table like files[path] = bites and if somebody else requests the file to load it from there?

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...