Client downloading

I’m making my custom gamemode and forgot one vital part for it.
I need to know what the code was for clients to download and install server files automatically when joining the server.
I totally forgot what the code was for it. Someone please help.

Do you people read the wiki or just type random shit into your editor?

I tried to look for it there but I couldn’t find it. Thanks for the solution.

And I came across this when on the website sent above:


function AddDir(dir) // Recursively adds everything in a directory to be downloaded by client
	local list = file.FindDir("../"..dir.."/*")
	for _, fdir in pairs(list) do
		if fdir != ".svn" then // Don't spam people with useless .svn folders
			AddDir(dir.."/"..fdir)
		end
	end
 
	for k,v in pairs(file.Find(dir.."/*", true)) do
		resource.AddFile(dir.."/"..v)
	end
end
 
AddDir("models/yourmodels")

My question is do I need to fill in the blanks where it says:


(.."/*")

with the folder which the dictionary is being created of or just fill in the bottom with the folder?

That code is outdated and won’t work. Just like that website is outdated.



function AddDir( dir ) // Recursively adds everything in a directory to be downloaded by client
    local files, list = file.Find( dir.."/*", "GAME")
    for _, fdir in pairs(list) do
        if fdir != ".svn" then // Don't spam people with useless .svn folders
            AddDir(dir.."/"..fdir)
        end
    end
 
    for k,v in pairs( files ) do resource.AddFile(dir .. "/" .. v ) end
end
 
AddDir("models/yourmodels") -- You use this function to add new folders and such

This code is untested, but should work.

I leave it as is and just fill in the “AddDir(“models/yourmodels”)” at the end?

Fill in “AddDir(“models/yourmodels”)”

You would do the following code:


function AddDir( dir ) // Recursively adds everything in a directory to be downloaded by client
    local files, list = file.Find( dir.."/*", "GAME")
    for _, fdir in pairs(list) do
        if fdir != ".svn" then // Don't spam people with useless .svn folders
            AddDir(dir.."/"..fdir)
        end
    end
 
    for k,v in pairs( files ) do resource.AddFile(dir .. "/" .. v ) end
end

Once and then you just add the Dictionaries after that?

Yes. You declare the function once and the call it as many times as needed.



AddDir("models/yourmodels")
AddDir("sound/yousounds")


Now when I’m attempting to join the server, its bringing me in the game then immediately kicking me for “Too many lua errors”
I don’t know what could possibly going wrong i’m looking for bugs.

Edit: I found an error in the Dictionary code:

lua: init.lua:69: ‘then’ expected near ‘=’

Line 69:


 if fdir != ".svn" then

Someone please help!

I just ran the code I provided and it worked with no errors, means you have error somewhere else in your code.