Creating new game modes

From Pragma
Jump to: navigation, search

Before reading this tutorial it's recommended to set up ZeroBrane, which will allow you to work and debug with Lua more easily.

Description

Gamemodes define the internal logic and behavior of the game.
All new gamemodes should be placed within an addon, you can read this article to find out how to create a new addon and work with it.
Once you have created the addon directory, create the path "lua/gamemodes/" relative to it. Then create a new directory in lower-case letters, and without spaces or special characters inside that path. The name should be unique and identify your gamemode somehow, but will never be displayed anywhere.

You will also have to create the following files:

info.txt

To allow the game to actually recognize your gamemode, you need to create a "info.txt" in the gamemode's main directory. In it, you have to define the following values:

"zen" // Has to be the same as the directory name
{
	$string class "GMZen" // The gamemode class as defined in the init.lua
	$string name "Zen" // Name of the gamemode which will show up in the game and the server browser
	$string author "Silverlan"
	$float version 0.1 // Version has to be >= 0.1
}

init.lua

The "init.lua" contains the main gamemode functions. It is loaded automatically by the engine and doesn't have to be included. A gamemode should generally be defined as such:

class 'GMZen' (GMBase) -- All gamemodes have to be derived from GMBase. The class name should start with the uppercase letters "GM", however this is not a requirement.

function GMZen:__init() -- Constructor, called before the map is loaded
	GMBase.__init(self) -- Base constructor has to be called!
end

function GMZen:Think()
	-- GMBase.Think(self) -- If you want to override the default behavior, simply don't call the base function.
end

function GMZen:Tick()
	GMBase.Tick(self)
end

You can find a list of default gamemode hooks here.

You can also set up new keybindings for your gamemode, which will show up in the options menu. You can read this article to find out how (See menu.xml).