Locations
From GMod Wiki
The tone of this page does not meet Garry's Mod Wiki standards. Please rewrite it using an encyclopedic tone. More pages requiring tone cleanup here. Details: uses first and second person |
Contents |
Where do I put my script?
So, you have written your first basic script, but where the heck do you put it to make it work? Well, first let's examine the Garry's Mod file and folder structure.
File Folder Structure
Navigate to steam/steamapps/<username>/garrysmod/garrysmod.
In here, you will find several folders which you will probably be familiar with - such as the addons folder and the maps folder. Open up the lua folder.
Inside here, you should see 4 folders: "includes", "postprocess", "vgui" and "autorun". If you don't see an autorun folder, create one now.
Inside the autorun folder, every Lua script will be executed when the game starts. If you want the script to only execute on the SERVER machine, you must create a folder called "server" and put the scripts in here. If you want the script to only execute on CLIENT machines, you must do the same with a folder called "client."
If you have a basic script that you just want to run when you start the game, you should put it in the autorun folder.
If you want to add scripted weapons or scripted entities to the game, you can add a folder inside the Lua folder called "weapons". Inside here, you have a folder for each SWEP. Inside each folder, is the cl_init.lua, init.lua and shared.lua files that control that SWEP. For SENTs, the folder name is "entities".
Addon Format
Inside your addons folder, there is a folder for each addon. Inside each addon, there will be an info.txt file and a Lua folder. Inside the lua folder, all your scripts go in exactly the same way they would the normal Lua folder. For example, autorun scripts would go in addons/<addonname>/lua/autorun/.
See Addons for more information
Gamemode Format
In your gamemodes folder, each gamemode will have it's own folder. Inside each gamemode folder, there will be an info.txt file and a "gamemode" folder. This follows a different format to the standard format. Inside the "gamemode" folder, there will be a shared.lua, init.lua and cl_init.lua script. These scripts can then load other scripts you want to run in order, by use of the "include" command.
Folder List
- lua/ - Base lua folder.
- lua/autorun - All scripts in here are run on game startup.
- lua/autorun/server - All scripts in here are run on game startup for server only.
- lua/autorun/client - All scripts in here are run on game startup for client only.
- lua/includes/modules/ - Place modules in this folder.
- lua/weapons/ - All folders in here will be loaded as SWEPS.
- lua/weapons/<weaponname>/ - SWEP code goes here!
- lua/entities/ - All folders in here will be loaded as SENTS.'
- lua/entities/<entityname>/ - SENT code goes here!
- addons/<addonname>/lua/ - Base lua folder for addon.
- addons/<addonname>/lua/autorun - All scripts in here are run on game startup.
- addons/<addonname>/lua/autorun/server - All scripts in here are run on game startup for server only.
- addons/<addonname>/lua/autorun/client - All scripts in here are run on game startup for client only.
- addons/<addonname>/lua/weapons/ - All folders in here will be loaded as SWEPS.
- addons/<addonname>/lua/weapons/<weaponname>/ - SWEP code goes here!
- addons/<addonname>/lua/entities/ - All folders in here will be loaded as SENTS.
- addons/<addonname>/lua/entities/<entityname>/ - SENT code goes here!
- gamemodes/<gamemodename>/gamemode/ - Gamemode code goes here!
- gamemodes/<gamemodename>/entities/weapons/ - Gamemode SWEPS go here!
- gamemodes/<gamemodename>/entities/entities/ - Gamemode SENTS go here!
See Also
Addons- How to install and update addons, as well as a partial addons list.