Jump to content

Tables


DarkByte

Recommended Posts

Posted

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

When I hear someone saying Mac is better than PC.

o0pjNKG.gif w0t?VeJXjxD.gifw0t? evspcFJ.gifw0t?

Great minds discuss ideas, average minds discuss events and small minds discuss people.

Posted

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!")

When I hear someone saying Mac is better than PC.

o0pjNKG.gif w0t?VeJXjxD.gifw0t? evspcFJ.gifw0t?

Great minds discuss ideas, average minds discuss events and small minds discuss people.

Posted

i don't recommend you to use DownloadFile "onClientPlayerSpawn".

Read the note : This function may cause performance issues with client and/or server.

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted

I replaced it with onClientResourceStart. And I always get these errors.

saV6I2B.png

When I hear someone saying Mac is better than PC.

o0pjNKG.gif w0t?VeJXjxD.gifw0t? evspcFJ.gifw0t?

Great minds discuss ideas, average minds discuss events and small minds discuss people.

Posted
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

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted

280 mbs for mods, no

Could you fix my code? I got a lot of errors

When I hear someone saying Mac is better than PC.

o0pjNKG.gif w0t?VeJXjxD.gifw0t? evspcFJ.gifw0t?

Great minds discuss ideas, average minds discuss events and small minds discuss people.

Posted
280 mbs for mods, no

So the The solution is:

1) Remove fileExists().

2) Always call downloadFile for files with download="false".

3) Only use the file after onClientFileDownloadComplete is triggered.

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted

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 
) 
  

When I hear someone saying Mac is better than PC.

o0pjNKG.gif w0t?VeJXjxD.gifw0t? evspcFJ.gifw0t?

Great minds discuss ideas, average minds discuss events and small minds discuss people.

Posted

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) 
  

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted

It's replacing, same errors in debug and every time i spawn they replace

When I hear someone saying Mac is better than PC.

o0pjNKG.gif w0t?VeJXjxD.gifw0t? evspcFJ.gifw0t?

Great minds discuss ideas, average minds discuss events and small minds discuss people.

Posted
It's replacing, same errors in debug and every time i spawn they replace

1) Check your meta.xml file.

2) Check mods path.

3) Try using outputDebugString to see what the problem is.

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

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