• resource.addfile help
    2 replies, posted
Hey, im really new to this whole garrys mod server hosting thing so i was wondering if anyone could help me with my problem. So im running a server off my computer with the hldsTool and me and a couple friends have found a couple addons that we like and i add them onto the server. I recently started looking into how I could make it so when my friends join my server, the server would make them download the addons that i add to the server instead of us all having to download the addons beforehand. After some reserach i could either rent a server from a webhost and my problems would be solved, but i dont want to pay just to download files. So, i found out about the resource.addfile lua script and i was wondering if anyone could help me with how I actually set it up into my garrys mod server file. 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") This is the code that I wanted to use so i dont have to individually have to type out each and every file to be downloaded. In conclusion, how do i go about editing this and how do i make it autorun for the server. Sorry if this is stupid but I cant seem to find any help regarding how to run this because some forum posts say to place it in an autorun folder and I just got completely lost because of my lack of knowledge. Help would be much appreciated:smile:
It's better to wrap your code around [code] tags, because it's easier to read that way. [code]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 [/code] You should put this as like "AddDir.lua" and drop it into your lua/autorun/server folder. And now you just want to add folders to download. Make a file called "myfiles.lua" or whatever and put in AddDir("models/tf2") or w.e and save it and throw it in lua/autorun
I put this in but i keep getting too many lua erros because of this, what am I doing wrong? [CODE]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("materials/entities")[/CODE] [QUOTE][code]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 [/code] You should put this as like "AddDir.lua" and drop it into your lua/autorun/server folder. And now you just want to add folders to download. Make a file called "myfiles.lua" or whatever and put in AddDir("models/tf2") or w.e and save it and throw it in lua/autorun[/QUOTE][/QUOTE]
Sorry, you need to Log In to post a reply to this thread.