Server rentals :: NFOservers.com

Forums

All times are UTC - 8 hours



Author Message
PostPosted: Tue May 22, 2012 4:06 pm 
Offline
Staff
Staff
User avatar

Joined: Fri Sep 17, 2010 9:06 am
Posts: 2025
Location: California
To do this you will need to use a LUA file.

  1. Connect to your server FTP by using the connection info on the "File Manager" tab
  2. Navigate to garrysmod/lua/autorun/server/
  3. Create a new "Example.lua" file.
  4. Then add this code "resource.AddFile("file path here")"

Save the file, run a websync and your files should be force downloading now.

As an alternative to manually specifying files, you can use this code to add everything in a certain directory. The code below would add everything in the content folder.
Code:
local path = "../"..GM.Folder.."/content"
local folders = {""}
while true do
   local curdir = table.remove(folders,1)
   if not curdir then break end
   local searchdir = path..curdir
   for _, filename in ipairs(file.Find(searchdir.."/*")) do
      if filename ~= ".svn" then
         if file.IsDir(searchdir.."/"..filename) then
            table.insert(folders,curdir.."/"..filename)
         else
            resource.AddSingleFile(string.sub(curdir.."/"..filename,2))
         end
      end
   end
end




If you want to force-add any related files this function will automatically add any other files that are related to the selected one, and throw an error if it can't find them. For example, a .vmt file will automatically add the .vtf with the same name, and a .mdl file will automatically add all .vvd, .ani, .dx80.vtx, .dx90.vtx, .sw.vtx, .phy and .jpg files with the same name, with a separate error for each missing file. (This can lead to spamming the consoles of potential players)

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("models/yourmodels")

Information sourced from http://maurits.tv/data/garrysmod/wiki/w ... xd2d2.html and http://maurits.tv/data/garrysmod/wiki/w ... x5809.html

_________________
<@TimeX-NFo> Hey, we used to have to carry our packets to the servers.
<@TimeX-NFo> And it was upstream, both ways.

<@TimeX-NFo|away> You're asking the old dude for help?????
<@Kraze^NFo> Yes


Top
 Profile  
 
PostPosted: Tue May 07, 2013 6:14 pm 
Offline
Staff
Staff
User avatar

Joined: Fri Sep 17, 2010 9:06 am
Posts: 2025
Location: California
We've seen a few people who have tried force downloading map files to clients. Do not do this as it will require all clients who do not have the maps to download them all before joining.

When the server switches to a custom map that the client does not have it will automatically start downloading it for them.

_________________
<@TimeX-NFo> Hey, we used to have to carry our packets to the servers.
<@TimeX-NFo> And it was upstream, both ways.

<@TimeX-NFo|away> You're asking the old dude for help?????
<@Kraze^NFo> Yes


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
It is currently Fri May 24, 2013 3:47 pm
Powered by phpBB® Forum Software © phpBB Group