<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=103495106181459904329</id>
	<title>Multi Theft Auto: Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=103495106181459904329"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/wiki/Special:Contributions/103495106181459904329"/>
	<updated>2026-04-06T07:41:28Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=RU/Writing_Gamemodes&amp;diff=25918</id>
		<title>RU/Writing Gamemodes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=RU/Writing_Gamemodes&amp;diff=25918"/>
		<updated>2011-05-30T05:58:28Z</updated>

		<summary type="html">&lt;p&gt;103495106181459904329: /* Менеджер карт */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{translate}}&lt;br /&gt;
Это руководство поможет вам, как написать правильный режим игры. Если вы только что начали писать скрипты для MTA, вы должны сначала просмотреть другие учебники на [[RU/Main Page|Главная страница]].&lt;br /&gt;
==Введение==&lt;br /&gt;
Gamemode (ГМ, мод, гейммод, игровой режим) - ресурс, который, будучи запущенным, контролирует весь игровой процесс. Гейммод включает в себя отправку сообщений игрокам - указания к действиям, респаун игроков, создание команд, указаний, что игрокам нужно делать для победы, или для получения очков, и т.д. Примеры - гонки и DeatMatch'и.&lt;br /&gt;
&lt;br /&gt;
==Что означает &amp;quot;правильный игровой режим&amp;quot;?==&lt;br /&gt;
Проще говоря, правильным игровым режимом можно назвать такой режим, который в полной мере использует MTA систему .map файлов. Это означает, что код игрового режима не имеет любых специфических карт, данные которых жестко привязаны к нему, такие как положение игроков или автомобилей. Вместо этого, игровой режим должен быть в состоянии загружать .map файлы, которые и будут определять эти данные. Таким образом, игровой режим может иметь несколько карт, а также люди смогут создавать .map файлы для игрового режима используя MTA редактор карт, который является гораздо более удобным, чем написание кода.&lt;br /&gt;
&lt;br /&gt;
Очевидным примеров &amp;quot;правильного игрового режима&amp;quot; является MTA: Race. Он допускает пользовательские карты с большим количеством возможностей внутри .map файла. Чтобы изменить точки появления игроков, объекты и т.д., пользователю не нужно изменять сам игровой режим.&lt;br /&gt;
&lt;br /&gt;
===Файлы карт===&lt;br /&gt;
Файлы карт основываются на XML документах с форматом .map. Они определяют контекст игры для одного или нескольких конкретных игровых режимов. Однако, они не должны менять правила игры, которые определены игровым режимом.&lt;br /&gt;
&lt;br /&gt;
Каждый элемент на карте соответствует узлу .map файла. Существует стандартный синтаксис для общих элементов, таких как точки появления игроков, объекты и транспортные средства. Для особых же элементов карты, соответствующих специфике игрового режима, вам нужно придумать собственный синтаксис.&lt;br /&gt;
&lt;br /&gt;
====Пример====&lt;br /&gt;
Давайте для примера возьмем режим Capture the Flag. Карта для этого режима нуждается главным образом в определенных точках появления игроков, расположенных флагах и в конце концов объектах и транспортных средствах. Упрощенный файл карты может выглядеть следующим образом:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;map&amp;gt;&lt;br /&gt;
    &amp;lt;spawnpoint id=&amp;quot;spawnpoint1&amp;quot; posX=&amp;quot;1959.5487060547&amp;quot; posY=&amp;quot;-1714.4613037109&amp;quot; posZ=&amp;quot;877.25219726563&amp;quot; rot=&amp;quot;63.350006103516&amp;quot; model=&amp;quot;0&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;pickup id=&amp;quot;Armor 1&amp;quot; posX=&amp;quot;1911.083984375&amp;quot; posY=&amp;quot;-1658.8798828125&amp;quot; posZ=&amp;quot;885.40216064453&amp;quot; type=&amp;quot;armor&amp;quot; health=&amp;quot;50&amp;quot; respawn=&amp;quot;60000&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;flag posX=&amp;quot;1959.5487060547&amp;quot; posY=&amp;quot;-1714.4613037109&amp;quot; posZ=&amp;quot;877.25219726563&amp;quot; team=&amp;quot;blue&amp;quot; /&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
&amp;lt;/map&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Здесь вы можете увидеть два MTA элемента - точку появления игрока и пикап. Что еще более важно, карта имеет пользовательский узел &amp;quot;flag&amp;quot;, который определяет положение и цвет флага. Точка появления игрока и пикап могут быть обработаны путем существующих внешних ресурсов, пользовательские элементы должны быть обработаны игровым режимом.&lt;br /&gt;
&lt;br /&gt;
To summarize - we want mass mapper input as we saw in MTA:Race. Users should NOT have to touch the gamemode script itself at all.&lt;br /&gt;
&lt;br /&gt;
====Пример получения .map информации====&lt;br /&gt;
Как уже упоминалось выше, вашему игровому режиму нужно получить пользовательские элементы, которые определены в файле карты, и обработать их. Это довольно просто, как показано ниже.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- получаем таблицу со всеми элементами типа &amp;quot;flag&amp;quot;&lt;br /&gt;
local flagElements = getElementsByType ( &amp;quot;flag&amp;quot; )&lt;br /&gt;
-- пропускаем их через цикл&lt;br /&gt;
for key, value in pairs(flagElements) do&lt;br /&gt;
	-- получаем нашу информацию&lt;br /&gt;
	local posX = getElementData ( value, &amp;quot;posX&amp;quot; )&lt;br /&gt;
	local posY = getElementData ( value, &amp;quot;posY&amp;quot; )&lt;br /&gt;
	local posZ = getElementData ( value, &amp;quot;posZ&amp;quot; )&lt;br /&gt;
	local team = getElementData ( value, &amp;quot;team&amp;quot; )&lt;br /&gt;
	-- создаем объект в соответствии с положением флага&lt;br /&gt;
	createObject ( 1337, posX, posY, posZ )&lt;br /&gt;
	-- выводим команду, для которой мы создали базу&lt;br /&gt;
	outputChatBox ( &amp;quot;Base for team &amp;quot; .. team .. &amp;quot; created&amp;quot; )&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Функция [[getElementsByType]] возвращает таблицу всех элементов определенного типа (тип соответствует имени узла в .map файле). Это работает как с пользовательскими типами, так и со встроенными в МТА(например, &amp;quot;vehicle&amp;quot; или &amp;quot;player&amp;quot;).&lt;br /&gt;
[[getElementData]] может быть использована для получения XML-атрибутов в .map файле.&lt;br /&gt;
В этом простом примере объект создается на месте флага и в окно чата выводится сообщение. В действительности, вы конечно должны делать все это во время загрузки карты, так как в этом случае создается форма столкновения для обнаружения игроков с флагом.&lt;br /&gt;
&lt;br /&gt;
==Менеджер карт==&lt;br /&gt;
Прочитав раздел выше должно быть понятно, что игровой режим всегда должен состоять из двух частей:&lt;br /&gt;
* Ресурс игрового режима, который всегда остается неизменным&lt;br /&gt;
* Множество различных ресурсов карт, которые дают игровому режиму конкретную карту содержащую информацию&lt;br /&gt;
&lt;br /&gt;
Теперь, вместо того чтобы писать загрузчик карт для каждого игрового режима, [[Map manager]] предоставляет функции для загрузки этих самых режимов и карт. Проще говоря, когда вы вводите правильную команду (например 'gamemode ctf ctf-italy'), запускаются ресурсы 'ctf' и 'ctf-italy' вызывая событие ([[onGamemodeMapStart]]) говорящее что для ресурса 'ctf' была загружена карта. Ресурс 'ctf' может получить доступ к информации 'ctf-italy' содержащую стартовые точки для игроков.&lt;br /&gt;
&lt;br /&gt;
===How to use the mapmanager===&lt;br /&gt;
To use the mapmanager service, your gamemode resource has to be tagged as such first. More specifically you'll be setting the &amp;quot;type&amp;quot; attribute of its &amp;lt;info&amp;gt; tag to &amp;quot;gamemode&amp;quot; inside meta.xml. Also, you can set the &amp;quot;name&amp;quot; attribute to a friendly name (like &amp;quot;Capture the flag&amp;quot;) that will be shown on ASE instead of the resource name.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- meta.xml in &amp;quot;cowcatapult&amp;quot; gamemode --&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info type=&amp;quot;gamemode&amp;quot; name=&amp;quot;Cow catapulting 2.0&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your gamemode is going to load custom maps, you should add handlers for&lt;br /&gt;
* onGamemodeMapStart&lt;br /&gt;
* onGamemodeMapStop (if any unloading is necessary)&lt;br /&gt;
These are fired when a map for your gamemode is started or stopped, and pass the map resource as a parameter.&lt;br /&gt;
Within the handler function for these events you can extract all info you need from the resource's map files and configuration files.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function startCtfMap( startedMap ) -- startedMap contains a reference to the resource of the map&lt;br /&gt;
    local mapRoot = getResourceRootElement( startedMap )        -- get the root node of the started map&lt;br /&gt;
    local flagElements = getElementsByType ( &amp;quot;flag&amp;quot; , mapRoot ) -- get all flags in the map and store them in a table&lt;br /&gt;
    -- go on loading information like in the example above&lt;br /&gt;
&lt;br /&gt;
    -- spawn players etc.&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
addEventHandler(&amp;quot;onGamemodeMapStart&amp;quot;, getRootElement(), startCtfMap)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Making maps compatible===&lt;br /&gt;
Maps are separate resources. This is done so no editing of the gamemode resource is ever necessary in order to create a custom map, and also allows you to pack map-specific scripts/config files with them.&lt;br /&gt;
&lt;br /&gt;
To make a map compatible with your gamemode, open its resource's meta.xml and tag it as well: the &amp;quot;type&amp;quot; attribute must be set to &amp;quot;map&amp;quot;, and the &amp;quot;gamemodes&amp;quot; attribute must be a comma-separated list (no spaces) of gamemode resource names that the map works with.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--map's meta.xml--&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info type=&amp;quot;map&amp;quot; gamemodes=&amp;quot;cowcatapult,assault,tdm&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have everything set up, admins will use these two commands to start/stop gamemodes:&lt;br /&gt;
/gamemode gamemodeName [mapName] (optional parameter allows picking an initial map, defaults to none)&lt;br /&gt;
/changemap mapName [gamemodeName] (optional parameter specifies the gamemode to start the map with, defaults to the current one)&lt;br /&gt;
&lt;br /&gt;
[[Map manager]] exports a few more access functions which you don't have to use, but may be useful.&lt;br /&gt;
&lt;br /&gt;
==What else should you do==&lt;br /&gt;
There are several other resources that gamemodes should use/be compliant with.&lt;br /&gt;
&lt;br /&gt;
===Helpmanager===&lt;br /&gt;
The helpmanager is ought to be the standard interface for players when they need help. If you use the helpmanager to display your gamemode's help, every player that used helpmanager before (e.g. in other gamemodes) will immediately know how to get there. It also displays help for different resources running resources in one window, if necessary.&lt;br /&gt;
&lt;br /&gt;
There are basicially two ways to use the helpmanager:&lt;br /&gt;
* Provide a simple text that explains how to use your gamemode&lt;br /&gt;
* Request a GUI element from the helpmanager that will be displayed in its own tab in the helpmanager window and lets you add any GUI elements to it. This is the recommended way for gamemodes that need to display more complex information that needs its own GUI.&lt;br /&gt;
&lt;br /&gt;
Read the helpmanager page for details on how to do it.&lt;br /&gt;
&lt;br /&gt;
===Scoreboard===&lt;br /&gt;
Scoreboard displays players and teams currently ingame. You add custom columns to it to provide map specific information. For example the column 'points' in the 'ctf' gamemode could represent the player's points gained through kills or captures. As usual, see the scoreboard help page for more information.&lt;br /&gt;
&lt;br /&gt;
===Map cycler===&lt;br /&gt;
The map cycler controls what gamemodes and maps are played on a server. You can specifiy for example how many times in a row a map will be played until it switches to the next. To achieve this, you need to tell the map cycler when your gamemode finished (e.g. when a round ends).&lt;br /&gt;
&lt;br /&gt;
[[en:Writing Gamemodes]]&lt;br /&gt;
[[it:Scrivere una gamemode]]&lt;/div&gt;</summary>
		<author><name>103495106181459904329</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=RU/Writing_Gamemodes&amp;diff=25917</id>
		<title>RU/Writing Gamemodes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=RU/Writing_Gamemodes&amp;diff=25917"/>
		<updated>2011-05-30T05:47:58Z</updated>

		<summary type="html">&lt;p&gt;103495106181459904329: /* Менеджер карт */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{translate}}&lt;br /&gt;
Это руководство поможет вам, как написать правильный режим игры. Если вы только что начали писать скрипты для MTA, вы должны сначала просмотреть другие учебники на [[RU/Main Page|Главная страница]].&lt;br /&gt;
==Введение==&lt;br /&gt;
Gamemode (ГМ, мод, гейммод, игровой режим) - ресурс, который, будучи запущенным, контролирует весь игровой процесс. Гейммод включает в себя отправку сообщений игрокам - указания к действиям, респаун игроков, создание команд, указаний, что игрокам нужно делать для победы, или для получения очков, и т.д. Примеры - гонки и DeatMatch'и.&lt;br /&gt;
&lt;br /&gt;
==Что означает &amp;quot;правильный игровой режим&amp;quot;?==&lt;br /&gt;
Проще говоря, правильным игровым режимом можно назвать такой режим, который в полной мере использует MTA систему .map файлов. Это означает, что код игрового режима не имеет любых специфических карт, данные которых жестко привязаны к нему, такие как положение игроков или автомобилей. Вместо этого, игровой режим должен быть в состоянии загружать .map файлы, которые и будут определять эти данные. Таким образом, игровой режим может иметь несколько карт, а также люди смогут создавать .map файлы для игрового режима используя MTA редактор карт, который является гораздо более удобным, чем написание кода.&lt;br /&gt;
&lt;br /&gt;
Очевидным примеров &amp;quot;правильного игрового режима&amp;quot; является MTA: Race. Он допускает пользовательские карты с большим количеством возможностей внутри .map файла. Чтобы изменить точки появления игроков, объекты и т.д., пользователю не нужно изменять сам игровой режим.&lt;br /&gt;
&lt;br /&gt;
===Файлы карт===&lt;br /&gt;
Файлы карт основываются на XML документах с форматом .map. Они определяют контекст игры для одного или нескольких конкретных игровых режимов. Однако, они не должны менять правила игры, которые определены игровым режимом.&lt;br /&gt;
&lt;br /&gt;
Каждый элемент на карте соответствует узлу .map файла. Существует стандартный синтаксис для общих элементов, таких как точки появления игроков, объекты и транспортные средства. Для особых же элементов карты, соответствующих специфике игрового режима, вам нужно придумать собственный синтаксис.&lt;br /&gt;
&lt;br /&gt;
====Пример====&lt;br /&gt;
Давайте для примера возьмем режим Capture the Flag. Карта для этого режима нуждается главным образом в определенных точках появления игроков, расположенных флагах и в конце концов объектах и транспортных средствах. Упрощенный файл карты может выглядеть следующим образом:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;map&amp;gt;&lt;br /&gt;
    &amp;lt;spawnpoint id=&amp;quot;spawnpoint1&amp;quot; posX=&amp;quot;1959.5487060547&amp;quot; posY=&amp;quot;-1714.4613037109&amp;quot; posZ=&amp;quot;877.25219726563&amp;quot; rot=&amp;quot;63.350006103516&amp;quot; model=&amp;quot;0&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;pickup id=&amp;quot;Armor 1&amp;quot; posX=&amp;quot;1911.083984375&amp;quot; posY=&amp;quot;-1658.8798828125&amp;quot; posZ=&amp;quot;885.40216064453&amp;quot; type=&amp;quot;armor&amp;quot; health=&amp;quot;50&amp;quot; respawn=&amp;quot;60000&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;flag posX=&amp;quot;1959.5487060547&amp;quot; posY=&amp;quot;-1714.4613037109&amp;quot; posZ=&amp;quot;877.25219726563&amp;quot; team=&amp;quot;blue&amp;quot; /&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
&amp;lt;/map&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Здесь вы можете увидеть два MTA элемента - точку появления игрока и пикап. Что еще более важно, карта имеет пользовательский узел &amp;quot;flag&amp;quot;, который определяет положение и цвет флага. Точка появления игрока и пикап могут быть обработаны путем существующих внешних ресурсов, пользовательские элементы должны быть обработаны игровым режимом.&lt;br /&gt;
&lt;br /&gt;
To summarize - we want mass mapper input as we saw in MTA:Race. Users should NOT have to touch the gamemode script itself at all.&lt;br /&gt;
&lt;br /&gt;
====Пример получения .map информации====&lt;br /&gt;
Как уже упоминалось выше, вашему игровому режиму нужно получить пользовательские элементы, которые определены в файле карты, и обработать их. Это довольно просто, как показано ниже.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- получаем таблицу со всеми элементами типа &amp;quot;flag&amp;quot;&lt;br /&gt;
local flagElements = getElementsByType ( &amp;quot;flag&amp;quot; )&lt;br /&gt;
-- пропускаем их через цикл&lt;br /&gt;
for key, value in pairs(flagElements) do&lt;br /&gt;
	-- получаем нашу информацию&lt;br /&gt;
	local posX = getElementData ( value, &amp;quot;posX&amp;quot; )&lt;br /&gt;
	local posY = getElementData ( value, &amp;quot;posY&amp;quot; )&lt;br /&gt;
	local posZ = getElementData ( value, &amp;quot;posZ&amp;quot; )&lt;br /&gt;
	local team = getElementData ( value, &amp;quot;team&amp;quot; )&lt;br /&gt;
	-- создаем объект в соответствии с положением флага&lt;br /&gt;
	createObject ( 1337, posX, posY, posZ )&lt;br /&gt;
	-- выводим команду, для которой мы создали базу&lt;br /&gt;
	outputChatBox ( &amp;quot;Base for team &amp;quot; .. team .. &amp;quot; created&amp;quot; )&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Функция [[getElementsByType]] возвращает таблицу всех элементов определенного типа (тип соответствует имени узла в .map файле). Это работает как с пользовательскими типами, так и со встроенными в МТА(например, &amp;quot;vehicle&amp;quot; или &amp;quot;player&amp;quot;).&lt;br /&gt;
[[getElementData]] может быть использована для получения XML-атрибутов в .map файле.&lt;br /&gt;
В этом простом примере объект создается на месте флага и в окно чата выводится сообщение. В действительности, вы конечно должны делать все это во время загрузки карты, так как в этом случае создается форма столкновения для обнаружения игроков с флагом.&lt;br /&gt;
&lt;br /&gt;
==Менеджер карт==&lt;br /&gt;
Прочитав раздел выше должно быть понятно, что игровой режим всегда должен состоять из двух частей:&lt;br /&gt;
* Ресурс игрового режима, который всегда остается неизменным&lt;br /&gt;
* Множество различных ресурсов карт, которые дают игровому режиму конкретную карту содержащую информацию&lt;br /&gt;
&lt;br /&gt;
Теперь вместо того чтобы писать загрузчик карт для каждого игрового режима, [[Map manager]] предоставляет функции для загрузки этих самых режимов и карт. Simply put, when you enter the correct command (for example 'gamemode ctf ctf-italy') it will start both resources 'ctf' and 'ctf-italy' while triggering an event ([[onGamemodeMapStart]]) to tell the 'ctf' resource that a map was loaded. The 'ctf' resource can then access the information 'ctf-italy' contains and start spawning players etc.&lt;br /&gt;
&lt;br /&gt;
===How to use the mapmanager===&lt;br /&gt;
To use the mapmanager service, your gamemode resource has to be tagged as such first. More specifically you'll be setting the &amp;quot;type&amp;quot; attribute of its &amp;lt;info&amp;gt; tag to &amp;quot;gamemode&amp;quot; inside meta.xml. Also, you can set the &amp;quot;name&amp;quot; attribute to a friendly name (like &amp;quot;Capture the flag&amp;quot;) that will be shown on ASE instead of the resource name.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- meta.xml in &amp;quot;cowcatapult&amp;quot; gamemode --&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info type=&amp;quot;gamemode&amp;quot; name=&amp;quot;Cow catapulting 2.0&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your gamemode is going to load custom maps, you should add handlers for&lt;br /&gt;
* onGamemodeMapStart&lt;br /&gt;
* onGamemodeMapStop (if any unloading is necessary)&lt;br /&gt;
These are fired when a map for your gamemode is started or stopped, and pass the map resource as a parameter.&lt;br /&gt;
Within the handler function for these events you can extract all info you need from the resource's map files and configuration files.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function startCtfMap( startedMap ) -- startedMap contains a reference to the resource of the map&lt;br /&gt;
    local mapRoot = getResourceRootElement( startedMap )        -- get the root node of the started map&lt;br /&gt;
    local flagElements = getElementsByType ( &amp;quot;flag&amp;quot; , mapRoot ) -- get all flags in the map and store them in a table&lt;br /&gt;
    -- go on loading information like in the example above&lt;br /&gt;
&lt;br /&gt;
    -- spawn players etc.&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
addEventHandler(&amp;quot;onGamemodeMapStart&amp;quot;, getRootElement(), startCtfMap)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Making maps compatible===&lt;br /&gt;
Maps are separate resources. This is done so no editing of the gamemode resource is ever necessary in order to create a custom map, and also allows you to pack map-specific scripts/config files with them.&lt;br /&gt;
&lt;br /&gt;
To make a map compatible with your gamemode, open its resource's meta.xml and tag it as well: the &amp;quot;type&amp;quot; attribute must be set to &amp;quot;map&amp;quot;, and the &amp;quot;gamemodes&amp;quot; attribute must be a comma-separated list (no spaces) of gamemode resource names that the map works with.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--map's meta.xml--&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info type=&amp;quot;map&amp;quot; gamemodes=&amp;quot;cowcatapult,assault,tdm&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have everything set up, admins will use these two commands to start/stop gamemodes:&lt;br /&gt;
/gamemode gamemodeName [mapName] (optional parameter allows picking an initial map, defaults to none)&lt;br /&gt;
/changemap mapName [gamemodeName] (optional parameter specifies the gamemode to start the map with, defaults to the current one)&lt;br /&gt;
&lt;br /&gt;
[[Map manager]] exports a few more access functions which you don't have to use, but may be useful.&lt;br /&gt;
&lt;br /&gt;
==What else should you do==&lt;br /&gt;
There are several other resources that gamemodes should use/be compliant with.&lt;br /&gt;
&lt;br /&gt;
===Helpmanager===&lt;br /&gt;
The helpmanager is ought to be the standard interface for players when they need help. If you use the helpmanager to display your gamemode's help, every player that used helpmanager before (e.g. in other gamemodes) will immediately know how to get there. It also displays help for different resources running resources in one window, if necessary.&lt;br /&gt;
&lt;br /&gt;
There are basicially two ways to use the helpmanager:&lt;br /&gt;
* Provide a simple text that explains how to use your gamemode&lt;br /&gt;
* Request a GUI element from the helpmanager that will be displayed in its own tab in the helpmanager window and lets you add any GUI elements to it. This is the recommended way for gamemodes that need to display more complex information that needs its own GUI.&lt;br /&gt;
&lt;br /&gt;
Read the helpmanager page for details on how to do it.&lt;br /&gt;
&lt;br /&gt;
===Scoreboard===&lt;br /&gt;
Scoreboard displays players and teams currently ingame. You add custom columns to it to provide map specific information. For example the column 'points' in the 'ctf' gamemode could represent the player's points gained through kills or captures. As usual, see the scoreboard help page for more information.&lt;br /&gt;
&lt;br /&gt;
===Map cycler===&lt;br /&gt;
The map cycler controls what gamemodes and maps are played on a server. You can specifiy for example how many times in a row a map will be played until it switches to the next. To achieve this, you need to tell the map cycler when your gamemode finished (e.g. when a round ends).&lt;br /&gt;
&lt;br /&gt;
[[en:Writing Gamemodes]]&lt;br /&gt;
[[it:Scrivere una gamemode]]&lt;/div&gt;</summary>
		<author><name>103495106181459904329</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=RU/Writing_Gamemodes&amp;diff=25916</id>
		<title>RU/Writing Gamemodes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=RU/Writing_Gamemodes&amp;diff=25916"/>
		<updated>2011-05-30T05:47:34Z</updated>

		<summary type="html">&lt;p&gt;103495106181459904329: /* Map manager */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{translate}}&lt;br /&gt;
Это руководство поможет вам, как написать правильный режим игры. Если вы только что начали писать скрипты для MTA, вы должны сначала просмотреть другие учебники на [[RU/Main Page|Главная страница]].&lt;br /&gt;
==Введение==&lt;br /&gt;
Gamemode (ГМ, мод, гейммод, игровой режим) - ресурс, который, будучи запущенным, контролирует весь игровой процесс. Гейммод включает в себя отправку сообщений игрокам - указания к действиям, респаун игроков, создание команд, указаний, что игрокам нужно делать для победы, или для получения очков, и т.д. Примеры - гонки и DeatMatch'и.&lt;br /&gt;
&lt;br /&gt;
==Что означает &amp;quot;правильный игровой режим&amp;quot;?==&lt;br /&gt;
Проще говоря, правильным игровым режимом можно назвать такой режим, который в полной мере использует MTA систему .map файлов. Это означает, что код игрового режима не имеет любых специфических карт, данные которых жестко привязаны к нему, такие как положение игроков или автомобилей. Вместо этого, игровой режим должен быть в состоянии загружать .map файлы, которые и будут определять эти данные. Таким образом, игровой режим может иметь несколько карт, а также люди смогут создавать .map файлы для игрового режима используя MTA редактор карт, который является гораздо более удобным, чем написание кода.&lt;br /&gt;
&lt;br /&gt;
Очевидным примеров &amp;quot;правильного игрового режима&amp;quot; является MTA: Race. Он допускает пользовательские карты с большим количеством возможностей внутри .map файла. Чтобы изменить точки появления игроков, объекты и т.д., пользователю не нужно изменять сам игровой режим.&lt;br /&gt;
&lt;br /&gt;
===Файлы карт===&lt;br /&gt;
Файлы карт основываются на XML документах с форматом .map. Они определяют контекст игры для одного или нескольких конкретных игровых режимов. Однако, они не должны менять правила игры, которые определены игровым режимом.&lt;br /&gt;
&lt;br /&gt;
Каждый элемент на карте соответствует узлу .map файла. Существует стандартный синтаксис для общих элементов, таких как точки появления игроков, объекты и транспортные средства. Для особых же элементов карты, соответствующих специфике игрового режима, вам нужно придумать собственный синтаксис.&lt;br /&gt;
&lt;br /&gt;
====Пример====&lt;br /&gt;
Давайте для примера возьмем режим Capture the Flag. Карта для этого режима нуждается главным образом в определенных точках появления игроков, расположенных флагах и в конце концов объектах и транспортных средствах. Упрощенный файл карты может выглядеть следующим образом:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;map&amp;gt;&lt;br /&gt;
    &amp;lt;spawnpoint id=&amp;quot;spawnpoint1&amp;quot; posX=&amp;quot;1959.5487060547&amp;quot; posY=&amp;quot;-1714.4613037109&amp;quot; posZ=&amp;quot;877.25219726563&amp;quot; rot=&amp;quot;63.350006103516&amp;quot; model=&amp;quot;0&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;pickup id=&amp;quot;Armor 1&amp;quot; posX=&amp;quot;1911.083984375&amp;quot; posY=&amp;quot;-1658.8798828125&amp;quot; posZ=&amp;quot;885.40216064453&amp;quot; type=&amp;quot;armor&amp;quot; health=&amp;quot;50&amp;quot; respawn=&amp;quot;60000&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;flag posX=&amp;quot;1959.5487060547&amp;quot; posY=&amp;quot;-1714.4613037109&amp;quot; posZ=&amp;quot;877.25219726563&amp;quot; team=&amp;quot;blue&amp;quot; /&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
&amp;lt;/map&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Здесь вы можете увидеть два MTA элемента - точку появления игрока и пикап. Что еще более важно, карта имеет пользовательский узел &amp;quot;flag&amp;quot;, который определяет положение и цвет флага. Точка появления игрока и пикап могут быть обработаны путем существующих внешних ресурсов, пользовательские элементы должны быть обработаны игровым режимом.&lt;br /&gt;
&lt;br /&gt;
To summarize - we want mass mapper input as we saw in MTA:Race. Users should NOT have to touch the gamemode script itself at all.&lt;br /&gt;
&lt;br /&gt;
====Пример получения .map информации====&lt;br /&gt;
Как уже упоминалось выше, вашему игровому режиму нужно получить пользовательские элементы, которые определены в файле карты, и обработать их. Это довольно просто, как показано ниже.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- получаем таблицу со всеми элементами типа &amp;quot;flag&amp;quot;&lt;br /&gt;
local flagElements = getElementsByType ( &amp;quot;flag&amp;quot; )&lt;br /&gt;
-- пропускаем их через цикл&lt;br /&gt;
for key, value in pairs(flagElements) do&lt;br /&gt;
	-- получаем нашу информацию&lt;br /&gt;
	local posX = getElementData ( value, &amp;quot;posX&amp;quot; )&lt;br /&gt;
	local posY = getElementData ( value, &amp;quot;posY&amp;quot; )&lt;br /&gt;
	local posZ = getElementData ( value, &amp;quot;posZ&amp;quot; )&lt;br /&gt;
	local team = getElementData ( value, &amp;quot;team&amp;quot; )&lt;br /&gt;
	-- создаем объект в соответствии с положением флага&lt;br /&gt;
	createObject ( 1337, posX, posY, posZ )&lt;br /&gt;
	-- выводим команду, для которой мы создали базу&lt;br /&gt;
	outputChatBox ( &amp;quot;Base for team &amp;quot; .. team .. &amp;quot; created&amp;quot; )&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Функция [[getElementsByType]] возвращает таблицу всех элементов определенного типа (тип соответствует имени узла в .map файле). Это работает как с пользовательскими типами, так и со встроенными в МТА(например, &amp;quot;vehicle&amp;quot; или &amp;quot;player&amp;quot;).&lt;br /&gt;
[[getElementData]] может быть использована для получения XML-атрибутов в .map файле.&lt;br /&gt;
В этом простом примере объект создается на месте флага и в окно чата выводится сообщение. В действительности, вы конечно должны делать все это во время загрузки карты, так как в этом случае создается форма столкновения для обнаружения игроков с флагом.&lt;br /&gt;
&lt;br /&gt;
==Менеджер карт==&lt;br /&gt;
Прочитав раздел выше должно быть понятно, что режим игры всегда должен состоять из двух частей:&lt;br /&gt;
* Ресурс игрового режима, который всегда остается неизменным&lt;br /&gt;
* Множество различных ресурсов карт, которые дают игровому режиму конкретную карту содержащую информацию&lt;br /&gt;
&lt;br /&gt;
Теперь вместо того чтобы писать загрузчик карт для каждого игрового режима, [[Map manager]] предоставляет функции для загрузки этих самых режимов и карт. Simply put, when you enter the correct command (for example 'gamemode ctf ctf-italy') it will start both resources 'ctf' and 'ctf-italy' while triggering an event ([[onGamemodeMapStart]]) to tell the 'ctf' resource that a map was loaded. The 'ctf' resource can then access the information 'ctf-italy' contains and start spawning players etc.&lt;br /&gt;
&lt;br /&gt;
===How to use the mapmanager===&lt;br /&gt;
To use the mapmanager service, your gamemode resource has to be tagged as such first. More specifically you'll be setting the &amp;quot;type&amp;quot; attribute of its &amp;lt;info&amp;gt; tag to &amp;quot;gamemode&amp;quot; inside meta.xml. Also, you can set the &amp;quot;name&amp;quot; attribute to a friendly name (like &amp;quot;Capture the flag&amp;quot;) that will be shown on ASE instead of the resource name.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- meta.xml in &amp;quot;cowcatapult&amp;quot; gamemode --&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info type=&amp;quot;gamemode&amp;quot; name=&amp;quot;Cow catapulting 2.0&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your gamemode is going to load custom maps, you should add handlers for&lt;br /&gt;
* onGamemodeMapStart&lt;br /&gt;
* onGamemodeMapStop (if any unloading is necessary)&lt;br /&gt;
These are fired when a map for your gamemode is started or stopped, and pass the map resource as a parameter.&lt;br /&gt;
Within the handler function for these events you can extract all info you need from the resource's map files and configuration files.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function startCtfMap( startedMap ) -- startedMap contains a reference to the resource of the map&lt;br /&gt;
    local mapRoot = getResourceRootElement( startedMap )        -- get the root node of the started map&lt;br /&gt;
    local flagElements = getElementsByType ( &amp;quot;flag&amp;quot; , mapRoot ) -- get all flags in the map and store them in a table&lt;br /&gt;
    -- go on loading information like in the example above&lt;br /&gt;
&lt;br /&gt;
    -- spawn players etc.&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
addEventHandler(&amp;quot;onGamemodeMapStart&amp;quot;, getRootElement(), startCtfMap)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Making maps compatible===&lt;br /&gt;
Maps are separate resources. This is done so no editing of the gamemode resource is ever necessary in order to create a custom map, and also allows you to pack map-specific scripts/config files with them.&lt;br /&gt;
&lt;br /&gt;
To make a map compatible with your gamemode, open its resource's meta.xml and tag it as well: the &amp;quot;type&amp;quot; attribute must be set to &amp;quot;map&amp;quot;, and the &amp;quot;gamemodes&amp;quot; attribute must be a comma-separated list (no spaces) of gamemode resource names that the map works with.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--map's meta.xml--&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info type=&amp;quot;map&amp;quot; gamemodes=&amp;quot;cowcatapult,assault,tdm&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have everything set up, admins will use these two commands to start/stop gamemodes:&lt;br /&gt;
/gamemode gamemodeName [mapName] (optional parameter allows picking an initial map, defaults to none)&lt;br /&gt;
/changemap mapName [gamemodeName] (optional parameter specifies the gamemode to start the map with, defaults to the current one)&lt;br /&gt;
&lt;br /&gt;
[[Map manager]] exports a few more access functions which you don't have to use, but may be useful.&lt;br /&gt;
&lt;br /&gt;
==What else should you do==&lt;br /&gt;
There are several other resources that gamemodes should use/be compliant with.&lt;br /&gt;
&lt;br /&gt;
===Helpmanager===&lt;br /&gt;
The helpmanager is ought to be the standard interface for players when they need help. If you use the helpmanager to display your gamemode's help, every player that used helpmanager before (e.g. in other gamemodes) will immediately know how to get there. It also displays help for different resources running resources in one window, if necessary.&lt;br /&gt;
&lt;br /&gt;
There are basicially two ways to use the helpmanager:&lt;br /&gt;
* Provide a simple text that explains how to use your gamemode&lt;br /&gt;
* Request a GUI element from the helpmanager that will be displayed in its own tab in the helpmanager window and lets you add any GUI elements to it. This is the recommended way for gamemodes that need to display more complex information that needs its own GUI.&lt;br /&gt;
&lt;br /&gt;
Read the helpmanager page for details on how to do it.&lt;br /&gt;
&lt;br /&gt;
===Scoreboard===&lt;br /&gt;
Scoreboard displays players and teams currently ingame. You add custom columns to it to provide map specific information. For example the column 'points' in the 'ctf' gamemode could represent the player's points gained through kills or captures. As usual, see the scoreboard help page for more information.&lt;br /&gt;
&lt;br /&gt;
===Map cycler===&lt;br /&gt;
The map cycler controls what gamemodes and maps are played on a server. You can specifiy for example how many times in a row a map will be played until it switches to the next. To achieve this, you need to tell the map cycler when your gamemode finished (e.g. when a round ends).&lt;br /&gt;
&lt;br /&gt;
[[en:Writing Gamemodes]]&lt;br /&gt;
[[it:Scrivere una gamemode]]&lt;/div&gt;</summary>
		<author><name>103495106181459904329</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=RU/Writing_Gamemodes&amp;diff=25915</id>
		<title>RU/Writing Gamemodes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=RU/Writing_Gamemodes&amp;diff=25915"/>
		<updated>2011-05-30T05:41:06Z</updated>

		<summary type="html">&lt;p&gt;103495106181459904329: /* Пример получения .map информации */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{translate}}&lt;br /&gt;
Это руководство поможет вам, как написать правильный режим игры. Если вы только что начали писать скрипты для MTA, вы должны сначала просмотреть другие учебники на [[RU/Main Page|Главная страница]].&lt;br /&gt;
==Введение==&lt;br /&gt;
Gamemode (ГМ, мод, гейммод, игровой режим) - ресурс, который, будучи запущенным, контролирует весь игровой процесс. Гейммод включает в себя отправку сообщений игрокам - указания к действиям, респаун игроков, создание команд, указаний, что игрокам нужно делать для победы, или для получения очков, и т.д. Примеры - гонки и DeatMatch'и.&lt;br /&gt;
&lt;br /&gt;
==Что означает &amp;quot;правильный игровой режим&amp;quot;?==&lt;br /&gt;
Проще говоря, правильным игровым режимом можно назвать такой режим, который в полной мере использует MTA систему .map файлов. Это означает, что код игрового режима не имеет любых специфических карт, данные которых жестко привязаны к нему, такие как положение игроков или автомобилей. Вместо этого, игровой режим должен быть в состоянии загружать .map файлы, которые и будут определять эти данные. Таким образом, игровой режим может иметь несколько карт, а также люди смогут создавать .map файлы для игрового режима используя MTA редактор карт, который является гораздо более удобным, чем написание кода.&lt;br /&gt;
&lt;br /&gt;
Очевидным примеров &amp;quot;правильного игрового режима&amp;quot; является MTA: Race. Он допускает пользовательские карты с большим количеством возможностей внутри .map файла. Чтобы изменить точки появления игроков, объекты и т.д., пользователю не нужно изменять сам игровой режим.&lt;br /&gt;
&lt;br /&gt;
===Файлы карт===&lt;br /&gt;
Файлы карт основываются на XML документах с форматом .map. Они определяют контекст игры для одного или нескольких конкретных игровых режимов. Однако, они не должны менять правила игры, которые определены игровым режимом.&lt;br /&gt;
&lt;br /&gt;
Каждый элемент на карте соответствует узлу .map файла. Существует стандартный синтаксис для общих элементов, таких как точки появления игроков, объекты и транспортные средства. Для особых же элементов карты, соответствующих специфике игрового режима, вам нужно придумать собственный синтаксис.&lt;br /&gt;
&lt;br /&gt;
====Пример====&lt;br /&gt;
Давайте для примера возьмем режим Capture the Flag. Карта для этого режима нуждается главным образом в определенных точках появления игроков, расположенных флагах и в конце концов объектах и транспортных средствах. Упрощенный файл карты может выглядеть следующим образом:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;map&amp;gt;&lt;br /&gt;
    &amp;lt;spawnpoint id=&amp;quot;spawnpoint1&amp;quot; posX=&amp;quot;1959.5487060547&amp;quot; posY=&amp;quot;-1714.4613037109&amp;quot; posZ=&amp;quot;877.25219726563&amp;quot; rot=&amp;quot;63.350006103516&amp;quot; model=&amp;quot;0&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;pickup id=&amp;quot;Armor 1&amp;quot; posX=&amp;quot;1911.083984375&amp;quot; posY=&amp;quot;-1658.8798828125&amp;quot; posZ=&amp;quot;885.40216064453&amp;quot; type=&amp;quot;armor&amp;quot; health=&amp;quot;50&amp;quot; respawn=&amp;quot;60000&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;flag posX=&amp;quot;1959.5487060547&amp;quot; posY=&amp;quot;-1714.4613037109&amp;quot; posZ=&amp;quot;877.25219726563&amp;quot; team=&amp;quot;blue&amp;quot; /&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
&amp;lt;/map&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Здесь вы можете увидеть два MTA элемента - точку появления игрока и пикап. Что еще более важно, карта имеет пользовательский узел &amp;quot;flag&amp;quot;, который определяет положение и цвет флага. Точка появления игрока и пикап могут быть обработаны путем существующих внешних ресурсов, пользовательские элементы должны быть обработаны игровым режимом.&lt;br /&gt;
&lt;br /&gt;
To summarize - we want mass mapper input as we saw in MTA:Race. Users should NOT have to touch the gamemode script itself at all.&lt;br /&gt;
&lt;br /&gt;
====Пример получения .map информации====&lt;br /&gt;
Как уже упоминалось выше, вашему игровому режиму нужно получить пользовательские элементы, которые определены в файле карты, и обработать их. Это довольно просто, как показано ниже.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- получаем таблицу со всеми элементами типа &amp;quot;flag&amp;quot;&lt;br /&gt;
local flagElements = getElementsByType ( &amp;quot;flag&amp;quot; )&lt;br /&gt;
-- пропускаем их через цикл&lt;br /&gt;
for key, value in pairs(flagElements) do&lt;br /&gt;
	-- получаем нашу информацию&lt;br /&gt;
	local posX = getElementData ( value, &amp;quot;posX&amp;quot; )&lt;br /&gt;
	local posY = getElementData ( value, &amp;quot;posY&amp;quot; )&lt;br /&gt;
	local posZ = getElementData ( value, &amp;quot;posZ&amp;quot; )&lt;br /&gt;
	local team = getElementData ( value, &amp;quot;team&amp;quot; )&lt;br /&gt;
	-- создаем объект в соответствии с положением флага&lt;br /&gt;
	createObject ( 1337, posX, posY, posZ )&lt;br /&gt;
	-- выводим команду, для которой мы создали базу&lt;br /&gt;
	outputChatBox ( &amp;quot;Base for team &amp;quot; .. team .. &amp;quot; created&amp;quot; )&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Функция [[getElementsByType]] возвращает таблицу всех элементов определенного типа (тип соответствует имени узла в .map файле). Это работает как с пользовательскими типами, так и со встроенными в МТА(например, &amp;quot;vehicle&amp;quot; или &amp;quot;player&amp;quot;).&lt;br /&gt;
[[getElementData]] может быть использована для получения XML-атрибутов в .map файле.&lt;br /&gt;
В этом простом примере объект создается на месте флага и в окно чата выводится сообщение. В действительности, вы конечно должны делать все это во время загрузки карты, так как в этом случае создается форма столкновения для обнаружения игроков с флагом.&lt;br /&gt;
&lt;br /&gt;
==Map manager==&lt;br /&gt;
Having read the section above it should be clear that a gamemode should always consist of two parts:&lt;br /&gt;
* The gamemode resource that always stays the same&lt;br /&gt;
* Many different maps resources that give the gamemode map-specific information&lt;br /&gt;
&lt;br /&gt;
Now instead of writing a map-loader for every single gamemode, the [[Map manager]] provides functions to load gamemodes and maps. Simply put, when you enter the correct command (for example 'gamemode ctf ctf-italy') it will start both resources 'ctf' and 'ctf-italy' while triggering an event ([[onGamemodeMapStart]]) to tell the 'ctf' resource that a map was loaded. The 'ctf' resource can then access the information 'ctf-italy' contains and start spawning players etc.&lt;br /&gt;
&lt;br /&gt;
===How to use the mapmanager===&lt;br /&gt;
To use the mapmanager service, your gamemode resource has to be tagged as such first. More specifically you'll be setting the &amp;quot;type&amp;quot; attribute of its &amp;lt;info&amp;gt; tag to &amp;quot;gamemode&amp;quot; inside meta.xml. Also, you can set the &amp;quot;name&amp;quot; attribute to a friendly name (like &amp;quot;Capture the flag&amp;quot;) that will be shown on ASE instead of the resource name.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- meta.xml in &amp;quot;cowcatapult&amp;quot; gamemode --&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info type=&amp;quot;gamemode&amp;quot; name=&amp;quot;Cow catapulting 2.0&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your gamemode is going to load custom maps, you should add handlers for&lt;br /&gt;
* onGamemodeMapStart&lt;br /&gt;
* onGamemodeMapStop (if any unloading is necessary)&lt;br /&gt;
These are fired when a map for your gamemode is started or stopped, and pass the map resource as a parameter.&lt;br /&gt;
Within the handler function for these events you can extract all info you need from the resource's map files and configuration files.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function startCtfMap( startedMap ) -- startedMap contains a reference to the resource of the map&lt;br /&gt;
    local mapRoot = getResourceRootElement( startedMap )        -- get the root node of the started map&lt;br /&gt;
    local flagElements = getElementsByType ( &amp;quot;flag&amp;quot; , mapRoot ) -- get all flags in the map and store them in a table&lt;br /&gt;
    -- go on loading information like in the example above&lt;br /&gt;
&lt;br /&gt;
    -- spawn players etc.&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
addEventHandler(&amp;quot;onGamemodeMapStart&amp;quot;, getRootElement(), startCtfMap)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Making maps compatible===&lt;br /&gt;
Maps are separate resources. This is done so no editing of the gamemode resource is ever necessary in order to create a custom map, and also allows you to pack map-specific scripts/config files with them.&lt;br /&gt;
&lt;br /&gt;
To make a map compatible with your gamemode, open its resource's meta.xml and tag it as well: the &amp;quot;type&amp;quot; attribute must be set to &amp;quot;map&amp;quot;, and the &amp;quot;gamemodes&amp;quot; attribute must be a comma-separated list (no spaces) of gamemode resource names that the map works with.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--map's meta.xml--&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info type=&amp;quot;map&amp;quot; gamemodes=&amp;quot;cowcatapult,assault,tdm&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have everything set up, admins will use these two commands to start/stop gamemodes:&lt;br /&gt;
/gamemode gamemodeName [mapName] (optional parameter allows picking an initial map, defaults to none)&lt;br /&gt;
/changemap mapName [gamemodeName] (optional parameter specifies the gamemode to start the map with, defaults to the current one)&lt;br /&gt;
&lt;br /&gt;
[[Map manager]] exports a few more access functions which you don't have to use, but may be useful.&lt;br /&gt;
&lt;br /&gt;
==What else should you do==&lt;br /&gt;
There are several other resources that gamemodes should use/be compliant with.&lt;br /&gt;
&lt;br /&gt;
===Helpmanager===&lt;br /&gt;
The helpmanager is ought to be the standard interface for players when they need help. If you use the helpmanager to display your gamemode's help, every player that used helpmanager before (e.g. in other gamemodes) will immediately know how to get there. It also displays help for different resources running resources in one window, if necessary.&lt;br /&gt;
&lt;br /&gt;
There are basicially two ways to use the helpmanager:&lt;br /&gt;
* Provide a simple text that explains how to use your gamemode&lt;br /&gt;
* Request a GUI element from the helpmanager that will be displayed in its own tab in the helpmanager window and lets you add any GUI elements to it. This is the recommended way for gamemodes that need to display more complex information that needs its own GUI.&lt;br /&gt;
&lt;br /&gt;
Read the helpmanager page for details on how to do it.&lt;br /&gt;
&lt;br /&gt;
===Scoreboard===&lt;br /&gt;
Scoreboard displays players and teams currently ingame. You add custom columns to it to provide map specific information. For example the column 'points' in the 'ctf' gamemode could represent the player's points gained through kills or captures. As usual, see the scoreboard help page for more information.&lt;br /&gt;
&lt;br /&gt;
===Map cycler===&lt;br /&gt;
The map cycler controls what gamemodes and maps are played on a server. You can specifiy for example how many times in a row a map will be played until it switches to the next. To achieve this, you need to tell the map cycler when your gamemode finished (e.g. when a round ends).&lt;br /&gt;
&lt;br /&gt;
[[en:Writing Gamemodes]]&lt;br /&gt;
[[it:Scrivere una gamemode]]&lt;/div&gt;</summary>
		<author><name>103495106181459904329</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=RU/Writing_Gamemodes&amp;diff=25914</id>
		<title>RU/Writing Gamemodes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=RU/Writing_Gamemodes&amp;diff=25914"/>
		<updated>2011-05-30T05:34:36Z</updated>

		<summary type="html">&lt;p&gt;103495106181459904329: /* Пример получения .map информации */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{translate}}&lt;br /&gt;
Это руководство поможет вам, как написать правильный режим игры. Если вы только что начали писать скрипты для MTA, вы должны сначала просмотреть другие учебники на [[RU/Main Page|Главная страница]].&lt;br /&gt;
==Введение==&lt;br /&gt;
Gamemode (ГМ, мод, гейммод, игровой режим) - ресурс, который, будучи запущенным, контролирует весь игровой процесс. Гейммод включает в себя отправку сообщений игрокам - указания к действиям, респаун игроков, создание команд, указаний, что игрокам нужно делать для победы, или для получения очков, и т.д. Примеры - гонки и DeatMatch'и.&lt;br /&gt;
&lt;br /&gt;
==Что означает &amp;quot;правильный игровой режим&amp;quot;?==&lt;br /&gt;
Проще говоря, правильным игровым режимом можно назвать такой режим, который в полной мере использует MTA систему .map файлов. Это означает, что код игрового режима не имеет любых специфических карт, данные которых жестко привязаны к нему, такие как положение игроков или автомобилей. Вместо этого, игровой режим должен быть в состоянии загружать .map файлы, которые и будут определять эти данные. Таким образом, игровой режим может иметь несколько карт, а также люди смогут создавать .map файлы для игрового режима используя MTA редактор карт, который является гораздо более удобным, чем написание кода.&lt;br /&gt;
&lt;br /&gt;
Очевидным примеров &amp;quot;правильного игрового режима&amp;quot; является MTA: Race. Он допускает пользовательские карты с большим количеством возможностей внутри .map файла. Чтобы изменить точки появления игроков, объекты и т.д., пользователю не нужно изменять сам игровой режим.&lt;br /&gt;
&lt;br /&gt;
===Файлы карт===&lt;br /&gt;
Файлы карт основываются на XML документах с форматом .map. Они определяют контекст игры для одного или нескольких конкретных игровых режимов. Однако, они не должны менять правила игры, которые определены игровым режимом.&lt;br /&gt;
&lt;br /&gt;
Каждый элемент на карте соответствует узлу .map файла. Существует стандартный синтаксис для общих элементов, таких как точки появления игроков, объекты и транспортные средства. Для особых же элементов карты, соответствующих специфике игрового режима, вам нужно придумать собственный синтаксис.&lt;br /&gt;
&lt;br /&gt;
====Пример====&lt;br /&gt;
Давайте для примера возьмем режим Capture the Flag. Карта для этого режима нуждается главным образом в определенных точках появления игроков, расположенных флагах и в конце концов объектах и транспортных средствах. Упрощенный файл карты может выглядеть следующим образом:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;map&amp;gt;&lt;br /&gt;
    &amp;lt;spawnpoint id=&amp;quot;spawnpoint1&amp;quot; posX=&amp;quot;1959.5487060547&amp;quot; posY=&amp;quot;-1714.4613037109&amp;quot; posZ=&amp;quot;877.25219726563&amp;quot; rot=&amp;quot;63.350006103516&amp;quot; model=&amp;quot;0&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;pickup id=&amp;quot;Armor 1&amp;quot; posX=&amp;quot;1911.083984375&amp;quot; posY=&amp;quot;-1658.8798828125&amp;quot; posZ=&amp;quot;885.40216064453&amp;quot; type=&amp;quot;armor&amp;quot; health=&amp;quot;50&amp;quot; respawn=&amp;quot;60000&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;flag posX=&amp;quot;1959.5487060547&amp;quot; posY=&amp;quot;-1714.4613037109&amp;quot; posZ=&amp;quot;877.25219726563&amp;quot; team=&amp;quot;blue&amp;quot; /&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
&amp;lt;/map&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Здесь вы можете увидеть два MTA элемента - точку появления игрока и пикап. Что еще более важно, карта имеет пользовательский узел &amp;quot;flag&amp;quot;, который определяет положение и цвет флага. Точка появления игрока и пикап могут быть обработаны путем существующих внешних ресурсов, пользовательские элементы должны быть обработаны игровым режимом.&lt;br /&gt;
&lt;br /&gt;
To summarize - we want mass mapper input as we saw in MTA:Race. Users should NOT have to touch the gamemode script itself at all.&lt;br /&gt;
&lt;br /&gt;
====Пример получения .map информации====&lt;br /&gt;
Как уже упоминалось выше, вашему игровому режиму нужно получить пользовательские элементы, которые определены в файле карты, и обработать их. Это довольно просто, как показано ниже.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- получаем таблицу со всеми элементами типа &amp;quot;flag&amp;quot;&lt;br /&gt;
local flagElements = getElementsByType ( &amp;quot;flag&amp;quot; )&lt;br /&gt;
-- пропускаем их через цикл&lt;br /&gt;
for key, value in pairs(flagElements) do&lt;br /&gt;
	-- получаем нашу информацию&lt;br /&gt;
	local posX = getElementData ( value, &amp;quot;posX&amp;quot; )&lt;br /&gt;
	local posY = getElementData ( value, &amp;quot;posY&amp;quot; )&lt;br /&gt;
	local posZ = getElementData ( value, &amp;quot;posZ&amp;quot; )&lt;br /&gt;
	local team = getElementData ( value, &amp;quot;team&amp;quot; )&lt;br /&gt;
	-- создаем объект в соответствии с положением флага&lt;br /&gt;
	createObject ( 1337, posX, posY, posZ )&lt;br /&gt;
	-- выводим команду, для которой мы создали базу&lt;br /&gt;
	outputChatBox ( &amp;quot;Base for team &amp;quot; .. team .. &amp;quot; created&amp;quot; )&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Функция [[getElementsByType]] возвращает таблицу всех элементов определенного типа (тип соответствует имени узла в .map файле). Это работает как с пользовательскими типами, так и с встроенными в МТА(например, &amp;quot;vehicle&amp;quot; или &amp;quot;player&amp;quot;).&lt;br /&gt;
[[getElementData]] can be used to retrieve the xml attributes set in the .map file.&lt;br /&gt;
In this simple example, an object is created at the flag's location and a message is outputted in the chatbox. In reality, you will of course need to do more during map loading, like in this case setting up collision shapes to detect players taking the flag.&lt;br /&gt;
&lt;br /&gt;
==Map manager==&lt;br /&gt;
Having read the section above it should be clear that a gamemode should always consist of two parts:&lt;br /&gt;
* The gamemode resource that always stays the same&lt;br /&gt;
* Many different maps resources that give the gamemode map-specific information&lt;br /&gt;
&lt;br /&gt;
Now instead of writing a map-loader for every single gamemode, the [[Map manager]] provides functions to load gamemodes and maps. Simply put, when you enter the correct command (for example 'gamemode ctf ctf-italy') it will start both resources 'ctf' and 'ctf-italy' while triggering an event ([[onGamemodeMapStart]]) to tell the 'ctf' resource that a map was loaded. The 'ctf' resource can then access the information 'ctf-italy' contains and start spawning players etc.&lt;br /&gt;
&lt;br /&gt;
===How to use the mapmanager===&lt;br /&gt;
To use the mapmanager service, your gamemode resource has to be tagged as such first. More specifically you'll be setting the &amp;quot;type&amp;quot; attribute of its &amp;lt;info&amp;gt; tag to &amp;quot;gamemode&amp;quot; inside meta.xml. Also, you can set the &amp;quot;name&amp;quot; attribute to a friendly name (like &amp;quot;Capture the flag&amp;quot;) that will be shown on ASE instead of the resource name.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- meta.xml in &amp;quot;cowcatapult&amp;quot; gamemode --&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info type=&amp;quot;gamemode&amp;quot; name=&amp;quot;Cow catapulting 2.0&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your gamemode is going to load custom maps, you should add handlers for&lt;br /&gt;
* onGamemodeMapStart&lt;br /&gt;
* onGamemodeMapStop (if any unloading is necessary)&lt;br /&gt;
These are fired when a map for your gamemode is started or stopped, and pass the map resource as a parameter.&lt;br /&gt;
Within the handler function for these events you can extract all info you need from the resource's map files and configuration files.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function startCtfMap( startedMap ) -- startedMap contains a reference to the resource of the map&lt;br /&gt;
    local mapRoot = getResourceRootElement( startedMap )        -- get the root node of the started map&lt;br /&gt;
    local flagElements = getElementsByType ( &amp;quot;flag&amp;quot; , mapRoot ) -- get all flags in the map and store them in a table&lt;br /&gt;
    -- go on loading information like in the example above&lt;br /&gt;
&lt;br /&gt;
    -- spawn players etc.&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
addEventHandler(&amp;quot;onGamemodeMapStart&amp;quot;, getRootElement(), startCtfMap)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Making maps compatible===&lt;br /&gt;
Maps are separate resources. This is done so no editing of the gamemode resource is ever necessary in order to create a custom map, and also allows you to pack map-specific scripts/config files with them.&lt;br /&gt;
&lt;br /&gt;
To make a map compatible with your gamemode, open its resource's meta.xml and tag it as well: the &amp;quot;type&amp;quot; attribute must be set to &amp;quot;map&amp;quot;, and the &amp;quot;gamemodes&amp;quot; attribute must be a comma-separated list (no spaces) of gamemode resource names that the map works with.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--map's meta.xml--&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info type=&amp;quot;map&amp;quot; gamemodes=&amp;quot;cowcatapult,assault,tdm&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have everything set up, admins will use these two commands to start/stop gamemodes:&lt;br /&gt;
/gamemode gamemodeName [mapName] (optional parameter allows picking an initial map, defaults to none)&lt;br /&gt;
/changemap mapName [gamemodeName] (optional parameter specifies the gamemode to start the map with, defaults to the current one)&lt;br /&gt;
&lt;br /&gt;
[[Map manager]] exports a few more access functions which you don't have to use, but may be useful.&lt;br /&gt;
&lt;br /&gt;
==What else should you do==&lt;br /&gt;
There are several other resources that gamemodes should use/be compliant with.&lt;br /&gt;
&lt;br /&gt;
===Helpmanager===&lt;br /&gt;
The helpmanager is ought to be the standard interface for players when they need help. If you use the helpmanager to display your gamemode's help, every player that used helpmanager before (e.g. in other gamemodes) will immediately know how to get there. It also displays help for different resources running resources in one window, if necessary.&lt;br /&gt;
&lt;br /&gt;
There are basicially two ways to use the helpmanager:&lt;br /&gt;
* Provide a simple text that explains how to use your gamemode&lt;br /&gt;
* Request a GUI element from the helpmanager that will be displayed in its own tab in the helpmanager window and lets you add any GUI elements to it. This is the recommended way for gamemodes that need to display more complex information that needs its own GUI.&lt;br /&gt;
&lt;br /&gt;
Read the helpmanager page for details on how to do it.&lt;br /&gt;
&lt;br /&gt;
===Scoreboard===&lt;br /&gt;
Scoreboard displays players and teams currently ingame. You add custom columns to it to provide map specific information. For example the column 'points' in the 'ctf' gamemode could represent the player's points gained through kills or captures. As usual, see the scoreboard help page for more information.&lt;br /&gt;
&lt;br /&gt;
===Map cycler===&lt;br /&gt;
The map cycler controls what gamemodes and maps are played on a server. You can specifiy for example how many times in a row a map will be played until it switches to the next. To achieve this, you need to tell the map cycler when your gamemode finished (e.g. when a round ends).&lt;br /&gt;
&lt;br /&gt;
[[en:Writing Gamemodes]]&lt;br /&gt;
[[it:Scrivere una gamemode]]&lt;/div&gt;</summary>
		<author><name>103495106181459904329</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=RU/Writing_Gamemodes&amp;diff=25913</id>
		<title>RU/Writing Gamemodes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=RU/Writing_Gamemodes&amp;diff=25913"/>
		<updated>2011-05-30T05:29:37Z</updated>

		<summary type="html">&lt;p&gt;103495106181459904329: /* Example of getting the .map information */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{translate}}&lt;br /&gt;
Это руководство поможет вам, как написать правильный режим игры. Если вы только что начали писать скрипты для MTA, вы должны сначала просмотреть другие учебники на [[RU/Main Page|Главная страница]].&lt;br /&gt;
==Введение==&lt;br /&gt;
Gamemode (ГМ, мод, гейммод, игровой режим) - ресурс, который, будучи запущенным, контролирует весь игровой процесс. Гейммод включает в себя отправку сообщений игрокам - указания к действиям, респаун игроков, создание команд, указаний, что игрокам нужно делать для победы, или для получения очков, и т.д. Примеры - гонки и DeatMatch'и.&lt;br /&gt;
&lt;br /&gt;
==Что означает &amp;quot;правильный игровой режим&amp;quot;?==&lt;br /&gt;
Проще говоря, правильным игровым режимом можно назвать такой режим, который в полной мере использует MTA систему .map файлов. Это означает, что код игрового режима не имеет любых специфических карт, данные которых жестко привязаны к нему, такие как положение игроков или автомобилей. Вместо этого, игровой режим должен быть в состоянии загружать .map файлы, которые и будут определять эти данные. Таким образом, игровой режим может иметь несколько карт, а также люди смогут создавать .map файлы для игрового режима используя MTA редактор карт, который является гораздо более удобным, чем написание кода.&lt;br /&gt;
&lt;br /&gt;
Очевидным примеров &amp;quot;правильного игрового режима&amp;quot; является MTA: Race. Он допускает пользовательские карты с большим количеством возможностей внутри .map файла. Чтобы изменить точки появления игроков, объекты и т.д., пользователю не нужно изменять сам игровой режим.&lt;br /&gt;
&lt;br /&gt;
===Файлы карт===&lt;br /&gt;
Файлы карт основываются на XML документах с форматом .map. Они определяют контекст игры для одного или нескольких конкретных игровых режимов. Однако, они не должны менять правила игры, которые определены игровым режимом.&lt;br /&gt;
&lt;br /&gt;
Каждый элемент на карте соответствует узлу .map файла. Существует стандартный синтаксис для общих элементов, таких как точки появления игроков, объекты и транспортные средства. Для особых же элементов карты, соответствующих специфике игрового режима, вам нужно придумать собственный синтаксис.&lt;br /&gt;
&lt;br /&gt;
====Пример====&lt;br /&gt;
Давайте для примера возьмем режим Capture the Flag. Карта для этого режима нуждается главным образом в определенных точках появления игроков, расположенных флагах и в конце концов объектах и транспортных средствах. Упрощенный файл карты может выглядеть следующим образом:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;map&amp;gt;&lt;br /&gt;
    &amp;lt;spawnpoint id=&amp;quot;spawnpoint1&amp;quot; posX=&amp;quot;1959.5487060547&amp;quot; posY=&amp;quot;-1714.4613037109&amp;quot; posZ=&amp;quot;877.25219726563&amp;quot; rot=&amp;quot;63.350006103516&amp;quot; model=&amp;quot;0&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;pickup id=&amp;quot;Armor 1&amp;quot; posX=&amp;quot;1911.083984375&amp;quot; posY=&amp;quot;-1658.8798828125&amp;quot; posZ=&amp;quot;885.40216064453&amp;quot; type=&amp;quot;armor&amp;quot; health=&amp;quot;50&amp;quot; respawn=&amp;quot;60000&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;flag posX=&amp;quot;1959.5487060547&amp;quot; posY=&amp;quot;-1714.4613037109&amp;quot; posZ=&amp;quot;877.25219726563&amp;quot; team=&amp;quot;blue&amp;quot; /&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
&amp;lt;/map&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Здесь вы можете увидеть два MTA элемента - точку появления игрока и пикап. Что еще более важно, карта имеет пользовательский узел &amp;quot;flag&amp;quot;, который определяет положение и цвет флага. Точка появления игрока и пикап могут быть обработаны путем существующих внешних ресурсов, пользовательские элементы должны быть обработаны игровым режимом.&lt;br /&gt;
&lt;br /&gt;
To summarize - we want mass mapper input as we saw in MTA:Race. Users should NOT have to touch the gamemode script itself at all.&lt;br /&gt;
&lt;br /&gt;
====Пример получения .map информации====&lt;br /&gt;
Как уже упоминалось выше, вашему игровому режиму нужно получить пользовательские элементы, которые определены в файле карты, и обработать их. Это довольно просто, как показано ниже.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- получаем таблицу со всеми элементами типа &amp;quot;flag&amp;quot;&lt;br /&gt;
local flagElements = getElementsByType ( &amp;quot;flag&amp;quot; )&lt;br /&gt;
-- пропускаем их через цикл&lt;br /&gt;
for key, value in pairs(flagElements) do&lt;br /&gt;
	-- получаем нашу информацию&lt;br /&gt;
	local posX = getElementData ( value, &amp;quot;posX&amp;quot; )&lt;br /&gt;
	local posY = getElementData ( value, &amp;quot;posY&amp;quot; )&lt;br /&gt;
	local posZ = getElementData ( value, &amp;quot;posZ&amp;quot; )&lt;br /&gt;
	local team = getElementData ( value, &amp;quot;team&amp;quot; )&lt;br /&gt;
	-- создаем объект в соответствии с положением флага&lt;br /&gt;
	createObject ( 1337, posX, posY, posZ )&lt;br /&gt;
	-- выводим команду, для которой мы создали базу&lt;br /&gt;
	outputChatBox ( &amp;quot;Base for team &amp;quot; .. team .. &amp;quot; created&amp;quot; )&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The [[getElementsByType]] function retrieves a table of all the elements of a certain type (the type corresponds to the node name in the .map file). This works for both custom types and built-in MTA types (like &amp;quot;vehicle&amp;quot; or &amp;quot;player&amp;quot;).&lt;br /&gt;
[[getElementData]] can be used to retrieve the xml attributes set in the .map file.&lt;br /&gt;
In this simple example, an object is created at the flag's location and a message is outputted in the chatbox. In reality, you will of course need to do more during map loading, like in this case setting up collision shapes to detect players taking the flag.&lt;br /&gt;
&lt;br /&gt;
==Map manager==&lt;br /&gt;
Having read the section above it should be clear that a gamemode should always consist of two parts:&lt;br /&gt;
* The gamemode resource that always stays the same&lt;br /&gt;
* Many different maps resources that give the gamemode map-specific information&lt;br /&gt;
&lt;br /&gt;
Now instead of writing a map-loader for every single gamemode, the [[Map manager]] provides functions to load gamemodes and maps. Simply put, when you enter the correct command (for example 'gamemode ctf ctf-italy') it will start both resources 'ctf' and 'ctf-italy' while triggering an event ([[onGamemodeMapStart]]) to tell the 'ctf' resource that a map was loaded. The 'ctf' resource can then access the information 'ctf-italy' contains and start spawning players etc.&lt;br /&gt;
&lt;br /&gt;
===How to use the mapmanager===&lt;br /&gt;
To use the mapmanager service, your gamemode resource has to be tagged as such first. More specifically you'll be setting the &amp;quot;type&amp;quot; attribute of its &amp;lt;info&amp;gt; tag to &amp;quot;gamemode&amp;quot; inside meta.xml. Also, you can set the &amp;quot;name&amp;quot; attribute to a friendly name (like &amp;quot;Capture the flag&amp;quot;) that will be shown on ASE instead of the resource name.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- meta.xml in &amp;quot;cowcatapult&amp;quot; gamemode --&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info type=&amp;quot;gamemode&amp;quot; name=&amp;quot;Cow catapulting 2.0&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your gamemode is going to load custom maps, you should add handlers for&lt;br /&gt;
* onGamemodeMapStart&lt;br /&gt;
* onGamemodeMapStop (if any unloading is necessary)&lt;br /&gt;
These are fired when a map for your gamemode is started or stopped, and pass the map resource as a parameter.&lt;br /&gt;
Within the handler function for these events you can extract all info you need from the resource's map files and configuration files.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function startCtfMap( startedMap ) -- startedMap contains a reference to the resource of the map&lt;br /&gt;
    local mapRoot = getResourceRootElement( startedMap )        -- get the root node of the started map&lt;br /&gt;
    local flagElements = getElementsByType ( &amp;quot;flag&amp;quot; , mapRoot ) -- get all flags in the map and store them in a table&lt;br /&gt;
    -- go on loading information like in the example above&lt;br /&gt;
&lt;br /&gt;
    -- spawn players etc.&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
addEventHandler(&amp;quot;onGamemodeMapStart&amp;quot;, getRootElement(), startCtfMap)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Making maps compatible===&lt;br /&gt;
Maps are separate resources. This is done so no editing of the gamemode resource is ever necessary in order to create a custom map, and also allows you to pack map-specific scripts/config files with them.&lt;br /&gt;
&lt;br /&gt;
To make a map compatible with your gamemode, open its resource's meta.xml and tag it as well: the &amp;quot;type&amp;quot; attribute must be set to &amp;quot;map&amp;quot;, and the &amp;quot;gamemodes&amp;quot; attribute must be a comma-separated list (no spaces) of gamemode resource names that the map works with.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--map's meta.xml--&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info type=&amp;quot;map&amp;quot; gamemodes=&amp;quot;cowcatapult,assault,tdm&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have everything set up, admins will use these two commands to start/stop gamemodes:&lt;br /&gt;
/gamemode gamemodeName [mapName] (optional parameter allows picking an initial map, defaults to none)&lt;br /&gt;
/changemap mapName [gamemodeName] (optional parameter specifies the gamemode to start the map with, defaults to the current one)&lt;br /&gt;
&lt;br /&gt;
[[Map manager]] exports a few more access functions which you don't have to use, but may be useful.&lt;br /&gt;
&lt;br /&gt;
==What else should you do==&lt;br /&gt;
There are several other resources that gamemodes should use/be compliant with.&lt;br /&gt;
&lt;br /&gt;
===Helpmanager===&lt;br /&gt;
The helpmanager is ought to be the standard interface for players when they need help. If you use the helpmanager to display your gamemode's help, every player that used helpmanager before (e.g. in other gamemodes) will immediately know how to get there. It also displays help for different resources running resources in one window, if necessary.&lt;br /&gt;
&lt;br /&gt;
There are basicially two ways to use the helpmanager:&lt;br /&gt;
* Provide a simple text that explains how to use your gamemode&lt;br /&gt;
* Request a GUI element from the helpmanager that will be displayed in its own tab in the helpmanager window and lets you add any GUI elements to it. This is the recommended way for gamemodes that need to display more complex information that needs its own GUI.&lt;br /&gt;
&lt;br /&gt;
Read the helpmanager page for details on how to do it.&lt;br /&gt;
&lt;br /&gt;
===Scoreboard===&lt;br /&gt;
Scoreboard displays players and teams currently ingame. You add custom columns to it to provide map specific information. For example the column 'points' in the 'ctf' gamemode could represent the player's points gained through kills or captures. As usual, see the scoreboard help page for more information.&lt;br /&gt;
&lt;br /&gt;
===Map cycler===&lt;br /&gt;
The map cycler controls what gamemodes and maps are played on a server. You can specifiy for example how many times in a row a map will be played until it switches to the next. To achieve this, you need to tell the map cycler when your gamemode finished (e.g. when a round ends).&lt;br /&gt;
&lt;br /&gt;
[[en:Writing Gamemodes]]&lt;br /&gt;
[[it:Scrivere una gamemode]]&lt;/div&gt;</summary>
		<author><name>103495106181459904329</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=RU/Writing_Gamemodes&amp;diff=25912</id>
		<title>RU/Writing Gamemodes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=RU/Writing_Gamemodes&amp;diff=25912"/>
		<updated>2011-05-30T05:22:07Z</updated>

		<summary type="html">&lt;p&gt;103495106181459904329: /* Пример */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{translate}}&lt;br /&gt;
Это руководство поможет вам, как написать правильный режим игры. Если вы только что начали писать скрипты для MTA, вы должны сначала просмотреть другие учебники на [[RU/Main Page|Главная страница]].&lt;br /&gt;
==Введение==&lt;br /&gt;
Gamemode (ГМ, мод, гейммод, игровой режим) - ресурс, который, будучи запущенным, контролирует весь игровой процесс. Гейммод включает в себя отправку сообщений игрокам - указания к действиям, респаун игроков, создание команд, указаний, что игрокам нужно делать для победы, или для получения очков, и т.д. Примеры - гонки и DeatMatch'и.&lt;br /&gt;
&lt;br /&gt;
==Что означает &amp;quot;правильный игровой режим&amp;quot;?==&lt;br /&gt;
Проще говоря, правильным игровым режимом можно назвать такой режим, который в полной мере использует MTA систему .map файлов. Это означает, что код игрового режима не имеет любых специфических карт, данные которых жестко привязаны к нему, такие как положение игроков или автомобилей. Вместо этого, игровой режим должен быть в состоянии загружать .map файлы, которые и будут определять эти данные. Таким образом, игровой режим может иметь несколько карт, а также люди смогут создавать .map файлы для игрового режима используя MTA редактор карт, который является гораздо более удобным, чем написание кода.&lt;br /&gt;
&lt;br /&gt;
Очевидным примеров &amp;quot;правильного игрового режима&amp;quot; является MTA: Race. Он допускает пользовательские карты с большим количеством возможностей внутри .map файла. Чтобы изменить точки появления игроков, объекты и т.д., пользователю не нужно изменять сам игровой режим.&lt;br /&gt;
&lt;br /&gt;
===Файлы карт===&lt;br /&gt;
Файлы карт основываются на XML документах с форматом .map. Они определяют контекст игры для одного или нескольких конкретных игровых режимов. Однако, они не должны менять правила игры, которые определены игровым режимом.&lt;br /&gt;
&lt;br /&gt;
Каждый элемент на карте соответствует узлу .map файла. Существует стандартный синтаксис для общих элементов, таких как точки появления игроков, объекты и транспортные средства. Для особых же элементов карты, соответствующих специфике игрового режима, вам нужно придумать собственный синтаксис.&lt;br /&gt;
&lt;br /&gt;
====Пример====&lt;br /&gt;
Давайте для примера возьмем режим Capture the Flag. Карта для этого режима нуждается главным образом в определенных точках появления игроков, расположенных флагах и в конце концов объектах и транспортных средствах. Упрощенный файл карты может выглядеть следующим образом:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;map&amp;gt;&lt;br /&gt;
    &amp;lt;spawnpoint id=&amp;quot;spawnpoint1&amp;quot; posX=&amp;quot;1959.5487060547&amp;quot; posY=&amp;quot;-1714.4613037109&amp;quot; posZ=&amp;quot;877.25219726563&amp;quot; rot=&amp;quot;63.350006103516&amp;quot; model=&amp;quot;0&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;pickup id=&amp;quot;Armor 1&amp;quot; posX=&amp;quot;1911.083984375&amp;quot; posY=&amp;quot;-1658.8798828125&amp;quot; posZ=&amp;quot;885.40216064453&amp;quot; type=&amp;quot;armor&amp;quot; health=&amp;quot;50&amp;quot; respawn=&amp;quot;60000&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;flag posX=&amp;quot;1959.5487060547&amp;quot; posY=&amp;quot;-1714.4613037109&amp;quot; posZ=&amp;quot;877.25219726563&amp;quot; team=&amp;quot;blue&amp;quot; /&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
&amp;lt;/map&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Здесь вы можете увидеть два MTA элемента - точку появления игрока и пикап. Что еще более важно, карта имеет пользовательский узел &amp;quot;flag&amp;quot;, который определяет положение и цвет флага. Точка появления игрока и пикап могут быть обработаны путем существующих внешних ресурсов, пользовательские элементы должны быть обработаны игровым режимом.&lt;br /&gt;
&lt;br /&gt;
To summarize - we want mass mapper input as we saw in MTA:Race. Users should NOT have to touch the gamemode script itself at all.&lt;br /&gt;
&lt;br /&gt;
====Example of getting the .map information====&lt;br /&gt;
As mentioned above, your gamemode needs de retrieve custom elements that are defined in a map file and process them. This is quite easy as demonstrated below.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- retrieve a table with all flag elements&lt;br /&gt;
local flagElements = getElementsByType ( &amp;quot;flag&amp;quot; )&lt;br /&gt;
-- loop through them&lt;br /&gt;
for key, value in pairs(flagElements) do&lt;br /&gt;
	-- get our info&lt;br /&gt;
	local posX = getElementData ( value, &amp;quot;posX&amp;quot; )&lt;br /&gt;
	local posY = getElementData ( value, &amp;quot;posY&amp;quot; )&lt;br /&gt;
	local posZ = getElementData ( value, &amp;quot;posZ&amp;quot; )&lt;br /&gt;
	local team = getElementData ( value, &amp;quot;team&amp;quot; )&lt;br /&gt;
	-- create an object according to the flag position&lt;br /&gt;
	createObject ( 1337, posX, posY, posZ )&lt;br /&gt;
	-- output the team that we created a base for&lt;br /&gt;
	outputChatBox ( &amp;quot;Base for team &amp;quot; .. team .. &amp;quot; created&amp;quot; )&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The [[getElementsByType]] function retrieves a table of all the elements of a certain type (the type corresponds to the node name in the .map file). This works for both custom types and built-in MTA types (like &amp;quot;vehicle&amp;quot; or &amp;quot;player&amp;quot;).&lt;br /&gt;
[[getElementData]] can be used to retrieve the xml attributes set in the .map file.&lt;br /&gt;
In this simple example, an object is created at the flag's location and a message is outputted in the chatbox. In reality, you will of course need to do more during map loading, like in this case setting up collision shapes to detect players taking the flag.&lt;br /&gt;
&lt;br /&gt;
==Map manager==&lt;br /&gt;
Having read the section above it should be clear that a gamemode should always consist of two parts:&lt;br /&gt;
* The gamemode resource that always stays the same&lt;br /&gt;
* Many different maps resources that give the gamemode map-specific information&lt;br /&gt;
&lt;br /&gt;
Now instead of writing a map-loader for every single gamemode, the [[Map manager]] provides functions to load gamemodes and maps. Simply put, when you enter the correct command (for example 'gamemode ctf ctf-italy') it will start both resources 'ctf' and 'ctf-italy' while triggering an event ([[onGamemodeMapStart]]) to tell the 'ctf' resource that a map was loaded. The 'ctf' resource can then access the information 'ctf-italy' contains and start spawning players etc.&lt;br /&gt;
&lt;br /&gt;
===How to use the mapmanager===&lt;br /&gt;
To use the mapmanager service, your gamemode resource has to be tagged as such first. More specifically you'll be setting the &amp;quot;type&amp;quot; attribute of its &amp;lt;info&amp;gt; tag to &amp;quot;gamemode&amp;quot; inside meta.xml. Also, you can set the &amp;quot;name&amp;quot; attribute to a friendly name (like &amp;quot;Capture the flag&amp;quot;) that will be shown on ASE instead of the resource name.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- meta.xml in &amp;quot;cowcatapult&amp;quot; gamemode --&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info type=&amp;quot;gamemode&amp;quot; name=&amp;quot;Cow catapulting 2.0&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your gamemode is going to load custom maps, you should add handlers for&lt;br /&gt;
* onGamemodeMapStart&lt;br /&gt;
* onGamemodeMapStop (if any unloading is necessary)&lt;br /&gt;
These are fired when a map for your gamemode is started or stopped, and pass the map resource as a parameter.&lt;br /&gt;
Within the handler function for these events you can extract all info you need from the resource's map files and configuration files.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function startCtfMap( startedMap ) -- startedMap contains a reference to the resource of the map&lt;br /&gt;
    local mapRoot = getResourceRootElement( startedMap )        -- get the root node of the started map&lt;br /&gt;
    local flagElements = getElementsByType ( &amp;quot;flag&amp;quot; , mapRoot ) -- get all flags in the map and store them in a table&lt;br /&gt;
    -- go on loading information like in the example above&lt;br /&gt;
&lt;br /&gt;
    -- spawn players etc.&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
addEventHandler(&amp;quot;onGamemodeMapStart&amp;quot;, getRootElement(), startCtfMap)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Making maps compatible===&lt;br /&gt;
Maps are separate resources. This is done so no editing of the gamemode resource is ever necessary in order to create a custom map, and also allows you to pack map-specific scripts/config files with them.&lt;br /&gt;
&lt;br /&gt;
To make a map compatible with your gamemode, open its resource's meta.xml and tag it as well: the &amp;quot;type&amp;quot; attribute must be set to &amp;quot;map&amp;quot;, and the &amp;quot;gamemodes&amp;quot; attribute must be a comma-separated list (no spaces) of gamemode resource names that the map works with.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--map's meta.xml--&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info type=&amp;quot;map&amp;quot; gamemodes=&amp;quot;cowcatapult,assault,tdm&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have everything set up, admins will use these two commands to start/stop gamemodes:&lt;br /&gt;
/gamemode gamemodeName [mapName] (optional parameter allows picking an initial map, defaults to none)&lt;br /&gt;
/changemap mapName [gamemodeName] (optional parameter specifies the gamemode to start the map with, defaults to the current one)&lt;br /&gt;
&lt;br /&gt;
[[Map manager]] exports a few more access functions which you don't have to use, but may be useful.&lt;br /&gt;
&lt;br /&gt;
==What else should you do==&lt;br /&gt;
There are several other resources that gamemodes should use/be compliant with.&lt;br /&gt;
&lt;br /&gt;
===Helpmanager===&lt;br /&gt;
The helpmanager is ought to be the standard interface for players when they need help. If you use the helpmanager to display your gamemode's help, every player that used helpmanager before (e.g. in other gamemodes) will immediately know how to get there. It also displays help for different resources running resources in one window, if necessary.&lt;br /&gt;
&lt;br /&gt;
There are basicially two ways to use the helpmanager:&lt;br /&gt;
* Provide a simple text that explains how to use your gamemode&lt;br /&gt;
* Request a GUI element from the helpmanager that will be displayed in its own tab in the helpmanager window and lets you add any GUI elements to it. This is the recommended way for gamemodes that need to display more complex information that needs its own GUI.&lt;br /&gt;
&lt;br /&gt;
Read the helpmanager page for details on how to do it.&lt;br /&gt;
&lt;br /&gt;
===Scoreboard===&lt;br /&gt;
Scoreboard displays players and teams currently ingame. You add custom columns to it to provide map specific information. For example the column 'points' in the 'ctf' gamemode could represent the player's points gained through kills or captures. As usual, see the scoreboard help page for more information.&lt;br /&gt;
&lt;br /&gt;
===Map cycler===&lt;br /&gt;
The map cycler controls what gamemodes and maps are played on a server. You can specifiy for example how many times in a row a map will be played until it switches to the next. To achieve this, you need to tell the map cycler when your gamemode finished (e.g. when a round ends).&lt;br /&gt;
&lt;br /&gt;
[[en:Writing Gamemodes]]&lt;br /&gt;
[[it:Scrivere una gamemode]]&lt;/div&gt;</summary>
		<author><name>103495106181459904329</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=RU/Writing_Gamemodes&amp;diff=25911</id>
		<title>RU/Writing Gamemodes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=RU/Writing_Gamemodes&amp;diff=25911"/>
		<updated>2011-05-30T05:09:04Z</updated>

		<summary type="html">&lt;p&gt;103495106181459904329: /* Файлы карт */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{translate}}&lt;br /&gt;
Это руководство поможет вам, как написать правильный режим игры. Если вы только что начали писать скрипты для MTA, вы должны сначала просмотреть другие учебники на [[RU/Main Page|Главная страница]].&lt;br /&gt;
==Введение==&lt;br /&gt;
Gamemode (ГМ, мод, гейммод, игровой режим) - ресурс, который, будучи запущенным, контролирует весь игровой процесс. Гейммод включает в себя отправку сообщений игрокам - указания к действиям, респаун игроков, создание команд, указаний, что игрокам нужно делать для победы, или для получения очков, и т.д. Примеры - гонки и DeatMatch'и.&lt;br /&gt;
&lt;br /&gt;
==Что означает &amp;quot;правильный игровой режим&amp;quot;?==&lt;br /&gt;
Проще говоря, правильным игровым режимом можно назвать такой режим, который в полной мере использует MTA систему .map файлов. Это означает, что код игрового режима не имеет любых специфических карт, данные которых жестко привязаны к нему, такие как положение игроков или автомобилей. Вместо этого, игровой режим должен быть в состоянии загружать .map файлы, которые и будут определять эти данные. Таким образом, игровой режим может иметь несколько карт, а также люди смогут создавать .map файлы для игрового режима используя MTA редактор карт, который является гораздо более удобным, чем написание кода.&lt;br /&gt;
&lt;br /&gt;
Очевидным примеров &amp;quot;правильного игрового режима&amp;quot; является MTA: Race. Он допускает пользовательские карты с большим количеством возможностей внутри .map файла. Чтобы изменить точки появления игроков, объекты и т.д., пользователю не нужно изменять сам игровой режим.&lt;br /&gt;
&lt;br /&gt;
===Файлы карт===&lt;br /&gt;
Файлы карт основываются на XML документах с форматом .map. Они определяют контекст игры для одного или нескольких конкретных игровых режимов. Однако, они не должны менять правила игры, которые определены игровым режимом.&lt;br /&gt;
&lt;br /&gt;
Каждый элемент на карте соответствует узлу .map файла. Существует стандартный синтаксис для общих элементов, таких как точки появления игроков, объекты и транспортные средства. Для особых же элементов карты, соответствующих специфике игрового режима, вам нужно придумать собственный синтаксис.&lt;br /&gt;
&lt;br /&gt;
====Пример====&lt;br /&gt;
Давайте для примера возьмем режим Capture the Flag. Карта для этого режима нуждается главным образом в определенных точках появления игроков, расположенных флагах и в конце концов объектах и транспортных средствах. Упрощенный файл карты может выглядеть следующим образом:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;map&amp;gt;&lt;br /&gt;
    &amp;lt;spawnpoint id=&amp;quot;spawnpoint1&amp;quot; posX=&amp;quot;1959.5487060547&amp;quot; posY=&amp;quot;-1714.4613037109&amp;quot; posZ=&amp;quot;877.25219726563&amp;quot; rot=&amp;quot;63.350006103516&amp;quot; model=&amp;quot;0&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;pickup id=&amp;quot;Armor 1&amp;quot; posX=&amp;quot;1911.083984375&amp;quot; posY=&amp;quot;-1658.8798828125&amp;quot; posZ=&amp;quot;885.40216064453&amp;quot; type=&amp;quot;armor&amp;quot; health=&amp;quot;50&amp;quot; respawn=&amp;quot;60000&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;flag posX=&amp;quot;1959.5487060547&amp;quot; posY=&amp;quot;-1714.4613037109&amp;quot; posZ=&amp;quot;877.25219726563&amp;quot; team=&amp;quot;blue&amp;quot; /&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
&amp;lt;/map&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here you can see two MTA elements - a spawnpoint and a pickup. More importantly, this .map has a custom &amp;quot;flag&amp;quot; node which defines the position and color of the flag. The spawnpoint and pickup can be handled by existing external resources, custom elements have to be processed by the gamemode.&lt;br /&gt;
&lt;br /&gt;
To summarize - we want mass mapper input as we saw in MTA:Race. Users should NOT have to touch the gamemode script itself at all.&lt;br /&gt;
&lt;br /&gt;
====Example of getting the .map information====&lt;br /&gt;
As mentioned above, your gamemode needs de retrieve custom elements that are defined in a map file and process them. This is quite easy as demonstrated below.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- retrieve a table with all flag elements&lt;br /&gt;
local flagElements = getElementsByType ( &amp;quot;flag&amp;quot; )&lt;br /&gt;
-- loop through them&lt;br /&gt;
for key, value in pairs(flagElements) do&lt;br /&gt;
	-- get our info&lt;br /&gt;
	local posX = getElementData ( value, &amp;quot;posX&amp;quot; )&lt;br /&gt;
	local posY = getElementData ( value, &amp;quot;posY&amp;quot; )&lt;br /&gt;
	local posZ = getElementData ( value, &amp;quot;posZ&amp;quot; )&lt;br /&gt;
	local team = getElementData ( value, &amp;quot;team&amp;quot; )&lt;br /&gt;
	-- create an object according to the flag position&lt;br /&gt;
	createObject ( 1337, posX, posY, posZ )&lt;br /&gt;
	-- output the team that we created a base for&lt;br /&gt;
	outputChatBox ( &amp;quot;Base for team &amp;quot; .. team .. &amp;quot; created&amp;quot; )&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The [[getElementsByType]] function retrieves a table of all the elements of a certain type (the type corresponds to the node name in the .map file). This works for both custom types and built-in MTA types (like &amp;quot;vehicle&amp;quot; or &amp;quot;player&amp;quot;).&lt;br /&gt;
[[getElementData]] can be used to retrieve the xml attributes set in the .map file.&lt;br /&gt;
In this simple example, an object is created at the flag's location and a message is outputted in the chatbox. In reality, you will of course need to do more during map loading, like in this case setting up collision shapes to detect players taking the flag.&lt;br /&gt;
&lt;br /&gt;
==Map manager==&lt;br /&gt;
Having read the section above it should be clear that a gamemode should always consist of two parts:&lt;br /&gt;
* The gamemode resource that always stays the same&lt;br /&gt;
* Many different maps resources that give the gamemode map-specific information&lt;br /&gt;
&lt;br /&gt;
Now instead of writing a map-loader for every single gamemode, the [[Map manager]] provides functions to load gamemodes and maps. Simply put, when you enter the correct command (for example 'gamemode ctf ctf-italy') it will start both resources 'ctf' and 'ctf-italy' while triggering an event ([[onGamemodeMapStart]]) to tell the 'ctf' resource that a map was loaded. The 'ctf' resource can then access the information 'ctf-italy' contains and start spawning players etc.&lt;br /&gt;
&lt;br /&gt;
===How to use the mapmanager===&lt;br /&gt;
To use the mapmanager service, your gamemode resource has to be tagged as such first. More specifically you'll be setting the &amp;quot;type&amp;quot; attribute of its &amp;lt;info&amp;gt; tag to &amp;quot;gamemode&amp;quot; inside meta.xml. Also, you can set the &amp;quot;name&amp;quot; attribute to a friendly name (like &amp;quot;Capture the flag&amp;quot;) that will be shown on ASE instead of the resource name.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- meta.xml in &amp;quot;cowcatapult&amp;quot; gamemode --&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info type=&amp;quot;gamemode&amp;quot; name=&amp;quot;Cow catapulting 2.0&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your gamemode is going to load custom maps, you should add handlers for&lt;br /&gt;
* onGamemodeMapStart&lt;br /&gt;
* onGamemodeMapStop (if any unloading is necessary)&lt;br /&gt;
These are fired when a map for your gamemode is started or stopped, and pass the map resource as a parameter.&lt;br /&gt;
Within the handler function for these events you can extract all info you need from the resource's map files and configuration files.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function startCtfMap( startedMap ) -- startedMap contains a reference to the resource of the map&lt;br /&gt;
    local mapRoot = getResourceRootElement( startedMap )        -- get the root node of the started map&lt;br /&gt;
    local flagElements = getElementsByType ( &amp;quot;flag&amp;quot; , mapRoot ) -- get all flags in the map and store them in a table&lt;br /&gt;
    -- go on loading information like in the example above&lt;br /&gt;
&lt;br /&gt;
    -- spawn players etc.&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
addEventHandler(&amp;quot;onGamemodeMapStart&amp;quot;, getRootElement(), startCtfMap)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Making maps compatible===&lt;br /&gt;
Maps are separate resources. This is done so no editing of the gamemode resource is ever necessary in order to create a custom map, and also allows you to pack map-specific scripts/config files with them.&lt;br /&gt;
&lt;br /&gt;
To make a map compatible with your gamemode, open its resource's meta.xml and tag it as well: the &amp;quot;type&amp;quot; attribute must be set to &amp;quot;map&amp;quot;, and the &amp;quot;gamemodes&amp;quot; attribute must be a comma-separated list (no spaces) of gamemode resource names that the map works with.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--map's meta.xml--&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info type=&amp;quot;map&amp;quot; gamemodes=&amp;quot;cowcatapult,assault,tdm&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have everything set up, admins will use these two commands to start/stop gamemodes:&lt;br /&gt;
/gamemode gamemodeName [mapName] (optional parameter allows picking an initial map, defaults to none)&lt;br /&gt;
/changemap mapName [gamemodeName] (optional parameter specifies the gamemode to start the map with, defaults to the current one)&lt;br /&gt;
&lt;br /&gt;
[[Map manager]] exports a few more access functions which you don't have to use, but may be useful.&lt;br /&gt;
&lt;br /&gt;
==What else should you do==&lt;br /&gt;
There are several other resources that gamemodes should use/be compliant with.&lt;br /&gt;
&lt;br /&gt;
===Helpmanager===&lt;br /&gt;
The helpmanager is ought to be the standard interface for players when they need help. If you use the helpmanager to display your gamemode's help, every player that used helpmanager before (e.g. in other gamemodes) will immediately know how to get there. It also displays help for different resources running resources in one window, if necessary.&lt;br /&gt;
&lt;br /&gt;
There are basicially two ways to use the helpmanager:&lt;br /&gt;
* Provide a simple text that explains how to use your gamemode&lt;br /&gt;
* Request a GUI element from the helpmanager that will be displayed in its own tab in the helpmanager window and lets you add any GUI elements to it. This is the recommended way for gamemodes that need to display more complex information that needs its own GUI.&lt;br /&gt;
&lt;br /&gt;
Read the helpmanager page for details on how to do it.&lt;br /&gt;
&lt;br /&gt;
===Scoreboard===&lt;br /&gt;
Scoreboard displays players and teams currently ingame. You add custom columns to it to provide map specific information. For example the column 'points' in the 'ctf' gamemode could represent the player's points gained through kills or captures. As usual, see the scoreboard help page for more information.&lt;br /&gt;
&lt;br /&gt;
===Map cycler===&lt;br /&gt;
The map cycler controls what gamemodes and maps are played on a server. You can specifiy for example how many times in a row a map will be played until it switches to the next. To achieve this, you need to tell the map cycler when your gamemode finished (e.g. when a round ends).&lt;br /&gt;
&lt;br /&gt;
[[en:Writing Gamemodes]]&lt;br /&gt;
[[it:Scrivere una gamemode]]&lt;/div&gt;</summary>
		<author><name>103495106181459904329</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=RU/Writing_Gamemodes&amp;diff=25910</id>
		<title>RU/Writing Gamemodes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=RU/Writing_Gamemodes&amp;diff=25910"/>
		<updated>2011-05-30T04:57:15Z</updated>

		<summary type="html">&lt;p&gt;103495106181459904329: /* Map Files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{translate}}&lt;br /&gt;
Это руководство поможет вам, как написать правильный режим игры. Если вы только что начали писать скрипты для MTA, вы должны сначала просмотреть другие учебники на [[RU/Main Page|Главная страница]].&lt;br /&gt;
==Введение==&lt;br /&gt;
Gamemode (ГМ, мод, гейммод, игровой режим) - ресурс, который, будучи запущенным, контролирует весь игровой процесс. Гейммод включает в себя отправку сообщений игрокам - указания к действиям, респаун игроков, создание команд, указаний, что игрокам нужно делать для победы, или для получения очков, и т.д. Примеры - гонки и DeatMatch'и.&lt;br /&gt;
&lt;br /&gt;
==Что означает &amp;quot;правильный игровой режим&amp;quot;?==&lt;br /&gt;
Проще говоря, правильным игровым режимом можно назвать такой режим, который в полной мере использует MTA систему .map файлов. Это означает, что код игрового режима не имеет любых специфических карт, данные которых жестко привязаны к нему, такие как положение игроков или автомобилей. Вместо этого, игровой режим должен быть в состоянии загружать .map файлы, которые и будут определять эти данные. Таким образом, игровой режим может иметь несколько карт, а также люди смогут создавать .map файлы для игрового режима используя MTA редактор карт, который является гораздо более удобным, чем написание кода.&lt;br /&gt;
&lt;br /&gt;
Очевидным примеров &amp;quot;правильного игрового режима&amp;quot; является MTA: Race. Он допускает пользовательские карты с большим количеством возможностей внутри .map файла. Чтобы изменить точки появления игроков, объекты и т.д., пользователю не нужно изменять сам игровой режим.&lt;br /&gt;
&lt;br /&gt;
===Файлы карт===&lt;br /&gt;
Файлы карт основываются на XML документах с форматом .map. Они определяют контекст игры для одного или нескольких конкретных игровых режимов. Однако, они не должны менять правила игры, которые определены игровым режимом.&lt;br /&gt;
&lt;br /&gt;
Каждый элемент на карте соответствует узлу .map файла. There is standard syntax for common things like spawnpoints, objects and vehicles; however, for &amp;quot;special&amp;quot;, gamemode specific information, you need to invent your own syntax.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
Let's take a Capture the Flag gamemode as an example. A map for this gamemode needs to mainly define spawnpoints and flag locations, and eventually objects and vehicles. A simplified map file could look like this:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;map&amp;gt;&lt;br /&gt;
    &amp;lt;spawnpoint id=&amp;quot;spawnpoint1&amp;quot; posX=&amp;quot;1959.5487060547&amp;quot; posY=&amp;quot;-1714.4613037109&amp;quot; posZ=&amp;quot;877.25219726563&amp;quot; rot=&amp;quot;63.350006103516&amp;quot; model=&amp;quot;0&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;pickup id=&amp;quot;Armor 1&amp;quot; posX=&amp;quot;1911.083984375&amp;quot; posY=&amp;quot;-1658.8798828125&amp;quot; posZ=&amp;quot;885.40216064453&amp;quot; type=&amp;quot;armor&amp;quot; health=&amp;quot;50&amp;quot; respawn=&amp;quot;60000&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;flag posX=&amp;quot;1959.5487060547&amp;quot; posY=&amp;quot;-1714.4613037109&amp;quot; posZ=&amp;quot;877.25219726563&amp;quot; team=&amp;quot;blue&amp;quot; /&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
&amp;lt;/map&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here you can see two MTA elements - a spawnpoint and a pickup. More importantly, this .map has a custom &amp;quot;flag&amp;quot; node which defines the position and color of the flag. The spawnpoint and pickup can be handled by existing external resources, custom elements have to be processed by the gamemode.&lt;br /&gt;
&lt;br /&gt;
To summarize - we want mass mapper input as we saw in MTA:Race. Users should NOT have to touch the gamemode script itself at all.&lt;br /&gt;
&lt;br /&gt;
====Example of getting the .map information====&lt;br /&gt;
As mentioned above, your gamemode needs de retrieve custom elements that are defined in a map file and process them. This is quite easy as demonstrated below.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- retrieve a table with all flag elements&lt;br /&gt;
local flagElements = getElementsByType ( &amp;quot;flag&amp;quot; )&lt;br /&gt;
-- loop through them&lt;br /&gt;
for key, value in pairs(flagElements) do&lt;br /&gt;
	-- get our info&lt;br /&gt;
	local posX = getElementData ( value, &amp;quot;posX&amp;quot; )&lt;br /&gt;
	local posY = getElementData ( value, &amp;quot;posY&amp;quot; )&lt;br /&gt;
	local posZ = getElementData ( value, &amp;quot;posZ&amp;quot; )&lt;br /&gt;
	local team = getElementData ( value, &amp;quot;team&amp;quot; )&lt;br /&gt;
	-- create an object according to the flag position&lt;br /&gt;
	createObject ( 1337, posX, posY, posZ )&lt;br /&gt;
	-- output the team that we created a base for&lt;br /&gt;
	outputChatBox ( &amp;quot;Base for team &amp;quot; .. team .. &amp;quot; created&amp;quot; )&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The [[getElementsByType]] function retrieves a table of all the elements of a certain type (the type corresponds to the node name in the .map file). This works for both custom types and built-in MTA types (like &amp;quot;vehicle&amp;quot; or &amp;quot;player&amp;quot;).&lt;br /&gt;
[[getElementData]] can be used to retrieve the xml attributes set in the .map file.&lt;br /&gt;
In this simple example, an object is created at the flag's location and a message is outputted in the chatbox. In reality, you will of course need to do more during map loading, like in this case setting up collision shapes to detect players taking the flag.&lt;br /&gt;
&lt;br /&gt;
==Map manager==&lt;br /&gt;
Having read the section above it should be clear that a gamemode should always consist of two parts:&lt;br /&gt;
* The gamemode resource that always stays the same&lt;br /&gt;
* Many different maps resources that give the gamemode map-specific information&lt;br /&gt;
&lt;br /&gt;
Now instead of writing a map-loader for every single gamemode, the [[Map manager]] provides functions to load gamemodes and maps. Simply put, when you enter the correct command (for example 'gamemode ctf ctf-italy') it will start both resources 'ctf' and 'ctf-italy' while triggering an event ([[onGamemodeMapStart]]) to tell the 'ctf' resource that a map was loaded. The 'ctf' resource can then access the information 'ctf-italy' contains and start spawning players etc.&lt;br /&gt;
&lt;br /&gt;
===How to use the mapmanager===&lt;br /&gt;
To use the mapmanager service, your gamemode resource has to be tagged as such first. More specifically you'll be setting the &amp;quot;type&amp;quot; attribute of its &amp;lt;info&amp;gt; tag to &amp;quot;gamemode&amp;quot; inside meta.xml. Also, you can set the &amp;quot;name&amp;quot; attribute to a friendly name (like &amp;quot;Capture the flag&amp;quot;) that will be shown on ASE instead of the resource name.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- meta.xml in &amp;quot;cowcatapult&amp;quot; gamemode --&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info type=&amp;quot;gamemode&amp;quot; name=&amp;quot;Cow catapulting 2.0&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your gamemode is going to load custom maps, you should add handlers for&lt;br /&gt;
* onGamemodeMapStart&lt;br /&gt;
* onGamemodeMapStop (if any unloading is necessary)&lt;br /&gt;
These are fired when a map for your gamemode is started or stopped, and pass the map resource as a parameter.&lt;br /&gt;
Within the handler function for these events you can extract all info you need from the resource's map files and configuration files.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function startCtfMap( startedMap ) -- startedMap contains a reference to the resource of the map&lt;br /&gt;
    local mapRoot = getResourceRootElement( startedMap )        -- get the root node of the started map&lt;br /&gt;
    local flagElements = getElementsByType ( &amp;quot;flag&amp;quot; , mapRoot ) -- get all flags in the map and store them in a table&lt;br /&gt;
    -- go on loading information like in the example above&lt;br /&gt;
&lt;br /&gt;
    -- spawn players etc.&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
addEventHandler(&amp;quot;onGamemodeMapStart&amp;quot;, getRootElement(), startCtfMap)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Making maps compatible===&lt;br /&gt;
Maps are separate resources. This is done so no editing of the gamemode resource is ever necessary in order to create a custom map, and also allows you to pack map-specific scripts/config files with them.&lt;br /&gt;
&lt;br /&gt;
To make a map compatible with your gamemode, open its resource's meta.xml and tag it as well: the &amp;quot;type&amp;quot; attribute must be set to &amp;quot;map&amp;quot;, and the &amp;quot;gamemodes&amp;quot; attribute must be a comma-separated list (no spaces) of gamemode resource names that the map works with.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--map's meta.xml--&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info type=&amp;quot;map&amp;quot; gamemodes=&amp;quot;cowcatapult,assault,tdm&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have everything set up, admins will use these two commands to start/stop gamemodes:&lt;br /&gt;
/gamemode gamemodeName [mapName] (optional parameter allows picking an initial map, defaults to none)&lt;br /&gt;
/changemap mapName [gamemodeName] (optional parameter specifies the gamemode to start the map with, defaults to the current one)&lt;br /&gt;
&lt;br /&gt;
[[Map manager]] exports a few more access functions which you don't have to use, but may be useful.&lt;br /&gt;
&lt;br /&gt;
==What else should you do==&lt;br /&gt;
There are several other resources that gamemodes should use/be compliant with.&lt;br /&gt;
&lt;br /&gt;
===Helpmanager===&lt;br /&gt;
The helpmanager is ought to be the standard interface for players when they need help. If you use the helpmanager to display your gamemode's help, every player that used helpmanager before (e.g. in other gamemodes) will immediately know how to get there. It also displays help for different resources running resources in one window, if necessary.&lt;br /&gt;
&lt;br /&gt;
There are basicially two ways to use the helpmanager:&lt;br /&gt;
* Provide a simple text that explains how to use your gamemode&lt;br /&gt;
* Request a GUI element from the helpmanager that will be displayed in its own tab in the helpmanager window and lets you add any GUI elements to it. This is the recommended way for gamemodes that need to display more complex information that needs its own GUI.&lt;br /&gt;
&lt;br /&gt;
Read the helpmanager page for details on how to do it.&lt;br /&gt;
&lt;br /&gt;
===Scoreboard===&lt;br /&gt;
Scoreboard displays players and teams currently ingame. You add custom columns to it to provide map specific information. For example the column 'points' in the 'ctf' gamemode could represent the player's points gained through kills or captures. As usual, see the scoreboard help page for more information.&lt;br /&gt;
&lt;br /&gt;
===Map cycler===&lt;br /&gt;
The map cycler controls what gamemodes and maps are played on a server. You can specifiy for example how many times in a row a map will be played until it switches to the next. To achieve this, you need to tell the map cycler when your gamemode finished (e.g. when a round ends).&lt;br /&gt;
&lt;br /&gt;
[[en:Writing Gamemodes]]&lt;br /&gt;
[[it:Scrivere una gamemode]]&lt;/div&gt;</summary>
		<author><name>103495106181459904329</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=RU/Writing_Gamemodes&amp;diff=25909</id>
		<title>RU/Writing Gamemodes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=RU/Writing_Gamemodes&amp;diff=25909"/>
		<updated>2011-05-30T04:45:18Z</updated>

		<summary type="html">&lt;p&gt;103495106181459904329: /* Введение */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{translate}}&lt;br /&gt;
Это руководство поможет вам, как написать правильный режим игры. Если вы только что начали писать скрипты для MTA, вы должны сначала просмотреть другие учебники на [[RU/Main Page|Главная страница]].&lt;br /&gt;
==Введение==&lt;br /&gt;
Gamemode (ГМ, мод, гейммод, игровой режим) - ресурс, который, будучи запущенным, контролирует весь игровой процесс. Гейммод включает в себя отправку сообщений игрокам - указания к действиям, респаун игроков, создание команд, указаний, что игрокам нужно делать для победы, или для получения очков, и т.д. Примеры - гонки и DeatMatch'и.&lt;br /&gt;
&lt;br /&gt;
==Что означает &amp;quot;правильный игровой режим&amp;quot;?==&lt;br /&gt;
Проще говоря, правильным игровым режимом можно назвать такой режим, который в полной мере использует MTA систему .map файлов. Это означает, что код игрового режима не имеет любых специфических карт, данные которых жестко привязаны к нему, такие как положение игроков или автомобилей. Вместо этого, игровой режим должен быть в состоянии загружать .map файлы, которые и будут определять эти данные. Таким образом, игровой режим может иметь несколько карт, а также люди смогут создавать .map файлы для игрового режима используя MTA редактор карт, который является гораздо более удобным, чем написание кода.&lt;br /&gt;
&lt;br /&gt;
Очевидным примеров &amp;quot;правильного игрового режима&amp;quot; является MTA: Race. Он допускает пользовательские карты с большим количеством возможностей внутри .map файла. Чтобы изменить точки появления игроков, объекты и т.д., пользователю не нужно изменять сам игровой режим.&lt;br /&gt;
&lt;br /&gt;
===Map Files===&lt;br /&gt;
Map files are basically XML documents with a .map extension. They define an environment to play one or more specific gamemodes in. They are however not supposed to change the rules of the game - those are defined by the gamemode.&lt;br /&gt;
&lt;br /&gt;
Each element in a map corresponds to a node in the .map file. There is standard syntax for common things like spawnpoints, objects and vehicles; however, for &amp;quot;special&amp;quot;, gamemode specific information, you need to invent your own syntax.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
Let's take a Capture the Flag gamemode as an example. A map for this gamemode needs to mainly define spawnpoints and flag locations, and eventually objects and vehicles. A simplified map file could look like this:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;map&amp;gt;&lt;br /&gt;
    &amp;lt;spawnpoint id=&amp;quot;spawnpoint1&amp;quot; posX=&amp;quot;1959.5487060547&amp;quot; posY=&amp;quot;-1714.4613037109&amp;quot; posZ=&amp;quot;877.25219726563&amp;quot; rot=&amp;quot;63.350006103516&amp;quot; model=&amp;quot;0&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;pickup id=&amp;quot;Armor 1&amp;quot; posX=&amp;quot;1911.083984375&amp;quot; posY=&amp;quot;-1658.8798828125&amp;quot; posZ=&amp;quot;885.40216064453&amp;quot; type=&amp;quot;armor&amp;quot; health=&amp;quot;50&amp;quot; respawn=&amp;quot;60000&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;flag posX=&amp;quot;1959.5487060547&amp;quot; posY=&amp;quot;-1714.4613037109&amp;quot; posZ=&amp;quot;877.25219726563&amp;quot; team=&amp;quot;blue&amp;quot; /&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
&amp;lt;/map&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here you can see two MTA elements - a spawnpoint and a pickup. More importantly, this .map has a custom &amp;quot;flag&amp;quot; node which defines the position and color of the flag. The spawnpoint and pickup can be handled by existing external resources, custom elements have to be processed by the gamemode.&lt;br /&gt;
&lt;br /&gt;
To summarize - we want mass mapper input as we saw in MTA:Race. Users should NOT have to touch the gamemode script itself at all.&lt;br /&gt;
&lt;br /&gt;
====Example of getting the .map information====&lt;br /&gt;
As mentioned above, your gamemode needs de retrieve custom elements that are defined in a map file and process them. This is quite easy as demonstrated below.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- retrieve a table with all flag elements&lt;br /&gt;
local flagElements = getElementsByType ( &amp;quot;flag&amp;quot; )&lt;br /&gt;
-- loop through them&lt;br /&gt;
for key, value in pairs(flagElements) do&lt;br /&gt;
	-- get our info&lt;br /&gt;
	local posX = getElementData ( value, &amp;quot;posX&amp;quot; )&lt;br /&gt;
	local posY = getElementData ( value, &amp;quot;posY&amp;quot; )&lt;br /&gt;
	local posZ = getElementData ( value, &amp;quot;posZ&amp;quot; )&lt;br /&gt;
	local team = getElementData ( value, &amp;quot;team&amp;quot; )&lt;br /&gt;
	-- create an object according to the flag position&lt;br /&gt;
	createObject ( 1337, posX, posY, posZ )&lt;br /&gt;
	-- output the team that we created a base for&lt;br /&gt;
	outputChatBox ( &amp;quot;Base for team &amp;quot; .. team .. &amp;quot; created&amp;quot; )&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The [[getElementsByType]] function retrieves a table of all the elements of a certain type (the type corresponds to the node name in the .map file). This works for both custom types and built-in MTA types (like &amp;quot;vehicle&amp;quot; or &amp;quot;player&amp;quot;).&lt;br /&gt;
[[getElementData]] can be used to retrieve the xml attributes set in the .map file.&lt;br /&gt;
In this simple example, an object is created at the flag's location and a message is outputted in the chatbox. In reality, you will of course need to do more during map loading, like in this case setting up collision shapes to detect players taking the flag.&lt;br /&gt;
&lt;br /&gt;
==Map manager==&lt;br /&gt;
Having read the section above it should be clear that a gamemode should always consist of two parts:&lt;br /&gt;
* The gamemode resource that always stays the same&lt;br /&gt;
* Many different maps resources that give the gamemode map-specific information&lt;br /&gt;
&lt;br /&gt;
Now instead of writing a map-loader for every single gamemode, the [[Map manager]] provides functions to load gamemodes and maps. Simply put, when you enter the correct command (for example 'gamemode ctf ctf-italy') it will start both resources 'ctf' and 'ctf-italy' while triggering an event ([[onGamemodeMapStart]]) to tell the 'ctf' resource that a map was loaded. The 'ctf' resource can then access the information 'ctf-italy' contains and start spawning players etc.&lt;br /&gt;
&lt;br /&gt;
===How to use the mapmanager===&lt;br /&gt;
To use the mapmanager service, your gamemode resource has to be tagged as such first. More specifically you'll be setting the &amp;quot;type&amp;quot; attribute of its &amp;lt;info&amp;gt; tag to &amp;quot;gamemode&amp;quot; inside meta.xml. Also, you can set the &amp;quot;name&amp;quot; attribute to a friendly name (like &amp;quot;Capture the flag&amp;quot;) that will be shown on ASE instead of the resource name.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- meta.xml in &amp;quot;cowcatapult&amp;quot; gamemode --&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info type=&amp;quot;gamemode&amp;quot; name=&amp;quot;Cow catapulting 2.0&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your gamemode is going to load custom maps, you should add handlers for&lt;br /&gt;
* onGamemodeMapStart&lt;br /&gt;
* onGamemodeMapStop (if any unloading is necessary)&lt;br /&gt;
These are fired when a map for your gamemode is started or stopped, and pass the map resource as a parameter.&lt;br /&gt;
Within the handler function for these events you can extract all info you need from the resource's map files and configuration files.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function startCtfMap( startedMap ) -- startedMap contains a reference to the resource of the map&lt;br /&gt;
    local mapRoot = getResourceRootElement( startedMap )        -- get the root node of the started map&lt;br /&gt;
    local flagElements = getElementsByType ( &amp;quot;flag&amp;quot; , mapRoot ) -- get all flags in the map and store them in a table&lt;br /&gt;
    -- go on loading information like in the example above&lt;br /&gt;
&lt;br /&gt;
    -- spawn players etc.&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
addEventHandler(&amp;quot;onGamemodeMapStart&amp;quot;, getRootElement(), startCtfMap)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Making maps compatible===&lt;br /&gt;
Maps are separate resources. This is done so no editing of the gamemode resource is ever necessary in order to create a custom map, and also allows you to pack map-specific scripts/config files with them.&lt;br /&gt;
&lt;br /&gt;
To make a map compatible with your gamemode, open its resource's meta.xml and tag it as well: the &amp;quot;type&amp;quot; attribute must be set to &amp;quot;map&amp;quot;, and the &amp;quot;gamemodes&amp;quot; attribute must be a comma-separated list (no spaces) of gamemode resource names that the map works with.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--map's meta.xml--&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info type=&amp;quot;map&amp;quot; gamemodes=&amp;quot;cowcatapult,assault,tdm&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have everything set up, admins will use these two commands to start/stop gamemodes:&lt;br /&gt;
/gamemode gamemodeName [mapName] (optional parameter allows picking an initial map, defaults to none)&lt;br /&gt;
/changemap mapName [gamemodeName] (optional parameter specifies the gamemode to start the map with, defaults to the current one)&lt;br /&gt;
&lt;br /&gt;
[[Map manager]] exports a few more access functions which you don't have to use, but may be useful.&lt;br /&gt;
&lt;br /&gt;
==What else should you do==&lt;br /&gt;
There are several other resources that gamemodes should use/be compliant with.&lt;br /&gt;
&lt;br /&gt;
===Helpmanager===&lt;br /&gt;
The helpmanager is ought to be the standard interface for players when they need help. If you use the helpmanager to display your gamemode's help, every player that used helpmanager before (e.g. in other gamemodes) will immediately know how to get there. It also displays help for different resources running resources in one window, if necessary.&lt;br /&gt;
&lt;br /&gt;
There are basicially two ways to use the helpmanager:&lt;br /&gt;
* Provide a simple text that explains how to use your gamemode&lt;br /&gt;
* Request a GUI element from the helpmanager that will be displayed in its own tab in the helpmanager window and lets you add any GUI elements to it. This is the recommended way for gamemodes that need to display more complex information that needs its own GUI.&lt;br /&gt;
&lt;br /&gt;
Read the helpmanager page for details on how to do it.&lt;br /&gt;
&lt;br /&gt;
===Scoreboard===&lt;br /&gt;
Scoreboard displays players and teams currently ingame. You add custom columns to it to provide map specific information. For example the column 'points' in the 'ctf' gamemode could represent the player's points gained through kills or captures. As usual, see the scoreboard help page for more information.&lt;br /&gt;
&lt;br /&gt;
===Map cycler===&lt;br /&gt;
The map cycler controls what gamemodes and maps are played on a server. You can specifiy for example how many times in a row a map will be played until it switches to the next. To achieve this, you need to tell the map cycler when your gamemode finished (e.g. when a round ends).&lt;br /&gt;
&lt;br /&gt;
[[en:Writing Gamemodes]]&lt;br /&gt;
[[it:Scrivere una gamemode]]&lt;/div&gt;</summary>
		<author><name>103495106181459904329</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=RU/Writing_Gamemodes&amp;diff=25908</id>
		<title>RU/Writing Gamemodes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=RU/Writing_Gamemodes&amp;diff=25908"/>
		<updated>2011-05-30T04:44:40Z</updated>

		<summary type="html">&lt;p&gt;103495106181459904329: /* Введение */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{translate}}&lt;br /&gt;
Это руководство поможет вам, как написать правильный режим игры. Если вы только что начали писать скрипты для MTA, вы должны сначала просмотреть другие учебники на [[RU/Main Page|Главная страница]].&lt;br /&gt;
==Введение==&lt;br /&gt;
Gamemode (ГМ, мод, гейммод, игровой режим) - ресурс, который, будучи запущенным, контролирует весь игровой процесс. Гейммод включает в себя отправку сообщений игрокам - указаний к действиям, респаун игроков, создание команд, указаний, что игрокам нужно делать для победы, или для получения очков, и т.д. Примеры - гонки и DeatMatch'и.&lt;br /&gt;
&lt;br /&gt;
==Что означает &amp;quot;правильный игровой режим&amp;quot;?==&lt;br /&gt;
Проще говоря, правильным игровым режимом можно назвать такой режим, который в полной мере использует MTA систему .map файлов. Это означает, что код игрового режима не имеет любых специфических карт, данные которых жестко привязаны к нему, такие как положение игроков или автомобилей. Вместо этого, игровой режим должен быть в состоянии загружать .map файлы, которые и будут определять эти данные. Таким образом, игровой режим может иметь несколько карт, а также люди смогут создавать .map файлы для игрового режима используя MTA редактор карт, который является гораздо более удобным, чем написание кода.&lt;br /&gt;
&lt;br /&gt;
Очевидным примеров &amp;quot;правильного игрового режима&amp;quot; является MTA: Race. Он допускает пользовательские карты с большим количеством возможностей внутри .map файла. Чтобы изменить точки появления игроков, объекты и т.д., пользователю не нужно изменять сам игровой режим.&lt;br /&gt;
&lt;br /&gt;
===Map Files===&lt;br /&gt;
Map files are basically XML documents with a .map extension. They define an environment to play one or more specific gamemodes in. They are however not supposed to change the rules of the game - those are defined by the gamemode.&lt;br /&gt;
&lt;br /&gt;
Each element in a map corresponds to a node in the .map file. There is standard syntax for common things like spawnpoints, objects and vehicles; however, for &amp;quot;special&amp;quot;, gamemode specific information, you need to invent your own syntax.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
Let's take a Capture the Flag gamemode as an example. A map for this gamemode needs to mainly define spawnpoints and flag locations, and eventually objects and vehicles. A simplified map file could look like this:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;map&amp;gt;&lt;br /&gt;
    &amp;lt;spawnpoint id=&amp;quot;spawnpoint1&amp;quot; posX=&amp;quot;1959.5487060547&amp;quot; posY=&amp;quot;-1714.4613037109&amp;quot; posZ=&amp;quot;877.25219726563&amp;quot; rot=&amp;quot;63.350006103516&amp;quot; model=&amp;quot;0&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;pickup id=&amp;quot;Armor 1&amp;quot; posX=&amp;quot;1911.083984375&amp;quot; posY=&amp;quot;-1658.8798828125&amp;quot; posZ=&amp;quot;885.40216064453&amp;quot; type=&amp;quot;armor&amp;quot; health=&amp;quot;50&amp;quot; respawn=&amp;quot;60000&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;flag posX=&amp;quot;1959.5487060547&amp;quot; posY=&amp;quot;-1714.4613037109&amp;quot; posZ=&amp;quot;877.25219726563&amp;quot; team=&amp;quot;blue&amp;quot; /&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
&amp;lt;/map&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here you can see two MTA elements - a spawnpoint and a pickup. More importantly, this .map has a custom &amp;quot;flag&amp;quot; node which defines the position and color of the flag. The spawnpoint and pickup can be handled by existing external resources, custom elements have to be processed by the gamemode.&lt;br /&gt;
&lt;br /&gt;
To summarize - we want mass mapper input as we saw in MTA:Race. Users should NOT have to touch the gamemode script itself at all.&lt;br /&gt;
&lt;br /&gt;
====Example of getting the .map information====&lt;br /&gt;
As mentioned above, your gamemode needs de retrieve custom elements that are defined in a map file and process them. This is quite easy as demonstrated below.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- retrieve a table with all flag elements&lt;br /&gt;
local flagElements = getElementsByType ( &amp;quot;flag&amp;quot; )&lt;br /&gt;
-- loop through them&lt;br /&gt;
for key, value in pairs(flagElements) do&lt;br /&gt;
	-- get our info&lt;br /&gt;
	local posX = getElementData ( value, &amp;quot;posX&amp;quot; )&lt;br /&gt;
	local posY = getElementData ( value, &amp;quot;posY&amp;quot; )&lt;br /&gt;
	local posZ = getElementData ( value, &amp;quot;posZ&amp;quot; )&lt;br /&gt;
	local team = getElementData ( value, &amp;quot;team&amp;quot; )&lt;br /&gt;
	-- create an object according to the flag position&lt;br /&gt;
	createObject ( 1337, posX, posY, posZ )&lt;br /&gt;
	-- output the team that we created a base for&lt;br /&gt;
	outputChatBox ( &amp;quot;Base for team &amp;quot; .. team .. &amp;quot; created&amp;quot; )&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The [[getElementsByType]] function retrieves a table of all the elements of a certain type (the type corresponds to the node name in the .map file). This works for both custom types and built-in MTA types (like &amp;quot;vehicle&amp;quot; or &amp;quot;player&amp;quot;).&lt;br /&gt;
[[getElementData]] can be used to retrieve the xml attributes set in the .map file.&lt;br /&gt;
In this simple example, an object is created at the flag's location and a message is outputted in the chatbox. In reality, you will of course need to do more during map loading, like in this case setting up collision shapes to detect players taking the flag.&lt;br /&gt;
&lt;br /&gt;
==Map manager==&lt;br /&gt;
Having read the section above it should be clear that a gamemode should always consist of two parts:&lt;br /&gt;
* The gamemode resource that always stays the same&lt;br /&gt;
* Many different maps resources that give the gamemode map-specific information&lt;br /&gt;
&lt;br /&gt;
Now instead of writing a map-loader for every single gamemode, the [[Map manager]] provides functions to load gamemodes and maps. Simply put, when you enter the correct command (for example 'gamemode ctf ctf-italy') it will start both resources 'ctf' and 'ctf-italy' while triggering an event ([[onGamemodeMapStart]]) to tell the 'ctf' resource that a map was loaded. The 'ctf' resource can then access the information 'ctf-italy' contains and start spawning players etc.&lt;br /&gt;
&lt;br /&gt;
===How to use the mapmanager===&lt;br /&gt;
To use the mapmanager service, your gamemode resource has to be tagged as such first. More specifically you'll be setting the &amp;quot;type&amp;quot; attribute of its &amp;lt;info&amp;gt; tag to &amp;quot;gamemode&amp;quot; inside meta.xml. Also, you can set the &amp;quot;name&amp;quot; attribute to a friendly name (like &amp;quot;Capture the flag&amp;quot;) that will be shown on ASE instead of the resource name.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- meta.xml in &amp;quot;cowcatapult&amp;quot; gamemode --&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info type=&amp;quot;gamemode&amp;quot; name=&amp;quot;Cow catapulting 2.0&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your gamemode is going to load custom maps, you should add handlers for&lt;br /&gt;
* onGamemodeMapStart&lt;br /&gt;
* onGamemodeMapStop (if any unloading is necessary)&lt;br /&gt;
These are fired when a map for your gamemode is started or stopped, and pass the map resource as a parameter.&lt;br /&gt;
Within the handler function for these events you can extract all info you need from the resource's map files and configuration files.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function startCtfMap( startedMap ) -- startedMap contains a reference to the resource of the map&lt;br /&gt;
    local mapRoot = getResourceRootElement( startedMap )        -- get the root node of the started map&lt;br /&gt;
    local flagElements = getElementsByType ( &amp;quot;flag&amp;quot; , mapRoot ) -- get all flags in the map and store them in a table&lt;br /&gt;
    -- go on loading information like in the example above&lt;br /&gt;
&lt;br /&gt;
    -- spawn players etc.&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
addEventHandler(&amp;quot;onGamemodeMapStart&amp;quot;, getRootElement(), startCtfMap)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Making maps compatible===&lt;br /&gt;
Maps are separate resources. This is done so no editing of the gamemode resource is ever necessary in order to create a custom map, and also allows you to pack map-specific scripts/config files with them.&lt;br /&gt;
&lt;br /&gt;
To make a map compatible with your gamemode, open its resource's meta.xml and tag it as well: the &amp;quot;type&amp;quot; attribute must be set to &amp;quot;map&amp;quot;, and the &amp;quot;gamemodes&amp;quot; attribute must be a comma-separated list (no spaces) of gamemode resource names that the map works with.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--map's meta.xml--&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info type=&amp;quot;map&amp;quot; gamemodes=&amp;quot;cowcatapult,assault,tdm&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have everything set up, admins will use these two commands to start/stop gamemodes:&lt;br /&gt;
/gamemode gamemodeName [mapName] (optional parameter allows picking an initial map, defaults to none)&lt;br /&gt;
/changemap mapName [gamemodeName] (optional parameter specifies the gamemode to start the map with, defaults to the current one)&lt;br /&gt;
&lt;br /&gt;
[[Map manager]] exports a few more access functions which you don't have to use, but may be useful.&lt;br /&gt;
&lt;br /&gt;
==What else should you do==&lt;br /&gt;
There are several other resources that gamemodes should use/be compliant with.&lt;br /&gt;
&lt;br /&gt;
===Helpmanager===&lt;br /&gt;
The helpmanager is ought to be the standard interface for players when they need help. If you use the helpmanager to display your gamemode's help, every player that used helpmanager before (e.g. in other gamemodes) will immediately know how to get there. It also displays help for different resources running resources in one window, if necessary.&lt;br /&gt;
&lt;br /&gt;
There are basicially two ways to use the helpmanager:&lt;br /&gt;
* Provide a simple text that explains how to use your gamemode&lt;br /&gt;
* Request a GUI element from the helpmanager that will be displayed in its own tab in the helpmanager window and lets you add any GUI elements to it. This is the recommended way for gamemodes that need to display more complex information that needs its own GUI.&lt;br /&gt;
&lt;br /&gt;
Read the helpmanager page for details on how to do it.&lt;br /&gt;
&lt;br /&gt;
===Scoreboard===&lt;br /&gt;
Scoreboard displays players and teams currently ingame. You add custom columns to it to provide map specific information. For example the column 'points' in the 'ctf' gamemode could represent the player's points gained through kills or captures. As usual, see the scoreboard help page for more information.&lt;br /&gt;
&lt;br /&gt;
===Map cycler===&lt;br /&gt;
The map cycler controls what gamemodes and maps are played on a server. You can specifiy for example how many times in a row a map will be played until it switches to the next. To achieve this, you need to tell the map cycler when your gamemode finished (e.g. when a round ends).&lt;br /&gt;
&lt;br /&gt;
[[en:Writing Gamemodes]]&lt;br /&gt;
[[it:Scrivere una gamemode]]&lt;/div&gt;</summary>
		<author><name>103495106181459904329</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=RU/Writing_Gamemodes&amp;diff=25907</id>
		<title>RU/Writing Gamemodes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=RU/Writing_Gamemodes&amp;diff=25907"/>
		<updated>2011-05-30T04:44:20Z</updated>

		<summary type="html">&lt;p&gt;103495106181459904329: /* Введение */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{translate}}&lt;br /&gt;
Это руководство поможет вам, как написать правильный режим игры. Если вы только что начали писать скрипты для MTA, вы должны сначала просмотреть другие учебники на [[RU/Main Page|Главная страница]].&lt;br /&gt;
==Введение==&lt;br /&gt;
Gamemode (ГМ, мод, гейммод) - ресурс, который, будучи запущенным, контролирует весь игровой процесс. Гейммод включает в себя отправку сообщений игрокам - указаний к действиям, респаун игроков, создание команд, указаний, что игрокам нужно делать для победы, или для получения очков, и т.д. Примеры - гонки и DeatMatch'и.&lt;br /&gt;
&lt;br /&gt;
==Что означает &amp;quot;правильный игровой режим&amp;quot;?==&lt;br /&gt;
Проще говоря, правильным игровым режимом можно назвать такой режим, который в полной мере использует MTA систему .map файлов. Это означает, что код игрового режима не имеет любых специфических карт, данные которых жестко привязаны к нему, такие как положение игроков или автомобилей. Вместо этого, игровой режим должен быть в состоянии загружать .map файлы, которые и будут определять эти данные. Таким образом, игровой режим может иметь несколько карт, а также люди смогут создавать .map файлы для игрового режима используя MTA редактор карт, который является гораздо более удобным, чем написание кода.&lt;br /&gt;
&lt;br /&gt;
Очевидным примеров &amp;quot;правильного игрового режима&amp;quot; является MTA: Race. Он допускает пользовательские карты с большим количеством возможностей внутри .map файла. Чтобы изменить точки появления игроков, объекты и т.д., пользователю не нужно изменять сам игровой режим.&lt;br /&gt;
&lt;br /&gt;
===Map Files===&lt;br /&gt;
Map files are basically XML documents with a .map extension. They define an environment to play one or more specific gamemodes in. They are however not supposed to change the rules of the game - those are defined by the gamemode.&lt;br /&gt;
&lt;br /&gt;
Each element in a map corresponds to a node in the .map file. There is standard syntax for common things like spawnpoints, objects and vehicles; however, for &amp;quot;special&amp;quot;, gamemode specific information, you need to invent your own syntax.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
Let's take a Capture the Flag gamemode as an example. A map for this gamemode needs to mainly define spawnpoints and flag locations, and eventually objects and vehicles. A simplified map file could look like this:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;map&amp;gt;&lt;br /&gt;
    &amp;lt;spawnpoint id=&amp;quot;spawnpoint1&amp;quot; posX=&amp;quot;1959.5487060547&amp;quot; posY=&amp;quot;-1714.4613037109&amp;quot; posZ=&amp;quot;877.25219726563&amp;quot; rot=&amp;quot;63.350006103516&amp;quot; model=&amp;quot;0&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;pickup id=&amp;quot;Armor 1&amp;quot; posX=&amp;quot;1911.083984375&amp;quot; posY=&amp;quot;-1658.8798828125&amp;quot; posZ=&amp;quot;885.40216064453&amp;quot; type=&amp;quot;armor&amp;quot; health=&amp;quot;50&amp;quot; respawn=&amp;quot;60000&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;flag posX=&amp;quot;1959.5487060547&amp;quot; posY=&amp;quot;-1714.4613037109&amp;quot; posZ=&amp;quot;877.25219726563&amp;quot; team=&amp;quot;blue&amp;quot; /&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
&amp;lt;/map&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here you can see two MTA elements - a spawnpoint and a pickup. More importantly, this .map has a custom &amp;quot;flag&amp;quot; node which defines the position and color of the flag. The spawnpoint and pickup can be handled by existing external resources, custom elements have to be processed by the gamemode.&lt;br /&gt;
&lt;br /&gt;
To summarize - we want mass mapper input as we saw in MTA:Race. Users should NOT have to touch the gamemode script itself at all.&lt;br /&gt;
&lt;br /&gt;
====Example of getting the .map information====&lt;br /&gt;
As mentioned above, your gamemode needs de retrieve custom elements that are defined in a map file and process them. This is quite easy as demonstrated below.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- retrieve a table with all flag elements&lt;br /&gt;
local flagElements = getElementsByType ( &amp;quot;flag&amp;quot; )&lt;br /&gt;
-- loop through them&lt;br /&gt;
for key, value in pairs(flagElements) do&lt;br /&gt;
	-- get our info&lt;br /&gt;
	local posX = getElementData ( value, &amp;quot;posX&amp;quot; )&lt;br /&gt;
	local posY = getElementData ( value, &amp;quot;posY&amp;quot; )&lt;br /&gt;
	local posZ = getElementData ( value, &amp;quot;posZ&amp;quot; )&lt;br /&gt;
	local team = getElementData ( value, &amp;quot;team&amp;quot; )&lt;br /&gt;
	-- create an object according to the flag position&lt;br /&gt;
	createObject ( 1337, posX, posY, posZ )&lt;br /&gt;
	-- output the team that we created a base for&lt;br /&gt;
	outputChatBox ( &amp;quot;Base for team &amp;quot; .. team .. &amp;quot; created&amp;quot; )&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The [[getElementsByType]] function retrieves a table of all the elements of a certain type (the type corresponds to the node name in the .map file). This works for both custom types and built-in MTA types (like &amp;quot;vehicle&amp;quot; or &amp;quot;player&amp;quot;).&lt;br /&gt;
[[getElementData]] can be used to retrieve the xml attributes set in the .map file.&lt;br /&gt;
In this simple example, an object is created at the flag's location and a message is outputted in the chatbox. In reality, you will of course need to do more during map loading, like in this case setting up collision shapes to detect players taking the flag.&lt;br /&gt;
&lt;br /&gt;
==Map manager==&lt;br /&gt;
Having read the section above it should be clear that a gamemode should always consist of two parts:&lt;br /&gt;
* The gamemode resource that always stays the same&lt;br /&gt;
* Many different maps resources that give the gamemode map-specific information&lt;br /&gt;
&lt;br /&gt;
Now instead of writing a map-loader for every single gamemode, the [[Map manager]] provides functions to load gamemodes and maps. Simply put, when you enter the correct command (for example 'gamemode ctf ctf-italy') it will start both resources 'ctf' and 'ctf-italy' while triggering an event ([[onGamemodeMapStart]]) to tell the 'ctf' resource that a map was loaded. The 'ctf' resource can then access the information 'ctf-italy' contains and start spawning players etc.&lt;br /&gt;
&lt;br /&gt;
===How to use the mapmanager===&lt;br /&gt;
To use the mapmanager service, your gamemode resource has to be tagged as such first. More specifically you'll be setting the &amp;quot;type&amp;quot; attribute of its &amp;lt;info&amp;gt; tag to &amp;quot;gamemode&amp;quot; inside meta.xml. Also, you can set the &amp;quot;name&amp;quot; attribute to a friendly name (like &amp;quot;Capture the flag&amp;quot;) that will be shown on ASE instead of the resource name.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- meta.xml in &amp;quot;cowcatapult&amp;quot; gamemode --&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info type=&amp;quot;gamemode&amp;quot; name=&amp;quot;Cow catapulting 2.0&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your gamemode is going to load custom maps, you should add handlers for&lt;br /&gt;
* onGamemodeMapStart&lt;br /&gt;
* onGamemodeMapStop (if any unloading is necessary)&lt;br /&gt;
These are fired when a map for your gamemode is started or stopped, and pass the map resource as a parameter.&lt;br /&gt;
Within the handler function for these events you can extract all info you need from the resource's map files and configuration files.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function startCtfMap( startedMap ) -- startedMap contains a reference to the resource of the map&lt;br /&gt;
    local mapRoot = getResourceRootElement( startedMap )        -- get the root node of the started map&lt;br /&gt;
    local flagElements = getElementsByType ( &amp;quot;flag&amp;quot; , mapRoot ) -- get all flags in the map and store them in a table&lt;br /&gt;
    -- go on loading information like in the example above&lt;br /&gt;
&lt;br /&gt;
    -- spawn players etc.&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
addEventHandler(&amp;quot;onGamemodeMapStart&amp;quot;, getRootElement(), startCtfMap)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Making maps compatible===&lt;br /&gt;
Maps are separate resources. This is done so no editing of the gamemode resource is ever necessary in order to create a custom map, and also allows you to pack map-specific scripts/config files with them.&lt;br /&gt;
&lt;br /&gt;
To make a map compatible with your gamemode, open its resource's meta.xml and tag it as well: the &amp;quot;type&amp;quot; attribute must be set to &amp;quot;map&amp;quot;, and the &amp;quot;gamemodes&amp;quot; attribute must be a comma-separated list (no spaces) of gamemode resource names that the map works with.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--map's meta.xml--&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info type=&amp;quot;map&amp;quot; gamemodes=&amp;quot;cowcatapult,assault,tdm&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have everything set up, admins will use these two commands to start/stop gamemodes:&lt;br /&gt;
/gamemode gamemodeName [mapName] (optional parameter allows picking an initial map, defaults to none)&lt;br /&gt;
/changemap mapName [gamemodeName] (optional parameter specifies the gamemode to start the map with, defaults to the current one)&lt;br /&gt;
&lt;br /&gt;
[[Map manager]] exports a few more access functions which you don't have to use, but may be useful.&lt;br /&gt;
&lt;br /&gt;
==What else should you do==&lt;br /&gt;
There are several other resources that gamemodes should use/be compliant with.&lt;br /&gt;
&lt;br /&gt;
===Helpmanager===&lt;br /&gt;
The helpmanager is ought to be the standard interface for players when they need help. If you use the helpmanager to display your gamemode's help, every player that used helpmanager before (e.g. in other gamemodes) will immediately know how to get there. It also displays help for different resources running resources in one window, if necessary.&lt;br /&gt;
&lt;br /&gt;
There are basicially two ways to use the helpmanager:&lt;br /&gt;
* Provide a simple text that explains how to use your gamemode&lt;br /&gt;
* Request a GUI element from the helpmanager that will be displayed in its own tab in the helpmanager window and lets you add any GUI elements to it. This is the recommended way for gamemodes that need to display more complex information that needs its own GUI.&lt;br /&gt;
&lt;br /&gt;
Read the helpmanager page for details on how to do it.&lt;br /&gt;
&lt;br /&gt;
===Scoreboard===&lt;br /&gt;
Scoreboard displays players and teams currently ingame. You add custom columns to it to provide map specific information. For example the column 'points' in the 'ctf' gamemode could represent the player's points gained through kills or captures. As usual, see the scoreboard help page for more information.&lt;br /&gt;
&lt;br /&gt;
===Map cycler===&lt;br /&gt;
The map cycler controls what gamemodes and maps are played on a server. You can specifiy for example how many times in a row a map will be played until it switches to the next. To achieve this, you need to tell the map cycler when your gamemode finished (e.g. when a round ends).&lt;br /&gt;
&lt;br /&gt;
[[en:Writing Gamemodes]]&lt;br /&gt;
[[it:Scrivere una gamemode]]&lt;/div&gt;</summary>
		<author><name>103495106181459904329</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=RU/Writing_Gamemodes&amp;diff=25906</id>
		<title>RU/Writing Gamemodes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=RU/Writing_Gamemodes&amp;diff=25906"/>
		<updated>2011-05-30T04:41:52Z</updated>

		<summary type="html">&lt;p&gt;103495106181459904329: /* Что означает &amp;quot;правильный игровой режим&amp;quot;? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{translate}}&lt;br /&gt;
Это руководство поможет вам, как написать правильный режим игры. Если вы только что начали писать скрипты для MTA, вы должны сначала просмотреть другие учебники на [[RU/Main Page|Главная страница]].&lt;br /&gt;
==Введение==&lt;br /&gt;
Gamemode (ГМ, мод, гейммод) - ресурс, который, будучи запущенным, контролирует весь игровой процесс. Гейммод включает в себя посылку сообщений игрокам - указания к действиям; респауном игроков; созданием команд; указанием, что игрокам надо делать для победы, или для получения очков, и т.д. Примеры - гонки и DeatMatch'и&lt;br /&gt;
&lt;br /&gt;
==Что означает &amp;quot;правильный игровой режим&amp;quot;?==&lt;br /&gt;
Проще говоря, правильным игровым режимом можно назвать такой режим, который в полной мере использует MTA систему .map файлов. Это означает, что код игрового режима не имеет любых специфических карт, данные которых жестко привязаны к нему, такие как положение игроков или автомобилей. Вместо этого, игровой режим должен быть в состоянии загружать .map файлы, которые и будут определять эти данные. Таким образом, игровой режим может иметь несколько карт, а также люди смогут создавать .map файлы для игрового режима используя MTA редактор карт, который является гораздо более удобным, чем написание кода.&lt;br /&gt;
&lt;br /&gt;
Очевидным примеров &amp;quot;правильного игрового режима&amp;quot; является MTA: Race. Он допускает пользовательские карты с большим количеством возможностей внутри .map файла. Чтобы изменить точки появления игроков, объекты и т.д., пользователю не нужно изменять сам игровой режим.&lt;br /&gt;
&lt;br /&gt;
===Map Files===&lt;br /&gt;
Map files are basically XML documents with a .map extension. They define an environment to play one or more specific gamemodes in. They are however not supposed to change the rules of the game - those are defined by the gamemode.&lt;br /&gt;
&lt;br /&gt;
Each element in a map corresponds to a node in the .map file. There is standard syntax for common things like spawnpoints, objects and vehicles; however, for &amp;quot;special&amp;quot;, gamemode specific information, you need to invent your own syntax.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
Let's take a Capture the Flag gamemode as an example. A map for this gamemode needs to mainly define spawnpoints and flag locations, and eventually objects and vehicles. A simplified map file could look like this:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;map&amp;gt;&lt;br /&gt;
    &amp;lt;spawnpoint id=&amp;quot;spawnpoint1&amp;quot; posX=&amp;quot;1959.5487060547&amp;quot; posY=&amp;quot;-1714.4613037109&amp;quot; posZ=&amp;quot;877.25219726563&amp;quot; rot=&amp;quot;63.350006103516&amp;quot; model=&amp;quot;0&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;pickup id=&amp;quot;Armor 1&amp;quot; posX=&amp;quot;1911.083984375&amp;quot; posY=&amp;quot;-1658.8798828125&amp;quot; posZ=&amp;quot;885.40216064453&amp;quot; type=&amp;quot;armor&amp;quot; health=&amp;quot;50&amp;quot; respawn=&amp;quot;60000&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;flag posX=&amp;quot;1959.5487060547&amp;quot; posY=&amp;quot;-1714.4613037109&amp;quot; posZ=&amp;quot;877.25219726563&amp;quot; team=&amp;quot;blue&amp;quot; /&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
&amp;lt;/map&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here you can see two MTA elements - a spawnpoint and a pickup. More importantly, this .map has a custom &amp;quot;flag&amp;quot; node which defines the position and color of the flag. The spawnpoint and pickup can be handled by existing external resources, custom elements have to be processed by the gamemode.&lt;br /&gt;
&lt;br /&gt;
To summarize - we want mass mapper input as we saw in MTA:Race. Users should NOT have to touch the gamemode script itself at all.&lt;br /&gt;
&lt;br /&gt;
====Example of getting the .map information====&lt;br /&gt;
As mentioned above, your gamemode needs de retrieve custom elements that are defined in a map file and process them. This is quite easy as demonstrated below.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- retrieve a table with all flag elements&lt;br /&gt;
local flagElements = getElementsByType ( &amp;quot;flag&amp;quot; )&lt;br /&gt;
-- loop through them&lt;br /&gt;
for key, value in pairs(flagElements) do&lt;br /&gt;
	-- get our info&lt;br /&gt;
	local posX = getElementData ( value, &amp;quot;posX&amp;quot; )&lt;br /&gt;
	local posY = getElementData ( value, &amp;quot;posY&amp;quot; )&lt;br /&gt;
	local posZ = getElementData ( value, &amp;quot;posZ&amp;quot; )&lt;br /&gt;
	local team = getElementData ( value, &amp;quot;team&amp;quot; )&lt;br /&gt;
	-- create an object according to the flag position&lt;br /&gt;
	createObject ( 1337, posX, posY, posZ )&lt;br /&gt;
	-- output the team that we created a base for&lt;br /&gt;
	outputChatBox ( &amp;quot;Base for team &amp;quot; .. team .. &amp;quot; created&amp;quot; )&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The [[getElementsByType]] function retrieves a table of all the elements of a certain type (the type corresponds to the node name in the .map file). This works for both custom types and built-in MTA types (like &amp;quot;vehicle&amp;quot; or &amp;quot;player&amp;quot;).&lt;br /&gt;
[[getElementData]] can be used to retrieve the xml attributes set in the .map file.&lt;br /&gt;
In this simple example, an object is created at the flag's location and a message is outputted in the chatbox. In reality, you will of course need to do more during map loading, like in this case setting up collision shapes to detect players taking the flag.&lt;br /&gt;
&lt;br /&gt;
==Map manager==&lt;br /&gt;
Having read the section above it should be clear that a gamemode should always consist of two parts:&lt;br /&gt;
* The gamemode resource that always stays the same&lt;br /&gt;
* Many different maps resources that give the gamemode map-specific information&lt;br /&gt;
&lt;br /&gt;
Now instead of writing a map-loader for every single gamemode, the [[Map manager]] provides functions to load gamemodes and maps. Simply put, when you enter the correct command (for example 'gamemode ctf ctf-italy') it will start both resources 'ctf' and 'ctf-italy' while triggering an event ([[onGamemodeMapStart]]) to tell the 'ctf' resource that a map was loaded. The 'ctf' resource can then access the information 'ctf-italy' contains and start spawning players etc.&lt;br /&gt;
&lt;br /&gt;
===How to use the mapmanager===&lt;br /&gt;
To use the mapmanager service, your gamemode resource has to be tagged as such first. More specifically you'll be setting the &amp;quot;type&amp;quot; attribute of its &amp;lt;info&amp;gt; tag to &amp;quot;gamemode&amp;quot; inside meta.xml. Also, you can set the &amp;quot;name&amp;quot; attribute to a friendly name (like &amp;quot;Capture the flag&amp;quot;) that will be shown on ASE instead of the resource name.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- meta.xml in &amp;quot;cowcatapult&amp;quot; gamemode --&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info type=&amp;quot;gamemode&amp;quot; name=&amp;quot;Cow catapulting 2.0&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your gamemode is going to load custom maps, you should add handlers for&lt;br /&gt;
* onGamemodeMapStart&lt;br /&gt;
* onGamemodeMapStop (if any unloading is necessary)&lt;br /&gt;
These are fired when a map for your gamemode is started or stopped, and pass the map resource as a parameter.&lt;br /&gt;
Within the handler function for these events you can extract all info you need from the resource's map files and configuration files.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function startCtfMap( startedMap ) -- startedMap contains a reference to the resource of the map&lt;br /&gt;
    local mapRoot = getResourceRootElement( startedMap )        -- get the root node of the started map&lt;br /&gt;
    local flagElements = getElementsByType ( &amp;quot;flag&amp;quot; , mapRoot ) -- get all flags in the map and store them in a table&lt;br /&gt;
    -- go on loading information like in the example above&lt;br /&gt;
&lt;br /&gt;
    -- spawn players etc.&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
addEventHandler(&amp;quot;onGamemodeMapStart&amp;quot;, getRootElement(), startCtfMap)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Making maps compatible===&lt;br /&gt;
Maps are separate resources. This is done so no editing of the gamemode resource is ever necessary in order to create a custom map, and also allows you to pack map-specific scripts/config files with them.&lt;br /&gt;
&lt;br /&gt;
To make a map compatible with your gamemode, open its resource's meta.xml and tag it as well: the &amp;quot;type&amp;quot; attribute must be set to &amp;quot;map&amp;quot;, and the &amp;quot;gamemodes&amp;quot; attribute must be a comma-separated list (no spaces) of gamemode resource names that the map works with.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--map's meta.xml--&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info type=&amp;quot;map&amp;quot; gamemodes=&amp;quot;cowcatapult,assault,tdm&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have everything set up, admins will use these two commands to start/stop gamemodes:&lt;br /&gt;
/gamemode gamemodeName [mapName] (optional parameter allows picking an initial map, defaults to none)&lt;br /&gt;
/changemap mapName [gamemodeName] (optional parameter specifies the gamemode to start the map with, defaults to the current one)&lt;br /&gt;
&lt;br /&gt;
[[Map manager]] exports a few more access functions which you don't have to use, but may be useful.&lt;br /&gt;
&lt;br /&gt;
==What else should you do==&lt;br /&gt;
There are several other resources that gamemodes should use/be compliant with.&lt;br /&gt;
&lt;br /&gt;
===Helpmanager===&lt;br /&gt;
The helpmanager is ought to be the standard interface for players when they need help. If you use the helpmanager to display your gamemode's help, every player that used helpmanager before (e.g. in other gamemodes) will immediately know how to get there. It also displays help for different resources running resources in one window, if necessary.&lt;br /&gt;
&lt;br /&gt;
There are basicially two ways to use the helpmanager:&lt;br /&gt;
* Provide a simple text that explains how to use your gamemode&lt;br /&gt;
* Request a GUI element from the helpmanager that will be displayed in its own tab in the helpmanager window and lets you add any GUI elements to it. This is the recommended way for gamemodes that need to display more complex information that needs its own GUI.&lt;br /&gt;
&lt;br /&gt;
Read the helpmanager page for details on how to do it.&lt;br /&gt;
&lt;br /&gt;
===Scoreboard===&lt;br /&gt;
Scoreboard displays players and teams currently ingame. You add custom columns to it to provide map specific information. For example the column 'points' in the 'ctf' gamemode could represent the player's points gained through kills or captures. As usual, see the scoreboard help page for more information.&lt;br /&gt;
&lt;br /&gt;
===Map cycler===&lt;br /&gt;
The map cycler controls what gamemodes and maps are played on a server. You can specifiy for example how many times in a row a map will be played until it switches to the next. To achieve this, you need to tell the map cycler when your gamemode finished (e.g. when a round ends).&lt;br /&gt;
&lt;br /&gt;
[[en:Writing Gamemodes]]&lt;br /&gt;
[[it:Scrivere una gamemode]]&lt;/div&gt;</summary>
		<author><name>103495106181459904329</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=RU/Writing_Gamemodes&amp;diff=25905</id>
		<title>RU/Writing Gamemodes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=RU/Writing_Gamemodes&amp;diff=25905"/>
		<updated>2011-05-30T04:35:30Z</updated>

		<summary type="html">&lt;p&gt;103495106181459904329: /* Что означает &amp;quot;правильный игровой режим&amp;quot;? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{translate}}&lt;br /&gt;
Это руководство поможет вам, как написать правильный режим игры. Если вы только что начали писать скрипты для MTA, вы должны сначала просмотреть другие учебники на [[RU/Main Page|Главная страница]].&lt;br /&gt;
==Введение==&lt;br /&gt;
Gamemode (ГМ, мод, гейммод) - ресурс, который, будучи запущенным, контролирует весь игровой процесс. Гейммод включает в себя посылку сообщений игрокам - указания к действиям; респауном игроков; созданием команд; указанием, что игрокам надо делать для победы, или для получения очков, и т.д. Примеры - гонки и DeatMatch'и&lt;br /&gt;
&lt;br /&gt;
==Что означает &amp;quot;правильный игровой режим&amp;quot;?==&lt;br /&gt;
Проще говоря, правильным игровым режимом можно назвать такой режим, который в полной мере использует MTA систему .map файлов. Это означает, что код игрового режима не имеет любых специфических карт, данные которых жестко привязаны к нему, такие как положение игроков или автомобилей. Вместо этого, игровой режим должен быть в состоянии загружать .map файлы, которые и будут определять эти данные. Таким образом, игровой режим может иметь несколько карт, а также люди смогут создавать .map файлы для игрового режима используя MTA редактор карт, который является гораздо более удобным, чем написание кода.&lt;br /&gt;
&lt;br /&gt;
An obvious example of a &amp;quot;proper gamemode&amp;quot; is MTA:Race. It allows usermade maps with lots of possibilities within the .map file. To alter spawnpoints, objects etc., the user doesn't need to edit the gamemode itself.&lt;br /&gt;
&lt;br /&gt;
===Map Files===&lt;br /&gt;
Map files are basically XML documents with a .map extension. They define an environment to play one or more specific gamemodes in. They are however not supposed to change the rules of the game - those are defined by the gamemode.&lt;br /&gt;
&lt;br /&gt;
Each element in a map corresponds to a node in the .map file. There is standard syntax for common things like spawnpoints, objects and vehicles; however, for &amp;quot;special&amp;quot;, gamemode specific information, you need to invent your own syntax.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
Let's take a Capture the Flag gamemode as an example. A map for this gamemode needs to mainly define spawnpoints and flag locations, and eventually objects and vehicles. A simplified map file could look like this:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;map&amp;gt;&lt;br /&gt;
    &amp;lt;spawnpoint id=&amp;quot;spawnpoint1&amp;quot; posX=&amp;quot;1959.5487060547&amp;quot; posY=&amp;quot;-1714.4613037109&amp;quot; posZ=&amp;quot;877.25219726563&amp;quot; rot=&amp;quot;63.350006103516&amp;quot; model=&amp;quot;0&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;pickup id=&amp;quot;Armor 1&amp;quot; posX=&amp;quot;1911.083984375&amp;quot; posY=&amp;quot;-1658.8798828125&amp;quot; posZ=&amp;quot;885.40216064453&amp;quot; type=&amp;quot;armor&amp;quot; health=&amp;quot;50&amp;quot; respawn=&amp;quot;60000&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;flag posX=&amp;quot;1959.5487060547&amp;quot; posY=&amp;quot;-1714.4613037109&amp;quot; posZ=&amp;quot;877.25219726563&amp;quot; team=&amp;quot;blue&amp;quot; /&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
&amp;lt;/map&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here you can see two MTA elements - a spawnpoint and a pickup. More importantly, this .map has a custom &amp;quot;flag&amp;quot; node which defines the position and color of the flag. The spawnpoint and pickup can be handled by existing external resources, custom elements have to be processed by the gamemode.&lt;br /&gt;
&lt;br /&gt;
To summarize - we want mass mapper input as we saw in MTA:Race. Users should NOT have to touch the gamemode script itself at all.&lt;br /&gt;
&lt;br /&gt;
====Example of getting the .map information====&lt;br /&gt;
As mentioned above, your gamemode needs de retrieve custom elements that are defined in a map file and process them. This is quite easy as demonstrated below.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- retrieve a table with all flag elements&lt;br /&gt;
local flagElements = getElementsByType ( &amp;quot;flag&amp;quot; )&lt;br /&gt;
-- loop through them&lt;br /&gt;
for key, value in pairs(flagElements) do&lt;br /&gt;
	-- get our info&lt;br /&gt;
	local posX = getElementData ( value, &amp;quot;posX&amp;quot; )&lt;br /&gt;
	local posY = getElementData ( value, &amp;quot;posY&amp;quot; )&lt;br /&gt;
	local posZ = getElementData ( value, &amp;quot;posZ&amp;quot; )&lt;br /&gt;
	local team = getElementData ( value, &amp;quot;team&amp;quot; )&lt;br /&gt;
	-- create an object according to the flag position&lt;br /&gt;
	createObject ( 1337, posX, posY, posZ )&lt;br /&gt;
	-- output the team that we created a base for&lt;br /&gt;
	outputChatBox ( &amp;quot;Base for team &amp;quot; .. team .. &amp;quot; created&amp;quot; )&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The [[getElementsByType]] function retrieves a table of all the elements of a certain type (the type corresponds to the node name in the .map file). This works for both custom types and built-in MTA types (like &amp;quot;vehicle&amp;quot; or &amp;quot;player&amp;quot;).&lt;br /&gt;
[[getElementData]] can be used to retrieve the xml attributes set in the .map file.&lt;br /&gt;
In this simple example, an object is created at the flag's location and a message is outputted in the chatbox. In reality, you will of course need to do more during map loading, like in this case setting up collision shapes to detect players taking the flag.&lt;br /&gt;
&lt;br /&gt;
==Map manager==&lt;br /&gt;
Having read the section above it should be clear that a gamemode should always consist of two parts:&lt;br /&gt;
* The gamemode resource that always stays the same&lt;br /&gt;
* Many different maps resources that give the gamemode map-specific information&lt;br /&gt;
&lt;br /&gt;
Now instead of writing a map-loader for every single gamemode, the [[Map manager]] provides functions to load gamemodes and maps. Simply put, when you enter the correct command (for example 'gamemode ctf ctf-italy') it will start both resources 'ctf' and 'ctf-italy' while triggering an event ([[onGamemodeMapStart]]) to tell the 'ctf' resource that a map was loaded. The 'ctf' resource can then access the information 'ctf-italy' contains and start spawning players etc.&lt;br /&gt;
&lt;br /&gt;
===How to use the mapmanager===&lt;br /&gt;
To use the mapmanager service, your gamemode resource has to be tagged as such first. More specifically you'll be setting the &amp;quot;type&amp;quot; attribute of its &amp;lt;info&amp;gt; tag to &amp;quot;gamemode&amp;quot; inside meta.xml. Also, you can set the &amp;quot;name&amp;quot; attribute to a friendly name (like &amp;quot;Capture the flag&amp;quot;) that will be shown on ASE instead of the resource name.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- meta.xml in &amp;quot;cowcatapult&amp;quot; gamemode --&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info type=&amp;quot;gamemode&amp;quot; name=&amp;quot;Cow catapulting 2.0&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your gamemode is going to load custom maps, you should add handlers for&lt;br /&gt;
* onGamemodeMapStart&lt;br /&gt;
* onGamemodeMapStop (if any unloading is necessary)&lt;br /&gt;
These are fired when a map for your gamemode is started or stopped, and pass the map resource as a parameter.&lt;br /&gt;
Within the handler function for these events you can extract all info you need from the resource's map files and configuration files.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function startCtfMap( startedMap ) -- startedMap contains a reference to the resource of the map&lt;br /&gt;
    local mapRoot = getResourceRootElement( startedMap )        -- get the root node of the started map&lt;br /&gt;
    local flagElements = getElementsByType ( &amp;quot;flag&amp;quot; , mapRoot ) -- get all flags in the map and store them in a table&lt;br /&gt;
    -- go on loading information like in the example above&lt;br /&gt;
&lt;br /&gt;
    -- spawn players etc.&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
addEventHandler(&amp;quot;onGamemodeMapStart&amp;quot;, getRootElement(), startCtfMap)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Making maps compatible===&lt;br /&gt;
Maps are separate resources. This is done so no editing of the gamemode resource is ever necessary in order to create a custom map, and also allows you to pack map-specific scripts/config files with them.&lt;br /&gt;
&lt;br /&gt;
To make a map compatible with your gamemode, open its resource's meta.xml and tag it as well: the &amp;quot;type&amp;quot; attribute must be set to &amp;quot;map&amp;quot;, and the &amp;quot;gamemodes&amp;quot; attribute must be a comma-separated list (no spaces) of gamemode resource names that the map works with.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--map's meta.xml--&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info type=&amp;quot;map&amp;quot; gamemodes=&amp;quot;cowcatapult,assault,tdm&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have everything set up, admins will use these two commands to start/stop gamemodes:&lt;br /&gt;
/gamemode gamemodeName [mapName] (optional parameter allows picking an initial map, defaults to none)&lt;br /&gt;
/changemap mapName [gamemodeName] (optional parameter specifies the gamemode to start the map with, defaults to the current one)&lt;br /&gt;
&lt;br /&gt;
[[Map manager]] exports a few more access functions which you don't have to use, but may be useful.&lt;br /&gt;
&lt;br /&gt;
==What else should you do==&lt;br /&gt;
There are several other resources that gamemodes should use/be compliant with.&lt;br /&gt;
&lt;br /&gt;
===Helpmanager===&lt;br /&gt;
The helpmanager is ought to be the standard interface for players when they need help. If you use the helpmanager to display your gamemode's help, every player that used helpmanager before (e.g. in other gamemodes) will immediately know how to get there. It also displays help for different resources running resources in one window, if necessary.&lt;br /&gt;
&lt;br /&gt;
There are basicially two ways to use the helpmanager:&lt;br /&gt;
* Provide a simple text that explains how to use your gamemode&lt;br /&gt;
* Request a GUI element from the helpmanager that will be displayed in its own tab in the helpmanager window and lets you add any GUI elements to it. This is the recommended way for gamemodes that need to display more complex information that needs its own GUI.&lt;br /&gt;
&lt;br /&gt;
Read the helpmanager page for details on how to do it.&lt;br /&gt;
&lt;br /&gt;
===Scoreboard===&lt;br /&gt;
Scoreboard displays players and teams currently ingame. You add custom columns to it to provide map specific information. For example the column 'points' in the 'ctf' gamemode could represent the player's points gained through kills or captures. As usual, see the scoreboard help page for more information.&lt;br /&gt;
&lt;br /&gt;
===Map cycler===&lt;br /&gt;
The map cycler controls what gamemodes and maps are played on a server. You can specifiy for example how many times in a row a map will be played until it switches to the next. To achieve this, you need to tell the map cycler when your gamemode finished (e.g. when a round ends).&lt;br /&gt;
&lt;br /&gt;
[[en:Writing Gamemodes]]&lt;br /&gt;
[[it:Scrivere una gamemode]]&lt;/div&gt;</summary>
		<author><name>103495106181459904329</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=RU/Writing_Gamemodes&amp;diff=25904</id>
		<title>RU/Writing Gamemodes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=RU/Writing_Gamemodes&amp;diff=25904"/>
		<updated>2011-05-30T04:25:16Z</updated>

		<summary type="html">&lt;p&gt;103495106181459904329: /* What does &amp;quot;proper gamemode&amp;quot; mean? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{translate}}&lt;br /&gt;
Это руководство поможет вам, как написать правильный режим игры. Если вы только что начали писать скрипты для MTA, вы должны сначала просмотреть другие учебники на [[RU/Main Page|Главная страница]].&lt;br /&gt;
==Введение==&lt;br /&gt;
Gamemode (ГМ, мод, гейммод) - ресурс, который, будучи запущенным, контролирует весь игровой процесс. Гейммод включает в себя посылку сообщений игрокам - указания к действиям; респауном игроков; созданием команд; указанием, что игрокам надо делать для победы, или для получения очков, и т.д. Примеры - гонки и DeatMatch'и&lt;br /&gt;
&lt;br /&gt;
==Что означает &amp;quot;правильный игровой режим&amp;quot;?==&lt;br /&gt;
Проще говоря, правильным игровым режимом можно назвать такой режим, который в полной мере использует MTA систему .map файлов. Это означает, что код игрового режима не имеет любых специфических карт, данные которых жестко привязаны к нему, таких как положение игроков или автомобилей. Instead, the gamemode should be able to load .map files which define these data. This way the gamemode can have multiple maps; also, people can create .map files for the gamemode with MTA's map editor, which is much more convenient than writing code.&lt;br /&gt;
&lt;br /&gt;
An obvious example of a &amp;quot;proper gamemode&amp;quot; is MTA:Race. It allows usermade maps with lots of possibilities within the .map file. To alter spawnpoints, objects etc., the user doesn't need to edit the gamemode itself.&lt;br /&gt;
&lt;br /&gt;
===Map Files===&lt;br /&gt;
Map files are basically XML documents with a .map extension. They define an environment to play one or more specific gamemodes in. They are however not supposed to change the rules of the game - those are defined by the gamemode.&lt;br /&gt;
&lt;br /&gt;
Each element in a map corresponds to a node in the .map file. There is standard syntax for common things like spawnpoints, objects and vehicles; however, for &amp;quot;special&amp;quot;, gamemode specific information, you need to invent your own syntax.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
Let's take a Capture the Flag gamemode as an example. A map for this gamemode needs to mainly define spawnpoints and flag locations, and eventually objects and vehicles. A simplified map file could look like this:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;map&amp;gt;&lt;br /&gt;
    &amp;lt;spawnpoint id=&amp;quot;spawnpoint1&amp;quot; posX=&amp;quot;1959.5487060547&amp;quot; posY=&amp;quot;-1714.4613037109&amp;quot; posZ=&amp;quot;877.25219726563&amp;quot; rot=&amp;quot;63.350006103516&amp;quot; model=&amp;quot;0&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;pickup id=&amp;quot;Armor 1&amp;quot; posX=&amp;quot;1911.083984375&amp;quot; posY=&amp;quot;-1658.8798828125&amp;quot; posZ=&amp;quot;885.40216064453&amp;quot; type=&amp;quot;armor&amp;quot; health=&amp;quot;50&amp;quot; respawn=&amp;quot;60000&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;flag posX=&amp;quot;1959.5487060547&amp;quot; posY=&amp;quot;-1714.4613037109&amp;quot; posZ=&amp;quot;877.25219726563&amp;quot; team=&amp;quot;blue&amp;quot; /&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
&amp;lt;/map&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here you can see two MTA elements - a spawnpoint and a pickup. More importantly, this .map has a custom &amp;quot;flag&amp;quot; node which defines the position and color of the flag. The spawnpoint and pickup can be handled by existing external resources, custom elements have to be processed by the gamemode.&lt;br /&gt;
&lt;br /&gt;
To summarize - we want mass mapper input as we saw in MTA:Race. Users should NOT have to touch the gamemode script itself at all.&lt;br /&gt;
&lt;br /&gt;
====Example of getting the .map information====&lt;br /&gt;
As mentioned above, your gamemode needs de retrieve custom elements that are defined in a map file and process them. This is quite easy as demonstrated below.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- retrieve a table with all flag elements&lt;br /&gt;
local flagElements = getElementsByType ( &amp;quot;flag&amp;quot; )&lt;br /&gt;
-- loop through them&lt;br /&gt;
for key, value in pairs(flagElements) do&lt;br /&gt;
	-- get our info&lt;br /&gt;
	local posX = getElementData ( value, &amp;quot;posX&amp;quot; )&lt;br /&gt;
	local posY = getElementData ( value, &amp;quot;posY&amp;quot; )&lt;br /&gt;
	local posZ = getElementData ( value, &amp;quot;posZ&amp;quot; )&lt;br /&gt;
	local team = getElementData ( value, &amp;quot;team&amp;quot; )&lt;br /&gt;
	-- create an object according to the flag position&lt;br /&gt;
	createObject ( 1337, posX, posY, posZ )&lt;br /&gt;
	-- output the team that we created a base for&lt;br /&gt;
	outputChatBox ( &amp;quot;Base for team &amp;quot; .. team .. &amp;quot; created&amp;quot; )&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The [[getElementsByType]] function retrieves a table of all the elements of a certain type (the type corresponds to the node name in the .map file). This works for both custom types and built-in MTA types (like &amp;quot;vehicle&amp;quot; or &amp;quot;player&amp;quot;).&lt;br /&gt;
[[getElementData]] can be used to retrieve the xml attributes set in the .map file.&lt;br /&gt;
In this simple example, an object is created at the flag's location and a message is outputted in the chatbox. In reality, you will of course need to do more during map loading, like in this case setting up collision shapes to detect players taking the flag.&lt;br /&gt;
&lt;br /&gt;
==Map manager==&lt;br /&gt;
Having read the section above it should be clear that a gamemode should always consist of two parts:&lt;br /&gt;
* The gamemode resource that always stays the same&lt;br /&gt;
* Many different maps resources that give the gamemode map-specific information&lt;br /&gt;
&lt;br /&gt;
Now instead of writing a map-loader for every single gamemode, the [[Map manager]] provides functions to load gamemodes and maps. Simply put, when you enter the correct command (for example 'gamemode ctf ctf-italy') it will start both resources 'ctf' and 'ctf-italy' while triggering an event ([[onGamemodeMapStart]]) to tell the 'ctf' resource that a map was loaded. The 'ctf' resource can then access the information 'ctf-italy' contains and start spawning players etc.&lt;br /&gt;
&lt;br /&gt;
===How to use the mapmanager===&lt;br /&gt;
To use the mapmanager service, your gamemode resource has to be tagged as such first. More specifically you'll be setting the &amp;quot;type&amp;quot; attribute of its &amp;lt;info&amp;gt; tag to &amp;quot;gamemode&amp;quot; inside meta.xml. Also, you can set the &amp;quot;name&amp;quot; attribute to a friendly name (like &amp;quot;Capture the flag&amp;quot;) that will be shown on ASE instead of the resource name.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- meta.xml in &amp;quot;cowcatapult&amp;quot; gamemode --&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info type=&amp;quot;gamemode&amp;quot; name=&amp;quot;Cow catapulting 2.0&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your gamemode is going to load custom maps, you should add handlers for&lt;br /&gt;
* onGamemodeMapStart&lt;br /&gt;
* onGamemodeMapStop (if any unloading is necessary)&lt;br /&gt;
These are fired when a map for your gamemode is started or stopped, and pass the map resource as a parameter.&lt;br /&gt;
Within the handler function for these events you can extract all info you need from the resource's map files and configuration files.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function startCtfMap( startedMap ) -- startedMap contains a reference to the resource of the map&lt;br /&gt;
    local mapRoot = getResourceRootElement( startedMap )        -- get the root node of the started map&lt;br /&gt;
    local flagElements = getElementsByType ( &amp;quot;flag&amp;quot; , mapRoot ) -- get all flags in the map and store them in a table&lt;br /&gt;
    -- go on loading information like in the example above&lt;br /&gt;
&lt;br /&gt;
    -- spawn players etc.&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
addEventHandler(&amp;quot;onGamemodeMapStart&amp;quot;, getRootElement(), startCtfMap)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Making maps compatible===&lt;br /&gt;
Maps are separate resources. This is done so no editing of the gamemode resource is ever necessary in order to create a custom map, and also allows you to pack map-specific scripts/config files with them.&lt;br /&gt;
&lt;br /&gt;
To make a map compatible with your gamemode, open its resource's meta.xml and tag it as well: the &amp;quot;type&amp;quot; attribute must be set to &amp;quot;map&amp;quot;, and the &amp;quot;gamemodes&amp;quot; attribute must be a comma-separated list (no spaces) of gamemode resource names that the map works with.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--map's meta.xml--&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;&lt;br /&gt;
    &amp;lt;info type=&amp;quot;map&amp;quot; gamemodes=&amp;quot;cowcatapult,assault,tdm&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/meta&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have everything set up, admins will use these two commands to start/stop gamemodes:&lt;br /&gt;
/gamemode gamemodeName [mapName] (optional parameter allows picking an initial map, defaults to none)&lt;br /&gt;
/changemap mapName [gamemodeName] (optional parameter specifies the gamemode to start the map with, defaults to the current one)&lt;br /&gt;
&lt;br /&gt;
[[Map manager]] exports a few more access functions which you don't have to use, but may be useful.&lt;br /&gt;
&lt;br /&gt;
==What else should you do==&lt;br /&gt;
There are several other resources that gamemodes should use/be compliant with.&lt;br /&gt;
&lt;br /&gt;
===Helpmanager===&lt;br /&gt;
The helpmanager is ought to be the standard interface for players when they need help. If you use the helpmanager to display your gamemode's help, every player that used helpmanager before (e.g. in other gamemodes) will immediately know how to get there. It also displays help for different resources running resources in one window, if necessary.&lt;br /&gt;
&lt;br /&gt;
There are basicially two ways to use the helpmanager:&lt;br /&gt;
* Provide a simple text that explains how to use your gamemode&lt;br /&gt;
* Request a GUI element from the helpmanager that will be displayed in its own tab in the helpmanager window and lets you add any GUI elements to it. This is the recommended way for gamemodes that need to display more complex information that needs its own GUI.&lt;br /&gt;
&lt;br /&gt;
Read the helpmanager page for details on how to do it.&lt;br /&gt;
&lt;br /&gt;
===Scoreboard===&lt;br /&gt;
Scoreboard displays players and teams currently ingame. You add custom columns to it to provide map specific information. For example the column 'points' in the 'ctf' gamemode could represent the player's points gained through kills or captures. As usual, see the scoreboard help page for more information.&lt;br /&gt;
&lt;br /&gt;
===Map cycler===&lt;br /&gt;
The map cycler controls what gamemodes and maps are played on a server. You can specifiy for example how many times in a row a map will be played until it switches to the next. To achieve this, you need to tell the map cycler when your gamemode finished (e.g. when a round ends).&lt;br /&gt;
&lt;br /&gt;
[[en:Writing Gamemodes]]&lt;br /&gt;
[[it:Scrivere una gamemode]]&lt;/div&gt;</summary>
		<author><name>103495106181459904329</name></author>
	</entry>
</feed>