How do I add the entire addons directory? (IE Models, materials, etc of all mods)

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(“addons”)

would this send the entire addons directory? I am trying to be positive that they have all the models, sounds, materials, resources, etc. How would this be possible? and where would I put the lua code. I tried putting it in /gamemode/sandbox/init.lua. and that made for hell on earth. so. I dont think I will do that again.

This isn’t a very good idea because if you have a lot of addons, clients will just give up connecting.

However, I have cleaned up that code a little better and I included the materials, models, and sounds folder. You would place this in /lua/autorun/server/downloads.lua

[lua]local addDir = function() end
addDir = function(dir)
local fileList = file.FindDir("…/"…dir…"/")
for _,v in pairs(fileList) do
if v ~= “.svn” then
addDir(dir…"/"…v)
end
end
for _,v in pairs(file.Find(dir…"/
", true)) do
resource.AddFile(dir…"/"…v)
end
end
addDir(“models”)
addDir(“materials”)
addDir(“sounds”)[/lua]

Now. is that the modesl materials and sounds from the addons? or the ones that are hard-installed into my directory?

[editline]27th October 2011[/editline]

Also. I have a fast-dl. and a godly compression ratio. Also. its just me and my friend for the most part.

That includes things from the addons folder because the contents of the addons are included in the file system. That may be a little more complex because of FastDL. How do you have your FastDL setup?

snip

[editline]27th October 2011[/editline]

Source RSC. everything is placed into the webserver directory.

[editline]27th October 2011[/editline]

http://naberius.com:84/redir/

If you are curious. XD 84 goes to the gameservers webdir. 80 goes to my website on the other box.

Did you fix the table issue? From what I can tell, your FastDL should work fine then.

I dont know what causes the table issue. :frowning:

I think that may be caused by too many files to download. Try removing wire and see if you still get the error.

[editline]27th October 2011[/editline]

Wire model pack, that is.

yea. it is definitely because of too many files. interesting though. LOL. Ill remove wire and check.

[editline]27th October 2011[/editline]

is it possible to increase the size of the table?

I think I’ve heard something about that in the past, but I’ve never experienced that error.

removing wire didnt help. Removing the line Models from the code did however. :confused: Sadly. the models is what I need it to send :frowning:

Try running this and then post what the last print says:

[lua]local numFiles = 0
local addDir = function() end
addDir = function(dir)
local fileList = file.FindDir("…/"…dir…"/")
for _,v in pairs(fileList) do
if v ~= “.svn” then
addDir(dir…"/"…v)
end
end
for _,v in pairs(file.Find(dir…"/
", true)) do
resource.AddFile(dir…"/"…v)
numFiles = numFiles + 1
print(numFiles…" files.")
end
end
addDir(“models”)
addDir(“materials”)
addDir(“sounds”)[/lua]

It counts up to about 8k or so. then starts screaming that its full. 8192 I think. Posting log in a sec. Hold on

Wow, do all of the errors that show file paths show the paths of actual models, or is the script trying to add something that isn’t a file?

http://dl.dropbox.com/u/919139/log.txt

[editline]27th October 2011[/editline]

Your guess is as good as mine mate.

Oh.

Uhh… yeah… I didn’t think about that. Heh.

It’s also adding all of the content files (hl2, cstrike, etc), so obviously there is a lot of files getting added.

What you should do is remove the addDir calls from the bottom of that script and add calls for the individual folders that the addons have in them. For example:

[lua]addDir(“models/beer”)
addDir(“models/blacknecro”)
addDir(“models/bull”)
addDir(“models/cheeze”)
addDir(“models/cyborgmatt”)
addDir(“models/expression 2”)
–Etc[/lua]

wouldnt putting addDir(“addons”) be just as simple? Or would that not work?

That alone wouldn’t work, but I may be able to code something that will work, give me a bit.

How do I give you rep? LOL. You are super helpful. I cannot thank you enough.

This will add the models, materials, and sounds for all addons except for those omitted. Again, remember that this is not a very good thing to do.

[lua]local omitAddons = {
“aoc”,
“counter-strike”,
“day-of-defeat”,
“diprip”,
“dystopia”,
“hl2_ep2”,
“left4dead”,
“left4dead2”,
“portal”,
“tf2”,
“zeno_clash”,
“zps”,
“checkers”,
“chess”,
“common”,
“go”,
“hearts”,
“spades”,
“toybox”
}

local addAddonContentFolder = function() end
addAddonContentFolder = function(folder, addon)
if file.Exists("…/addons/"…addon…"/"…folder) then
local files = file.Find(“addons/”…addon…"/"…folder…"/*", true)
for _,v in pairs(files) do
if file.IsDir("…/addons/"…addon…"/"…folder…"/"…v) then
if v ~= “.svn” then
addAddonContentFolder(folder…"/"…v, addon)
end
else
resource.AddFile(folder…"/"…v)
end
end
end
end

hook.Add(“Initialize”, “InitializeAddDownloads”, function()
Msg(“Creating download list, please wait…”)
local addons = file.FindDir("…/addons/*")
for _,addon in pairs(addons) do
if not table.HasValue(omitAddons, addon) then
addAddonContentFolder(“models”, addon)
addAddonContentFolder(“materials”, addon)
addAddonContentFolder(“sounds”, addon)
end
end
MsgN(“done”)
end
)[/lua]

The table at the beginning is a list of addons to omit from the resource list.