Gamemode Creation
Gamemode Content
Gamemode content such as maps, models and sounds should be placed in gamemodes/content/
folder. (i.e. gamemodes/content/models/..
).
Gamemode Folder
To create a new gamemode you need to create a new folder in the gamemodes folder. The folder should take the name of your gamemode. Inside of that folder there should be a text file named whatever your folder is.
For instance, if my gamemode was called SuperKillers
, I would create a folder in garrysmod/gamemodes/
called superkillers
. Then inside that folder I would create a text file called superkillers.txt
.
Note that in previous versions of Garry's Mod this file was always called info.txt
- but was changed in Version 13 to reflect the changes to the content.
Gamemode Text File
The .txt
file you created needs to be a keyvalues file.
key | description |
---|---|
title | The 'nice' title of your gamemode. Can contain spaces and capitals. |
maps | The map filter for your gamemode. This is used to correctly categorise maps in the map selector. This should only be set if the maps are unique to your gamemode. |
category | The category your gamemode falls into. See below for details. |
menusystem | Include and set to 1 if this gamemode should be selectable from the main menu |
workshopid | Optional. If your gamemode is on Workshop then this should be the workshopid of the file. (You won't have a workshopid until you upload - so you will need to set this in an update) |
settings | See below for details |
Category
Your gamemode can have only one category, out of the following choices:
rp
- Roleplay - Your gamemode contains Roleplay elements. If your gamemode has "RP" in its name, this is the category for you.pvp
- Your gamemode is based mostly on Player versus Player combat, be that competition or just a shooter gamemode.pve
- Your gamemode is based more around Player versus Environment combat, such as survival or campaign gamemodes. This does not exclude PvP.other
- Your gamemode does not fit in any of the above categories, for example sandbox or hangout type gamemodes.
Settings
The settings table allows you to create server configuration convars for your gamemode. It's completely optional. Your text file doesn't have to have a settings section.
In previous versions of GMod this section used to have its own file, in gamemode/<gamemode>/content/settings/server_settings/
. It was moved to the root folder to decrease load times.
These settings are configurable in the main menu in GMod. Each entry has a number of fields.
key | description |
---|---|
text | The text to show in game to describe this convar |
help | The help text to show on the convar (in the console) |
type | Either Text, CheckBox or Numeric. These are case-sensitive! |
default | The default value for the convar |
singleplayer | Whether this convar should show up for singleplayer, just having this key will enable it, it doesn't matter what the value is |
replicate | Whether this convar should be replicated (networked) to clients automatically. Default is 1 . |
dontcreate | Whether this convar should not be created, but still listed in the UI. Useful for engine convars. Default is 0 . |
Menu Background Images
If you want to include backgrounds with your gamemode place them in gamemodes/<yourgamemode>/backgrounds/
. They must all be jpg images.
Menu Logo Image
To supply a menu logo image place a .png
file in gamemodes/<yourgamemode>/logo.png
. This image should be 128 pixels high and up to 1024 pixels wide. The default logo is 288 x 128.
Menu Icon
To supply a menu icon place a .png
file in gamemodes/<yourgamemode>/icon24.png
. This image should ideally be 24x24 pixels but it can be up to 32x32. The server list displays the icons at 24x24 while the gamemode selection uses 32x32. Here's where it will appear.
Init and Shared Files
Three files are needed for your gamemode to function properly. These go into your <gamemode>/gamemode/
folder.
Please note, that while we use shared.lua
in the example below, it is completely optional. init.lua
and cl_init.lua
are not!
init.lua
This file is called when the server loads the gamemode. The example below tells the resource system to send the two files to the client, and then loads shared.lua
.
shared.lua
This file sets some common variables and creates the Initialize function. This is the only function you NEED to define. All others will be called from the base gamemode.
cl_init.lua
This file is called when the client loads the gamemode. You would put client specific things in here. We load shared.lua. Note that you can only include files here that have been registered with AddCSLuaFile on the server.
GAMEMODE.FolderName
This is a variable that will return the current folder name of the gamemode being run.
For example, If you are playing the gamemode Trouble In Terrorist Town
this variable will equal to terrortown
Deriving Gamemodes
If you are deriving your gamemode from something other than base, use this function to tell the engine that we do.
You must call the function on both client and server, and since our shared.lua
is included from both cl_init.lua
and init.lua
, we can do it once, in shared.lua
.
In the example below, let's say we derive our gamemode from sandbox, so we add this to our shared.lua
; somewhere above all function definitions is a good place:
Modding Gamemodes
If you wish to edit a gamemode but you do not want it to appear under a different category in the server browser and you do not want the edited version to override the original, in cases like editing Trouble In Terrorist Town
where a game update could undo your edits, you can copy the gamemode as usual and append _modded
to the gamemode's folder name (for example terrortown_modded
), as well as the .txt
file inside the gamemode folder.
You will still load it as terrortown_modded
on your server, but it will appear as terrortown
to the rest of the world.
Common Errors
Error loading gamemode: info.Valid
Your Gamemode Text File is invalid or was not found.
Error loading gamemode: !IsValidGamemode
The game could not find cl_init.lua
or init.lua
of your gamemode. Make sure these files exist in the correct place:
gamemodes/**yourgamemodename**/gamemode/init.lua
gamemodes/**yourgamemodename**/gamemode/cl_init.lua
Game crashes/freezes on death
You have not assigned a playermodel to the player.