Hello facepunch! Here is some code that makes resourcing so much easier!
[code]function resource.AddModel(path)
resource.AddFile(path..".mdl")
resource.AddFile(path..".sw.vtx")
resource.AddFile(path..".dx90.vtx")
resource.AddFile(path..".dx80.vtx")
resource.AddFile(path..".vvd")
end
function resource.AddMaterial(path)
resource.AddFile(path..".vtf")
resource.AddFile(path..".vmt")
end
function resource.AddFolder(folder)
for i,v in pairs(file.Find("../"..folder.."*")) do
if !(string.find(v,"bz2") or string.find(v,"exe") or string.find(v,"xbox") or string.find(v,"jpg") or string.find(v,"db")) then
resource.AddFile(folder..v)
end
end
end[/code]
The code makes adding models, materials, and even whole folders, simple!
You can add a model like this:
[code]resource.AddModel("models/rubicon")[/code]
NOTE: All files associated with the base name will be downloaded. (Example, .mdl, .vvd, .dx90.vtx, .dx80.vtx)
You can add a material like this:
[code]resource.AddMaterial("materials/models/props_foliage/spikeplant01")[/code]
NOTE: A .vmt and .vtf will be downloaded when adding a material.
You can add a whole folder like this:
[code]resource.AddFolder("sound/marker/")[/code]
NOTE: Everything inside that folder will be downloaded.
I really hope this helps some smaller communities with adding resources! I know how hard it can be adding every single file!
Sorry to burst your bubble but:
[b][url=http://wiki.garrysmod.com/?title=Resource.AddFile]Resource.AddFile [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
[quote=Wiki]For convenience, 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. If you do not want it to do this, use resource.AddSingleFile. [/quote]
And your AddFolder function will not filter out anything, you have written the syntax badly, I assume you want it to not add those file endings you are specifying. It would probably be better to check the end of the filename with string.sub.
[QUOTE=leiftiger;27594433]Sorry to burst your bubble but:
[b][url=http://wiki.garrysmod.com/?title=Resource.AddFile]Resource.AddFile [img_thumb]http://wiki.garrysmod.com/favicon.ico[/img_thumb][/url][/b]
And your AddFolder function will not filter out anything, you have written the syntax badly, I assume you want it to not add those file endings you are specifying. It would probably be better to check the end of the filename with string.sub.[/QUOTE]
Darn! Makes more sense to do it that way, yes. Sorry for the shitty, useless code then!
Sorry, you need to Log In to post a reply to this thread.