Garry's Mod Wiki

Revision Difference

Lua_Folder_Structure#560352

<cat>Dev.GettingStarted</cat> The structure of the Lua folder can be confusing. This page tries to layout where script files should go.⤶ If a folder is not mentioned here, you should not put your scripts into it unless you know what you are doing. ⤶ `lua/` (Same as `addons/<addonName>/lua/`) ⤶ > `autorun/` - A folder for automatic scripts load and include on Lua start, both clientside and serverside. ⤶ >> `client/` - Clientside only autorun scripts. ⤶ >> `server/` - Serverside only scripts. ⤶ >> `properties/` - A Folder for properties in <page>The Context Menu</page>. ⤶ > `bin/` - A folder for external binary modules. (<page>Creating Binary Modules</page>) ⤶ > `derma/` - A folder for <page>derma</page> utils. ⤶ > `drive/` - A folder for <page>drive</page> system classes. ⤶ > `effects/` - Scripts placed here will be automatically attempted to be loaded as Lua effects. (<page>util.Effect</page>) ⤶ > `entities/` - Scripts placed here will be automatically attempted to be loaded as SENTs. (<page>Structures/ENT</page>) ⤶ > `includes/` - A folder for Lua libraries and additional stuff used in other scripts. Runs first. ⤶ >> `extensions/` - A folder for extended libraries. For example <page>table</page> library already exists but `extensions/table.lua` extends it. ⤶ >> `modules/` - A folder for libraries. ⤶ > `matproxy/` - A folder for <page>matproxy</page> stuff. ⤶ > `menu/` - A folder used for <page text="Menu state">States</page>. ⤶ > `postprocess/` - Run by client on startup, typically contains Sandbox Post Processing effects. ⤶ > `skins/` - A folder for users <page text="derma skins">Derma Skin Creation</page>. ⤶ > `vgui/` - Clientside folder for UI panels. ⤶ > `weapons/` - Scripts placed here will be automatically attempted to be loaded as weapons. (<page>Structures/SWEP</page>) ⤶ >> `gmod_tool/stools/` - (Sandbox only) Scripts placed here will be automatically attempted to be loaded as tools. (<page>Structures/TOOL</page>) ⤶ `gamemodes/`⤶ ⤶ > `<gamemodename>/` - A folder containing gamemode files. ⤶ >> `entities/` - Basically `lua/` folder that is only loaded when the gamemode is. Subfolders are exactly the same as mentioned above. ⤶ >> `gamemode/` - Folder contains all gamemode files. `init.lua` and `cl_init.lua` __must__ exist in it. ⤶ `models/`⤶ >⤶ ⤶ `sound/`⤶ >⤶ ⤶ `resource/`⤶ ⤶ > `<fonts>/` - <page>surface.CreateFont</page>⤶ ⤶ > `<localization>/` <page>Addon Localization</page>⤶ ⤶ ⤶ `particles/` <page>game.AddParticles</page>⤶ >⤶ ⤶ `materials/` <page>Materials and Textures</page>⤶ # Lua Folder Structure⤶ The main game directory for Garry's Mod is the `garrysmod` folder located next to the game's executable `hl2.exe`, and contains much of the content you see while playing the game. This includes Lua scripts, sound effects, 3D models, and more. Each Addon for Garry's Mod needs its own folder in `garrysmod/addons/` that will hold all of its content. ⤶ Addons and Gamemodes have a nearly identical folder structure to the `garrysmod` folder. When making an Addon, all folders are optional and only those that your Addon requires should be created in order to keep your Addon's folder structure clean and easy to navigate. ⤶ Because this folder structure is applicable in multiple situations, the generic term `{Root}` is used here to mean the folder at the base of the game, Addon, or Gamemode. Folders that are meant primarily for use by Garry's Mod internally are marked with `[I]` to mean "Internal" and should not be modified unless you have a good reason to be doing so. ⤶ **Please note:** This is **not** an exhaustive list. This list is primarily intended to give a general overview of the game's folder structure as it relates to lua scripts, with more detailed information where it is relevant for Gamemode and Addon creation. ⤶ ` {Root} ` ` ├── lua` ` │ ├── autorun` - Scripts in this folder are run automatically when Lua starts on both [Client](https://wiki.facepunch.com/gmod/States#client) and [Server](https://wiki.facepunch.com/gmod/States#server) (Called ["Shared"](https://wiki.facepunch.com/gmod/States#sharedisntastate)) realms. ` │ │ ├── client` - Runs its contents automatically in the [Client](https://wiki.facepunch.com/gmod/States#client) realm. ` │ │ ├── server` - Runs its contents automatically in the [Server](https://wiki.facepunch.com/gmod/States#server) realm. ` │ │ └── properties` - Runs its contents automatically to create <page text="Properties">properties</page> used in <page>The Context Menu</page>. ` │ ├── bin` - Where <page text="Binary Modules">Creating_Binary_Modules</page>, an advanced feature, should be placed. ` │ ├── derma` - Where <page>Derma</page> utility scripts should go. ` │ ├── drive` - A dedicated folder for scripts relating to the <page>Drive</page> system. ` │ ├── effects` - Where scripts for custom <page text="Lua-based Effects">util.Effect</page> go. ` │ ├── entities` - Scripts placed here will be loaded as <page text="Scripted Entities (SENTs)">Scripted_Entities</page>. ` │ ├── includes` - `[I]` This is where `init.lua` (The first lua file executed when lua starts) is located. ` │ ├── matproxy` - For scripts relating the <page text="Material Proxy (matprox)">matproxy</page> library, used to create per-entity materials. ` │ ├── menu` - `[I]` Similar to the `inculdes` directory but for the game's main menu. Starts by running `menu.lua`. ` │ ├── postprocess` - Where scripts defining <page>Post-Processing Materials</page> are located. ` │ ├── skins` - Where scripts defining <page text="Skins">Derma_Skin_Creation</page> for the <page>Derma</page> library are placed. ` │ ├── vgui` - Scripts defining <page>Derma</page> interface elements like <page text="DButtons">DButton</page> and <page text="DSliders">DSlider</page>. ⤶ ` │ └── weapons` - Scripts placed here will be loaded as <page text="Scripted Weapons (SWEPs)">Structures/SWEP</page> ` │ └── gmod_tool` - This folder is created by the Toolgun in the <page text="Sandbox">gamemodes/Sandbox</page> Gamemode. ` │ └── stools` - This is where lua files for <page text="Scripted Tools (STOOLs)">Structures/TOOL</page> used with the Toolgun are placed. ` └── gamemodes` - <page text="Gamemodes">Gamemode_Creation</page> can be thought of as Addons that are only active while they are being played. ⤶ ` └── {Gamemode Name}` - Each Gamemode gets its own folder, which acts as its `{Root}` directory. ⤶ ` └── gamemode` - This folder **must** exist and **must** contain at least `init.lua` and `cl_init.lua` for the Gamemode to work.⤶