Forced Downloads

I need to make it so when people join one of my servers they are forced to download textures.

[lua]add.Resource(“path/thing”)[/lua]

Example:

[lua]add.Resource(“models/player/gman_high.mdl”)[/lua]

This will make the client download Gman playermodel, if he doesent have it already.

You put the file in “garrysmod/lua/autorun/server/resource.lua”.

Hope I helped.

Thank you, I was looking for this too.

Another way to do things, especially in bulk, is to have a lua file with the following code.

[lua]local ClientResources = 0;
local function ProcessFolder ( Location )
for k, v in pairs(file.Find(Location … ‘*’)) do
if file.IsDir(Location … v) then
ProcessFolder(Location … v … ‘/’)
else
local OurLocation = string.gsub(Location … v, ‘…/addons/ADDON-NAME-HERE/’, ‘’)

if !string.find(Location, ‘.db’) then
ClientResources = ClientResources + 1;
resource.AddFile(OurLocation);
end
end
end
end

if !SinglePlayer() then
ProcessFolder(’…/addons/ADDON-NAME-HERE/models/’);
ProcessFolder(’…/addons/ADDON-NAME-HERE/materials/’);
ProcessFolder(’…/addons/ADDON-NAME-HERE/sound/’);
end[/lua]

As an example. Just put it in autorun/server with whatever name you want. Should what you’re seeking for others to download not be an addon, then a slight alteration is needed.

[lua]local ClientResources = 0;
local function ProcessFolder ( Location )
for k, v in pairs(file.Find(Location … ‘*’)) do
if file.IsDir(Location … v) then
ProcessFolder(Location … v … ‘/’)
else
local OurLocation = string.gsub(Location … v, ‘…/materials/’, ‘’)

if !string.find(Location, ‘.db’) then
ClientResources = ClientResources + 1;
resource.AddFile(OurLocation);
end
end
end
end

if !SinglePlayer() then
ProcessFolder(’…/materials/models/MATERIAL-FOLDER’);
end[/lua]

Not tested that but I think it would work. Not to mention that you’d have to do that for each folder to be parsed, but it beats manually doing resource.AddFile.