• FastDL Folder Download
    16 replies, posted
Hello, I am new to modding and such, and I have checked, but not found how to make it so that you can add entire folders to FastDL instead of adding every single file separately. Since I run a DarkRP server, I have a lot of content, which some refuse to download. And I was wondering if anyone could help me with finding a way to add entire addons to the FastDL(well the materials, models, etc. folders.) Any help is much appreciated.
[URL="puu.sh/Mygc"]Download this[/URL], it really helps with adding content to lua resource file.
[LUA] local function AddResourceDir(directory) local files, folders = file.Find(directory.."/*", "GAME") for _, dir in pairs(folders) do AddResourceDir(directory.."/"..dir) end for k,v in pairs(files) do resource.AddFile(directory.."/"..v) end end AddResourceDir("materials/example") [/LUA]
Thank you both. Bo98, does that work with folders inside folders(ie. addon/materials/models)? [editline]29th June 2013[/editline] TheMostUpset, Why would this program need access to C:\Windows\system32?
Should do. It's relative to the garrysmod/ folder. [editline]29th June 2013[/editline] [QUOTE=Freece;41242105] TheMostUpset, Why would this program need access to C:\Windows\system32?[/QUOTE] I wouldn't use .exe files over Lua. I wouldn't trust it at all.
Bo98, do I put this in the root/garrysmod/lua/autorun or the root/garrysmod/addons/[addon]/lua/autorun? [editline]29th June 2013[/editline] Yea i figured as much.
[QUOTE=Freece;41242105]TheMostUpset, Why would this program need access to C:\Windows\system32?[/QUOTE] I dunno. I found it [URL="http://www.facepunch.com/showthread.php?t=842886"]here[/URL], don't worry, it's safe
lua/autorun Don't prefix it with root/garrysmod.
Well yea, but just to get the idea :) Saw someone else use it like that xD. Well thank you very much! [editline]29th June 2013[/editline] Just so that we are on the same page, I can have my addons in the addons folder and the still just write AddResourceDir("materials/example") or do I have to write it like this then: AddResourceDir("addons/[addon]/materials/example") [editline]29th June 2013[/editline] I keep getting this error: [ERROR] addons/extra_customizable_weaponry/lua/autorun/forcedownload.lua:2: attempt to concatenate global 'dir' (a nil value) 1. AddResourceDir - addons/extra_customizable_weaponry/lua/autorun/forcedownload.lua:2 2. unknown - addons/extra_customizable_weaponry/lua/autorun/forcedownload.lua:11 I have tried adding the code to garrysmod/lua/autorun/forcedownload.lua as well as garrysmod/addon/extra_customizable_weaponry/lua/autorun/forcedownload.lua. But neither will work. I have tried these combinations of AddResourceDir: AddResourceDir("models") AddResourceDir("materials") AddResourceDir("sound"), AddResourceDir("addons/extra_customizable_weaponry/models") AddResourceDir("addons/extra_customizable_weaponry/materials") AddResourceDir("addons/extra_customizable_weaponry/sound") What am I doing wrong?
I wasn't aware you can make clients download the dir, so say I wanted players to download everything in my materials and models I would just use that line of code in my force download.lua?
That code bot gave you was outdated! Use mine: local function AddDir(dir) local fil, List = file.Find(dir.."/*", "GAME") if List then for _, fdir in pairs(List) do if fdir != ".svn" then AddDir(dir.."/"..fdir) end end end if fil then for k,v in pairs(fil) do resource.AddFile(dir.."/"..v) end end end AddDir("models/")
I got it working with this code: if SERVER then local function AddResourceDir(directory, sdir) local files, folders = file.Find("addons/"..directory.."*", "GAME") for k,v in pairs(folders) do --print(directory..v.."/") AddResourceDir(directory..v.."/", sdir) end for k,v in pairs(files) do --resource.AddSingleFile("addons/"..directory..v) resource.AddSingleFile(string.gsub((directory..v), sdir, "")) end end AddResourceDir("extra_customizable_weaponry/models/", "extra_customizable_weaponry/") AddResourceDir("extra_customizable_weaponry/materials/", "extra_customizable_weaponry/") AddResourceDir("extra_customizable_weaponry/sound/", "extra_customizable_weaponry/") end And you have to place it in the /garrysmod/addons/[addon]/lua/autorun/[name of any file you want(ie forcedownload.lua)] And the follow the examples.
[QUOTE=Linox;41253447]That code bot gave you was outdated! Use mine: local function AddDir(dir) local fil, List = file.Find(dir.."/*", "GAME") if List then for _, fdir in pairs(List) do if fdir != ".svn" then AddDir(dir.."/"..fdir) end end end if fil then for k,v in pairs(fil) do resource.AddFile(dir.."/"..v) end end end AddDir("models/")[/QUOTE] That's the exact same but with different variable names and a couple of if statements. How is mine outdated? [editline]30th June 2013[/editline] [QUOTE=Freece;41242210] I keep getting this error: [ERROR] addons/extra_customizable_weaponry/lua/autorun/forcedownload.lua:2: attempt to concatenate global 'dir' (a nil value) 1. AddResourceDir - addons/extra_customizable_weaponry/lua/autorun/forcedownload.lua:2 2. unknown - addons/extra_customizable_weaponry/lua/autorun/forcedownload.lua:11 [/QUOTE] Yeah I made a typo. For future reference, here's the fix: [LUA]local files, folders = file.Find(directory.."/*", "GAME")[/LUA]
I was kidding about outdated :(
Just for future reference, how do i make that box for the code? xD
[noparse][lua][/lua][/noparse] tags.
[QUOTE=Bo98;41253548][noparse][lua][/lua][/noparse] tags.[/QUOTE] Even though thats fine you can use [CODE][/CODE] too :)
Sorry, you need to Log In to post a reply to this thread.