Jump to content

Tables


DarkByte

Recommended Posts

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

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

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

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

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