Garry's Mod Wiki

Revision Difference

resource.AddFile#526899

<function name="AddFile" parent="resource" type="libraryfunc"> <description> Adds the specified and all related files to the files the client should download. 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 <page>resource.AddSingleFile</page>. 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 <page>resource.AddSingleFile</page>.⤶ <warning>There's a 8192 downloadable file limit. If you need more, consider using Workshop addons - <page>resource.AddWorkshop</page>. You should also consider the fact that you have way too many downloads. This limit is shared among all resource.Add functions.</warning> <note>Running this function using a path relative to the main `garrysmod/` folder will not work for files in addons and gamemodes. Instead, the files must be added relative to their respective content folders. For example, a sound file from an addon would use the path "sound/[FILENAME_AND_EXTENSION]," despite the file being located in "addons/[ADDON_NAME]/sound/[FILENAME_AND_EXTENSION]"</note> ⤶ <note>The file must exist on the server or players will not download it!</note>⤶ </description> <realm>Server</realm> <args> <arg name="path" type="string">Virtual path of the file to be added, relative to `garrysmod/`. Do not add `.bz2` to the filepath. Do not put `gamemodes/*gamemodename*/content/` or `addons/<*addonname*/` into the path.</arg> </args> </function> <example> <description>Example of usage.</description> <code> resource.AddFile( "materials/my/material.vmt" ) -- Automatically adds materials/my/material.vtf resource.AddFile( "models/my/model.mdl" ) -- Automatically adds models/my/model.vtx and the rest resource.AddFile( "sound/my/sound.wav" ) -- Be careful, there's no S in the sound. </code> </example>