Lua code to automaticly resource.AddFile()

This code won’t work though because it will include all the materials and models that are in garrysmod by default. is there an alternative to file.Find?

function AddRes( path )
local files, folders = file.Find( path … “/*”, “MOD” )
for k, v in pairs( files ) do
resource.AddFile( path … “/” … v )

for k, v in pairs( folders ) do
	AddRes( path .. "/" .. v )


AddRes( “materials” )
AddRes( “models” )
AddRes( “sound” )

You’re probably better off doing it manually

So hardcore guy

(User was banned for this post ("Shitpost" - Craptasket))

doing resource.AddFile on every single file in the game isn’t really a good thing to do, because all downloads will come from your server, unless you have fastdl set up. if you’re trying to get players to download addons you’ve subscribed to, you’re better off using resource.AddWorkshop. i don’t really recommend this function either because it can get a bit screwy with lots of addons.

anyways, i did some snooping around in robotboy’s extended spawnmenu code and found that you can iterate through all subscribed addons using

engine.GetAddons and take each addon’s title and use that as the 2nd argument in the file.Find function. for the first argument you can use “sound” or “models” or “materials”. try doing that and see if it works.
for example
for k, addon in pairs( engine.GetAddons() ) do

if !addon.downloaded or !addon.mounted then continue end
local files, folders = file.Find( "*", addon.title )

// look through the file tree here using the files and folders tables


For workshop addons you should be using resource.AddWorkshop period. Using fastDL will just end up with double content and content conflicts for the end user. ( Especially should the workshop addon be updated on a later date )