<?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=WilliJ</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=WilliJ"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/wiki/Special:Contributions/WilliJ"/>
	<updated>2026-05-09T05:29:06Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=RU/Element_tree&amp;diff=25838</id>
		<title>RU/Element tree</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=RU/Element_tree&amp;diff=25838"/>
		<updated>2011-05-17T16:57:36Z</updated>

		<summary type="html">&lt;p&gt;WilliJ: /* Дерево элементов */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{translate}}&lt;br /&gt;
В MTA используется так называемое ''Дерево элементов'', которое содержит все элементы, расположенные на сервере и клиенте. Это непосредственно связано с расположением работающих [[ресурсов]] и XML файлов карт, хотя может быть изменено во время работы с помощью скриптов.&lt;br /&gt;
&lt;br /&gt;
Если вы знакомы с компьютерным понятием ''Дерево''(ветка, куст и т.д.), то вам будет легче разобраться. Если вы не понимаете, о чем речь, то ''Дерево элементов'' можно представить как ''Семейное дерево'' - в нём каждый человек имеет родителя. Так же и здесь. Каждый [[элемент]](в дальнейшем потомок) имеет своего ''родителя''.&lt;br /&gt;
&lt;br /&gt;
Все элементы, которые созданы внутри скриптов или файлов карт, являются потомками ресурса, которому они принадлежат. По этому, большинство элементов (за исключением [[клиент]]ских) существуют только во время работы ресурсов и перестают работать при остановке этих ресурсов.&lt;br /&gt;
&lt;br /&gt;
==Дерево элементов==&lt;br /&gt;
* '''root'''(корень): Это самый главный начальный элемент - корень. Все элементы - потомки этого элемента.&lt;br /&gt;
* '''resource'''(ресурсы): Это прямой потомок корня, с одним для каждого запущенным ресурсом(ресурсов может быть множество). Его так же можно назвать ''корень ресурса''. Его ID номер - это название ресурса.&lt;br /&gt;
* '''map'''(карта): Каждый элемент ресурса может содержать по крайней мере один элемент карты - это так называемые &amp;quot;.map&amp;quot; файлы находящиеся в ресурсах. Так же карта может быть создана скриптом - тогда такие карты называются ''динамическими''. Их ID номера содержат название карт, плюс дополнительно ''dynamic'' для динамических карт.&lt;br /&gt;
** Файлы карт могут содержать различное число [[элемент]]ов.&lt;br /&gt;
&lt;br /&gt;
==Пример==&lt;br /&gt;
Этот пример для серверной стороны, который сохраняет дамп дерева сервера в XML файл во время его работы.&lt;br /&gt;
''Просим заметить, что в некоторых местах имеются сокращения ради краткости обзора функции.''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;root&amp;gt;&lt;br /&gt;
	&amp;lt;console/&amp;gt;&lt;br /&gt;
	&amp;lt;player dontRespawn=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;player dontRespawn=&amp;quot;false&amp;quot; lastSpawnarea=&amp;quot;&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;resourcebrowser&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;ajax&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;resourcemanager&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;spawnmanager&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;mapmanager&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;runcode&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;fr&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;dynamic&amp;quot;&amp;gt;&lt;br /&gt;
			&amp;lt;vehicle/&amp;gt;&lt;br /&gt;
		&amp;lt;/map&amp;gt;&lt;br /&gt;
	&amp;lt;/resource&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;elementbrowser&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;assault&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;dynamic&amp;quot;&amp;gt;&lt;br /&gt;
			&amp;lt;team/&amp;gt;&lt;br /&gt;
			&amp;lt;team/&amp;gt;&lt;br /&gt;
			&amp;lt;blip/&amp;gt;&lt;br /&gt;
			&amp;lt;marker/&amp;gt;&lt;br /&gt;
			&amp;lt;colshape/&amp;gt;&lt;br /&gt;
			&amp;lt;blip/&amp;gt;&lt;br /&gt;
			&amp;lt;blip/&amp;gt;&lt;br /&gt;
		&amp;lt;/map&amp;gt;&lt;br /&gt;
	&amp;lt;/resource&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;as-farm&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;dynamic&amp;quot;/&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;as-farm.map&amp;quot;&amp;gt;&lt;br /&gt;
			&amp;lt;meta&amp;gt;&lt;br /&gt;
				&amp;lt;author/&amp;gt;&lt;br /&gt;
				&amp;lt;version/&amp;gt;&lt;br /&gt;
				&amp;lt;name/&amp;gt;&lt;br /&gt;
				&amp;lt;description/&amp;gt;&lt;br /&gt;
			&amp;lt;/meta&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;-8.3976354598999&amp;quot; posX=&amp;quot;20.182683944702&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;32.166355133057&amp;quot; posX=&amp;quot;-46.90763092041&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;35.214984893799&amp;quot; posX=&amp;quot;-33.486911773682&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;35.214984893799&amp;quot; posX=&amp;quot;-33.486911773682&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;objective id=&amp;quot;first&amp;quot; type=&amp;quot;checkpoint&amp;quot; description=&amp;quot;Breach into the farm&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;pickup type=&amp;quot;weapon&amp;quot; ... /&amp;gt;&lt;br /&gt;
		&amp;lt;/map&amp;gt;&lt;br /&gt;
	&amp;lt;/resource&amp;gt;&lt;br /&gt;
&amp;lt;/root&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
===Пояснение===&lt;br /&gt;
This tree consists of a number of resource root elements, the [[Element/Console|server console]] and two [[player]] elements, that are direct children of the '''root''' element. All these resources have a ''dynamic map'' as child element (it is just not shown for most of them). These contain the elements that are created dynamically by this resource using scripts, for example a [[vehicle]]. If the resource has a map file, it is also a child element, itself containing all the elements in the .map file.&lt;br /&gt;
&lt;br /&gt;
Let's have a closer look at the '''assault''' resource: This contains just one ''dynamic'' map that has 2 teams, 3 blips, 1 marker and 1 colshape as child elements. These are the elements that are created by the script, for example the marker, the colshape and one of the blips are probably used for the objective.&lt;br /&gt;
&lt;br /&gt;
The '''as-farm''' resource's function on the contrary is to be a map for the '''assault''' gamemode. The dynamic map is empty (it could contain elements if there was a script in it though), while there is a map called 'as-farm.map', that contains a number of elements. These are mostly custom elements (like spawngroup, spawnarea, objective) but also a few elements that MTA creates automactically after loading the map (like pickup). In the brackets after the element type, you can see the element data it contains. These are identical with the attributes the .map file contains within these elements, while you can also set and get element data for any other elements (e.g. players) with [[setElementData]] and [[getElementData]].&lt;br /&gt;
&lt;br /&gt;
==Практическое занятие==&lt;br /&gt;
Elements can have as many children as they like. This does not directly affect the map in any way, but it comes in to its own when combined with the scripting system.&lt;br /&gt;
&lt;br /&gt;
===Настройки для элементов===&lt;br /&gt;
If you call a set... function on a node of the element tree, the function will affect every element within it (that it can work on).&lt;br /&gt;
&lt;br /&gt;
So, the following code would set the size of every marker (the only type of element the setMarkerSize function can work on) that is below the root element to ''2.5''.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
setMarkerSize ( getRootElement(), 2.5 )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same can be done on any element, it is not restricted to the root element.&lt;br /&gt;
&lt;br /&gt;
===Менеджер карт===&lt;br /&gt;
The [[#Example|example above]] shows the way the [[map manager]] uses different resources. The 'assault' resource is the gamemode, that manages what happens on the server using scripts and thus by creating elements in the tree dynamically. When a map resource is started, the gamemode receives a [[resource|resource pointer]] referring to the started resource - in this case ''as-farm'' - from which you can retrieve and store the resource root element. Using this element in conjunction with functions like [[getElementsByType]], [[getElementData]] and various others, you can access any of the information that was loaded into the tree from the 'as-farm.map'-file through scripts in the gamemode resource.&lt;br /&gt;
&lt;br /&gt;
Another thing that has to be considered related to the tree of elements is the fact that when you change the map, you don't have to remove any elements you created within the map resource, while you '''do''' have to remove elements that are created within the gamemode resource, '''if''' they are specific to the map (which will be probably the case for those items you create based on information read from the map resource's .map files).&lt;br /&gt;
&lt;br /&gt;
==Element browser==&lt;br /&gt;
You can start the resource ''elementbrowser'' to see a live view of the element tree on your server. Just start the resource and browser to your server's web page and choose the ''Element browser'' option in the sidebar (firefox only currently).&lt;br /&gt;
[[Category:Scripting Concepts]]&lt;/div&gt;</summary>
		<author><name>WilliJ</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=RU/Element_tree&amp;diff=25837</id>
		<title>RU/Element tree</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=RU/Element_tree&amp;diff=25837"/>
		<updated>2011-05-17T16:55:33Z</updated>

		<summary type="html">&lt;p&gt;WilliJ: /* Пример */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{translate}}&lt;br /&gt;
В MTA используется так называемое ''Дерево элементов'', которое содержит все элементы, расположенные на сервере и клиенте. Это непосредственно связано с расположением работающих [[ресурсов]] и XML файлов карт, хотя может быть изменено во время работы с помощью скриптов.&lt;br /&gt;
&lt;br /&gt;
Если вы знакомы с компьютерным понятием ''Дерево''(ветка, куст и т.д.), то вам будет легче разобраться. Если вы не понимаете, о чем речь, то ''Дерево элементов'' можно представить как ''Семейное дерево'' - в нём каждый человек имеет родителя. Так же и здесь. Каждый [[элемент]](в дальнейшем потомок) имеет своего ''родителя''.&lt;br /&gt;
&lt;br /&gt;
Все элементы, которые созданы внутри скриптов или файлов карт, являются потомками ресурса, которому они принадлежат. По этому, большинство элементов (за исключением [[клиент]]ских) существуют только во время работы ресурсов и перестают работать при остановке этих ресурсов.&lt;br /&gt;
&lt;br /&gt;
==Дерево элементов==&lt;br /&gt;
* '''root'''(корень): Это самый главный начальный элемент - корень. Все элементы - потомки этого элемента.&lt;br /&gt;
* '''resource'''(ресурсы): Это прямой потомок корня, с одним для каждого запущенным ресурсом(ресурсов может быть множество). Его так же можно назвать ''корень ресурса''. Его ID номер - это название ресурса.&lt;br /&gt;
* '''map'''(карта): Каждый элемент ресурса может содержать по крайней мере один элемент карты - это так называемые &amp;quot;.map&amp;quot; файлы находящиеся в ресурсах. Так же карта может быть создана скриптом - тогда такие карты называются ''динамическими''. Их ID номера содержат название карт, плюс дополнительно ''dynamic'' для динамических карт.&lt;br /&gt;
** Файлы карт могут содержать различное число [[элемент]ов.&lt;br /&gt;
&lt;br /&gt;
==Пример==&lt;br /&gt;
Этот пример для серверной стороны, который сохраняет дамп дерева сервера в XML файл во время его работы.&lt;br /&gt;
''Просим заметить, что в некоторых местах имеются сокращения ради краткости обзора функции.''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;root&amp;gt;&lt;br /&gt;
	&amp;lt;console/&amp;gt;&lt;br /&gt;
	&amp;lt;player dontRespawn=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;player dontRespawn=&amp;quot;false&amp;quot; lastSpawnarea=&amp;quot;&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;resourcebrowser&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;ajax&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;resourcemanager&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;spawnmanager&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;mapmanager&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;runcode&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;fr&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;dynamic&amp;quot;&amp;gt;&lt;br /&gt;
			&amp;lt;vehicle/&amp;gt;&lt;br /&gt;
		&amp;lt;/map&amp;gt;&lt;br /&gt;
	&amp;lt;/resource&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;elementbrowser&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;assault&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;dynamic&amp;quot;&amp;gt;&lt;br /&gt;
			&amp;lt;team/&amp;gt;&lt;br /&gt;
			&amp;lt;team/&amp;gt;&lt;br /&gt;
			&amp;lt;blip/&amp;gt;&lt;br /&gt;
			&amp;lt;marker/&amp;gt;&lt;br /&gt;
			&amp;lt;colshape/&amp;gt;&lt;br /&gt;
			&amp;lt;blip/&amp;gt;&lt;br /&gt;
			&amp;lt;blip/&amp;gt;&lt;br /&gt;
		&amp;lt;/map&amp;gt;&lt;br /&gt;
	&amp;lt;/resource&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;as-farm&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;dynamic&amp;quot;/&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;as-farm.map&amp;quot;&amp;gt;&lt;br /&gt;
			&amp;lt;meta&amp;gt;&lt;br /&gt;
				&amp;lt;author/&amp;gt;&lt;br /&gt;
				&amp;lt;version/&amp;gt;&lt;br /&gt;
				&amp;lt;name/&amp;gt;&lt;br /&gt;
				&amp;lt;description/&amp;gt;&lt;br /&gt;
			&amp;lt;/meta&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;-8.3976354598999&amp;quot; posX=&amp;quot;20.182683944702&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;32.166355133057&amp;quot; posX=&amp;quot;-46.90763092041&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;35.214984893799&amp;quot; posX=&amp;quot;-33.486911773682&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;35.214984893799&amp;quot; posX=&amp;quot;-33.486911773682&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;objective id=&amp;quot;first&amp;quot; type=&amp;quot;checkpoint&amp;quot; description=&amp;quot;Breach into the farm&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;pickup type=&amp;quot;weapon&amp;quot; ... /&amp;gt;&lt;br /&gt;
		&amp;lt;/map&amp;gt;&lt;br /&gt;
	&amp;lt;/resource&amp;gt;&lt;br /&gt;
&amp;lt;/root&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
===Пояснение===&lt;br /&gt;
This tree consists of a number of resource root elements, the [[Element/Console|server console]] and two [[player]] elements, that are direct children of the '''root''' element. All these resources have a ''dynamic map'' as child element (it is just not shown for most of them). These contain the elements that are created dynamically by this resource using scripts, for example a [[vehicle]]. If the resource has a map file, it is also a child element, itself containing all the elements in the .map file.&lt;br /&gt;
&lt;br /&gt;
Let's have a closer look at the '''assault''' resource: This contains just one ''dynamic'' map that has 2 teams, 3 blips, 1 marker and 1 colshape as child elements. These are the elements that are created by the script, for example the marker, the colshape and one of the blips are probably used for the objective.&lt;br /&gt;
&lt;br /&gt;
The '''as-farm''' resource's function on the contrary is to be a map for the '''assault''' gamemode. The dynamic map is empty (it could contain elements if there was a script in it though), while there is a map called 'as-farm.map', that contains a number of elements. These are mostly custom elements (like spawngroup, spawnarea, objective) but also a few elements that MTA creates automactically after loading the map (like pickup). In the brackets after the element type, you can see the element data it contains. These are identical with the attributes the .map file contains within these elements, while you can also set and get element data for any other elements (e.g. players) with [[setElementData]] and [[getElementData]].&lt;br /&gt;
&lt;br /&gt;
==Практическое занятие==&lt;br /&gt;
Elements can have as many children as they like. This does not directly affect the map in any way, but it comes in to its own when combined with the scripting system.&lt;br /&gt;
&lt;br /&gt;
===Настройки для элементов===&lt;br /&gt;
If you call a set... function on a node of the element tree, the function will affect every element within it (that it can work on).&lt;br /&gt;
&lt;br /&gt;
So, the following code would set the size of every marker (the only type of element the setMarkerSize function can work on) that is below the root element to ''2.5''.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
setMarkerSize ( getRootElement(), 2.5 )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same can be done on any element, it is not restricted to the root element.&lt;br /&gt;
&lt;br /&gt;
===Менеджер карт===&lt;br /&gt;
The [[#Example|example above]] shows the way the [[map manager]] uses different resources. The 'assault' resource is the gamemode, that manages what happens on the server using scripts and thus by creating elements in the tree dynamically. When a map resource is started, the gamemode receives a [[resource|resource pointer]] referring to the started resource - in this case ''as-farm'' - from which you can retrieve and store the resource root element. Using this element in conjunction with functions like [[getElementsByType]], [[getElementData]] and various others, you can access any of the information that was loaded into the tree from the 'as-farm.map'-file through scripts in the gamemode resource.&lt;br /&gt;
&lt;br /&gt;
Another thing that has to be considered related to the tree of elements is the fact that when you change the map, you don't have to remove any elements you created within the map resource, while you '''do''' have to remove elements that are created within the gamemode resource, '''if''' they are specific to the map (which will be probably the case for those items you create based on information read from the map resource's .map files).&lt;br /&gt;
&lt;br /&gt;
==Element browser==&lt;br /&gt;
You can start the resource ''elementbrowser'' to see a live view of the element tree on your server. Just start the resource and browser to your server's web page and choose the ''Element browser'' option in the sidebar (firefox only currently).&lt;br /&gt;
[[Category:Scripting Concepts]]&lt;/div&gt;</summary>
		<author><name>WilliJ</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=RU/Element_tree&amp;diff=25836</id>
		<title>RU/Element tree</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=RU/Element_tree&amp;diff=25836"/>
		<updated>2011-05-17T16:54:27Z</updated>

		<summary type="html">&lt;p&gt;WilliJ: /* Пример */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{translate}}&lt;br /&gt;
В MTA используется так называемое ''Дерево элементов'', которое содержит все элементы, расположенные на сервере и клиенте. Это непосредственно связано с расположением работающих [[ресурсов]] и XML файлов карт, хотя может быть изменено во время работы с помощью скриптов.&lt;br /&gt;
&lt;br /&gt;
Если вы знакомы с компьютерным понятием ''Дерево''(ветка, куст и т.д.), то вам будет легче разобраться. Если вы не понимаете, о чем речь, то ''Дерево элементов'' можно представить как ''Семейное дерево'' - в нём каждый человек имеет родителя. Так же и здесь. Каждый [[элемент]](в дальнейшем потомок) имеет своего ''родителя''.&lt;br /&gt;
&lt;br /&gt;
Все элементы, которые созданы внутри скриптов или файлов карт, являются потомками ресурса, которому они принадлежат. По этому, большинство элементов (за исключением [[клиент]]ских) существуют только во время работы ресурсов и перестают работать при остановке этих ресурсов.&lt;br /&gt;
&lt;br /&gt;
==Дерево элементов==&lt;br /&gt;
* '''root'''(корень): Это самый главный начальный элемент - корень. Все элементы - потомки этого элемента.&lt;br /&gt;
* '''resource'''(ресурсы): Это прямой потомок корня, с одним для каждого запущенным ресурсом(ресурсов может быть множество). Его так же можно назвать ''корень ресурса''. Его ID номер - это название ресурса.&lt;br /&gt;
* '''map'''(карта): Каждый элемент ресурса может содержать по крайней мере один элемент карты - это так называемые &amp;quot;.map&amp;quot; файлы находящиеся в ресурсах. Так же карта может быть создана скриптом - тогда такие карты называются ''динамическими''. Их ID номера содержат название карт, плюс дополнительно ''dynamic'' для динамических карт.&lt;br /&gt;
** Файлы карт могут содержать различное число [[элемент]ов.&lt;br /&gt;
&lt;br /&gt;
==Пример==&lt;br /&gt;
Этот пример для серверной стороны, который создает дамп дерева сервера в XML файл во время его работы.&lt;br /&gt;
''Просим заметить, что в некоторых местах имеются сокращения ради краткости обзора функции.''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;root&amp;gt;&lt;br /&gt;
	&amp;lt;console/&amp;gt;&lt;br /&gt;
	&amp;lt;player dontRespawn=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;player dontRespawn=&amp;quot;false&amp;quot; lastSpawnarea=&amp;quot;&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;resourcebrowser&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;ajax&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;resourcemanager&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;spawnmanager&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;mapmanager&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;runcode&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;fr&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;dynamic&amp;quot;&amp;gt;&lt;br /&gt;
			&amp;lt;vehicle/&amp;gt;&lt;br /&gt;
		&amp;lt;/map&amp;gt;&lt;br /&gt;
	&amp;lt;/resource&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;elementbrowser&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;assault&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;dynamic&amp;quot;&amp;gt;&lt;br /&gt;
			&amp;lt;team/&amp;gt;&lt;br /&gt;
			&amp;lt;team/&amp;gt;&lt;br /&gt;
			&amp;lt;blip/&amp;gt;&lt;br /&gt;
			&amp;lt;marker/&amp;gt;&lt;br /&gt;
			&amp;lt;colshape/&amp;gt;&lt;br /&gt;
			&amp;lt;blip/&amp;gt;&lt;br /&gt;
			&amp;lt;blip/&amp;gt;&lt;br /&gt;
		&amp;lt;/map&amp;gt;&lt;br /&gt;
	&amp;lt;/resource&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;as-farm&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;dynamic&amp;quot;/&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;as-farm.map&amp;quot;&amp;gt;&lt;br /&gt;
			&amp;lt;meta&amp;gt;&lt;br /&gt;
				&amp;lt;author/&amp;gt;&lt;br /&gt;
				&amp;lt;version/&amp;gt;&lt;br /&gt;
				&amp;lt;name/&amp;gt;&lt;br /&gt;
				&amp;lt;description/&amp;gt;&lt;br /&gt;
			&amp;lt;/meta&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;-8.3976354598999&amp;quot; posX=&amp;quot;20.182683944702&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;32.166355133057&amp;quot; posX=&amp;quot;-46.90763092041&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;35.214984893799&amp;quot; posX=&amp;quot;-33.486911773682&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;35.214984893799&amp;quot; posX=&amp;quot;-33.486911773682&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;objective id=&amp;quot;first&amp;quot; type=&amp;quot;checkpoint&amp;quot; description=&amp;quot;Breach into the farm&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;pickup type=&amp;quot;weapon&amp;quot; ... /&amp;gt;&lt;br /&gt;
		&amp;lt;/map&amp;gt;&lt;br /&gt;
	&amp;lt;/resource&amp;gt;&lt;br /&gt;
&amp;lt;/root&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
===Пояснение===&lt;br /&gt;
This tree consists of a number of resource root elements, the [[Element/Console|server console]] and two [[player]] elements, that are direct children of the '''root''' element. All these resources have a ''dynamic map'' as child element (it is just not shown for most of them). These contain the elements that are created dynamically by this resource using scripts, for example a [[vehicle]]. If the resource has a map file, it is also a child element, itself containing all the elements in the .map file.&lt;br /&gt;
&lt;br /&gt;
Let's have a closer look at the '''assault''' resource: This contains just one ''dynamic'' map that has 2 teams, 3 blips, 1 marker and 1 colshape as child elements. These are the elements that are created by the script, for example the marker, the colshape and one of the blips are probably used for the objective.&lt;br /&gt;
&lt;br /&gt;
The '''as-farm''' resource's function on the contrary is to be a map for the '''assault''' gamemode. The dynamic map is empty (it could contain elements if there was a script in it though), while there is a map called 'as-farm.map', that contains a number of elements. These are mostly custom elements (like spawngroup, spawnarea, objective) but also a few elements that MTA creates automactically after loading the map (like pickup). In the brackets after the element type, you can see the element data it contains. These are identical with the attributes the .map file contains within these elements, while you can also set and get element data for any other elements (e.g. players) with [[setElementData]] and [[getElementData]].&lt;br /&gt;
&lt;br /&gt;
==Практическое занятие==&lt;br /&gt;
Elements can have as many children as they like. This does not directly affect the map in any way, but it comes in to its own when combined with the scripting system.&lt;br /&gt;
&lt;br /&gt;
===Настройки для элементов===&lt;br /&gt;
If you call a set... function on a node of the element tree, the function will affect every element within it (that it can work on).&lt;br /&gt;
&lt;br /&gt;
So, the following code would set the size of every marker (the only type of element the setMarkerSize function can work on) that is below the root element to ''2.5''.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
setMarkerSize ( getRootElement(), 2.5 )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same can be done on any element, it is not restricted to the root element.&lt;br /&gt;
&lt;br /&gt;
===Менеджер карт===&lt;br /&gt;
The [[#Example|example above]] shows the way the [[map manager]] uses different resources. The 'assault' resource is the gamemode, that manages what happens on the server using scripts and thus by creating elements in the tree dynamically. When a map resource is started, the gamemode receives a [[resource|resource pointer]] referring to the started resource - in this case ''as-farm'' - from which you can retrieve and store the resource root element. Using this element in conjunction with functions like [[getElementsByType]], [[getElementData]] and various others, you can access any of the information that was loaded into the tree from the 'as-farm.map'-file through scripts in the gamemode resource.&lt;br /&gt;
&lt;br /&gt;
Another thing that has to be considered related to the tree of elements is the fact that when you change the map, you don't have to remove any elements you created within the map resource, while you '''do''' have to remove elements that are created within the gamemode resource, '''if''' they are specific to the map (which will be probably the case for those items you create based on information read from the map resource's .map files).&lt;br /&gt;
&lt;br /&gt;
==Element browser==&lt;br /&gt;
You can start the resource ''elementbrowser'' to see a live view of the element tree on your server. Just start the resource and browser to your server's web page and choose the ''Element browser'' option in the sidebar (firefox only currently).&lt;br /&gt;
[[Category:Scripting Concepts]]&lt;/div&gt;</summary>
		<author><name>WilliJ</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=RU/Element_tree&amp;diff=25835</id>
		<title>RU/Element tree</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=RU/Element_tree&amp;diff=25835"/>
		<updated>2011-05-17T16:53:55Z</updated>

		<summary type="html">&lt;p&gt;WilliJ: /* Pratical application */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{translate}}&lt;br /&gt;
В MTA используется так называемое ''Дерево элементов'', которое содержит все элементы, расположенные на сервере и клиенте. Это непосредственно связано с расположением работающих [[ресурсов]] и XML файлов карт, хотя может быть изменено во время работы с помощью скриптов.&lt;br /&gt;
&lt;br /&gt;
Если вы знакомы с компьютерным понятием ''Дерево''(ветка, куст и т.д.), то вам будет легче разобраться. Если вы не понимаете, о чем речь, то ''Дерево элементов'' можно представить как ''Семейное дерево'' - в нём каждый человек имеет родителя. Так же и здесь. Каждый [[элемент]](в дальнейшем потомок) имеет своего ''родителя''.&lt;br /&gt;
&lt;br /&gt;
Все элементы, которые созданы внутри скриптов или файлов карт, являются потомками ресурса, которому они принадлежат. По этому, большинство элементов (за исключением [[клиент]]ских) существуют только во время работы ресурсов и перестают работать при остановке этих ресурсов.&lt;br /&gt;
&lt;br /&gt;
==Дерево элементов==&lt;br /&gt;
* '''root'''(корень): Это самый главный начальный элемент - корень. Все элементы - потомки этого элемента.&lt;br /&gt;
* '''resource'''(ресурсы): Это прямой потомок корня, с одним для каждого запущенным ресурсом(ресурсов может быть множество). Его так же можно назвать ''корень ресурса''. Его ID номер - это название ресурса.&lt;br /&gt;
* '''map'''(карта): Каждый элемент ресурса может содержать по крайней мере один элемент карты - это так называемые &amp;quot;.map&amp;quot; файлы находящиеся в ресурсах. Так же карта может быть создана скриптом - тогда такие карты называются ''динамическими''. Их ID номера содержат название карт, плюс дополнительно ''dynamic'' для динамических карт.&lt;br /&gt;
** Файлы карт могут содержать различное число [[элемент]ов.&lt;br /&gt;
&lt;br /&gt;
==Пример==&lt;br /&gt;
Этот пример для серверной стороны, который делает дамп дерева сервера в XML файл во время его работы.&lt;br /&gt;
''Просим заметить, что в некоторых местах имеются сокращения ради краткости обзора функции.''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;root&amp;gt;&lt;br /&gt;
	&amp;lt;console/&amp;gt;&lt;br /&gt;
	&amp;lt;player dontRespawn=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;player dontRespawn=&amp;quot;false&amp;quot; lastSpawnarea=&amp;quot;&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;resourcebrowser&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;ajax&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;resourcemanager&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;spawnmanager&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;mapmanager&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;runcode&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;fr&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;dynamic&amp;quot;&amp;gt;&lt;br /&gt;
			&amp;lt;vehicle/&amp;gt;&lt;br /&gt;
		&amp;lt;/map&amp;gt;&lt;br /&gt;
	&amp;lt;/resource&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;elementbrowser&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;assault&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;dynamic&amp;quot;&amp;gt;&lt;br /&gt;
			&amp;lt;team/&amp;gt;&lt;br /&gt;
			&amp;lt;team/&amp;gt;&lt;br /&gt;
			&amp;lt;blip/&amp;gt;&lt;br /&gt;
			&amp;lt;marker/&amp;gt;&lt;br /&gt;
			&amp;lt;colshape/&amp;gt;&lt;br /&gt;
			&amp;lt;blip/&amp;gt;&lt;br /&gt;
			&amp;lt;blip/&amp;gt;&lt;br /&gt;
		&amp;lt;/map&amp;gt;&lt;br /&gt;
	&amp;lt;/resource&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;as-farm&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;dynamic&amp;quot;/&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;as-farm.map&amp;quot;&amp;gt;&lt;br /&gt;
			&amp;lt;meta&amp;gt;&lt;br /&gt;
				&amp;lt;author/&amp;gt;&lt;br /&gt;
				&amp;lt;version/&amp;gt;&lt;br /&gt;
				&amp;lt;name/&amp;gt;&lt;br /&gt;
				&amp;lt;description/&amp;gt;&lt;br /&gt;
			&amp;lt;/meta&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;-8.3976354598999&amp;quot; posX=&amp;quot;20.182683944702&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;32.166355133057&amp;quot; posX=&amp;quot;-46.90763092041&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;35.214984893799&amp;quot; posX=&amp;quot;-33.486911773682&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;35.214984893799&amp;quot; posX=&amp;quot;-33.486911773682&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;objective id=&amp;quot;first&amp;quot; type=&amp;quot;checkpoint&amp;quot; description=&amp;quot;Breach into the farm&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;pickup type=&amp;quot;weapon&amp;quot; ... /&amp;gt;&lt;br /&gt;
		&amp;lt;/map&amp;gt;&lt;br /&gt;
	&amp;lt;/resource&amp;gt;&lt;br /&gt;
&amp;lt;/root&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
===Пояснение===&lt;br /&gt;
This tree consists of a number of resource root elements, the [[Element/Console|server console]] and two [[player]] elements, that are direct children of the '''root''' element. All these resources have a ''dynamic map'' as child element (it is just not shown for most of them). These contain the elements that are created dynamically by this resource using scripts, for example a [[vehicle]]. If the resource has a map file, it is also a child element, itself containing all the elements in the .map file.&lt;br /&gt;
&lt;br /&gt;
Let's have a closer look at the '''assault''' resource: This contains just one ''dynamic'' map that has 2 teams, 3 blips, 1 marker and 1 colshape as child elements. These are the elements that are created by the script, for example the marker, the colshape and one of the blips are probably used for the objective.&lt;br /&gt;
&lt;br /&gt;
The '''as-farm''' resource's function on the contrary is to be a map for the '''assault''' gamemode. The dynamic map is empty (it could contain elements if there was a script in it though), while there is a map called 'as-farm.map', that contains a number of elements. These are mostly custom elements (like spawngroup, spawnarea, objective) but also a few elements that MTA creates automactically after loading the map (like pickup). In the brackets after the element type, you can see the element data it contains. These are identical with the attributes the .map file contains within these elements, while you can also set and get element data for any other elements (e.g. players) with [[setElementData]] and [[getElementData]].&lt;br /&gt;
&lt;br /&gt;
==Практическое занятие==&lt;br /&gt;
Elements can have as many children as they like. This does not directly affect the map in any way, but it comes in to its own when combined with the scripting system.&lt;br /&gt;
&lt;br /&gt;
===Настройки для элементов===&lt;br /&gt;
If you call a set... function on a node of the element tree, the function will affect every element within it (that it can work on).&lt;br /&gt;
&lt;br /&gt;
So, the following code would set the size of every marker (the only type of element the setMarkerSize function can work on) that is below the root element to ''2.5''.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
setMarkerSize ( getRootElement(), 2.5 )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same can be done on any element, it is not restricted to the root element.&lt;br /&gt;
&lt;br /&gt;
===Менеджер карт===&lt;br /&gt;
The [[#Example|example above]] shows the way the [[map manager]] uses different resources. The 'assault' resource is the gamemode, that manages what happens on the server using scripts and thus by creating elements in the tree dynamically. When a map resource is started, the gamemode receives a [[resource|resource pointer]] referring to the started resource - in this case ''as-farm'' - from which you can retrieve and store the resource root element. Using this element in conjunction with functions like [[getElementsByType]], [[getElementData]] and various others, you can access any of the information that was loaded into the tree from the 'as-farm.map'-file through scripts in the gamemode resource.&lt;br /&gt;
&lt;br /&gt;
Another thing that has to be considered related to the tree of elements is the fact that when you change the map, you don't have to remove any elements you created within the map resource, while you '''do''' have to remove elements that are created within the gamemode resource, '''if''' they are specific to the map (which will be probably the case for those items you create based on information read from the map resource's .map files).&lt;br /&gt;
&lt;br /&gt;
==Element browser==&lt;br /&gt;
You can start the resource ''elementbrowser'' to see a live view of the element tree on your server. Just start the resource and browser to your server's web page and choose the ''Element browser'' option in the sidebar (firefox only currently).&lt;br /&gt;
[[Category:Scripting Concepts]]&lt;/div&gt;</summary>
		<author><name>WilliJ</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=RU/Element_tree&amp;diff=25834</id>
		<title>RU/Element tree</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=RU/Element_tree&amp;diff=25834"/>
		<updated>2011-05-17T16:50:42Z</updated>

		<summary type="html">&lt;p&gt;WilliJ: /* Дерево элементов */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{translate}}&lt;br /&gt;
В MTA используется так называемое ''Дерево элементов'', которое содержит все элементы, расположенные на сервере и клиенте. Это непосредственно связано с расположением работающих [[ресурсов]] и XML файлов карт, хотя может быть изменено во время работы с помощью скриптов.&lt;br /&gt;
&lt;br /&gt;
Если вы знакомы с компьютерным понятием ''Дерево''(ветка, куст и т.д.), то вам будет легче разобраться. Если вы не понимаете, о чем речь, то ''Дерево элементов'' можно представить как ''Семейное дерево'' - в нём каждый человек имеет родителя. Так же и здесь. Каждый [[элемент]](в дальнейшем потомок) имеет своего ''родителя''.&lt;br /&gt;
&lt;br /&gt;
Все элементы, которые созданы внутри скриптов или файлов карт, являются потомками ресурса, которому они принадлежат. По этому, большинство элементов (за исключением [[клиент]]ских) существуют только во время работы ресурсов и перестают работать при остановке этих ресурсов.&lt;br /&gt;
&lt;br /&gt;
==Дерево элементов==&lt;br /&gt;
* '''root'''(корень): Это самый главный начальный элемент - корень. Все элементы - потомки этого элемента.&lt;br /&gt;
* '''resource'''(ресурсы): Это прямой потомок корня, с одним для каждого запущенным ресурсом(ресурсов может быть множество). Его так же можно назвать ''корень ресурса''. Его ID номер - это название ресурса.&lt;br /&gt;
* '''map'''(карта): Каждый элемент ресурса может содержать по крайней мере один элемент карты - это так называемые &amp;quot;.map&amp;quot; файлы находящиеся в ресурсах. Так же карта может быть создана скриптом - тогда такие карты называются ''динамическими''. Их ID номера содержат название карт, плюс дополнительно ''dynamic'' для динамических карт.&lt;br /&gt;
** Файлы карт могут содержать различное число [[элемент]ов.&lt;br /&gt;
&lt;br /&gt;
==Пример==&lt;br /&gt;
Этот пример для серверной стороны, который делает дамп дерева сервера в XML файл во время его работы.&lt;br /&gt;
''Просим заметить, что в некоторых местах имеются сокращения ради краткости обзора функции.''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;root&amp;gt;&lt;br /&gt;
	&amp;lt;console/&amp;gt;&lt;br /&gt;
	&amp;lt;player dontRespawn=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;player dontRespawn=&amp;quot;false&amp;quot; lastSpawnarea=&amp;quot;&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;resourcebrowser&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;ajax&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;resourcemanager&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;spawnmanager&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;mapmanager&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;runcode&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;fr&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;dynamic&amp;quot;&amp;gt;&lt;br /&gt;
			&amp;lt;vehicle/&amp;gt;&lt;br /&gt;
		&amp;lt;/map&amp;gt;&lt;br /&gt;
	&amp;lt;/resource&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;elementbrowser&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;assault&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;dynamic&amp;quot;&amp;gt;&lt;br /&gt;
			&amp;lt;team/&amp;gt;&lt;br /&gt;
			&amp;lt;team/&amp;gt;&lt;br /&gt;
			&amp;lt;blip/&amp;gt;&lt;br /&gt;
			&amp;lt;marker/&amp;gt;&lt;br /&gt;
			&amp;lt;colshape/&amp;gt;&lt;br /&gt;
			&amp;lt;blip/&amp;gt;&lt;br /&gt;
			&amp;lt;blip/&amp;gt;&lt;br /&gt;
		&amp;lt;/map&amp;gt;&lt;br /&gt;
	&amp;lt;/resource&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;as-farm&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;dynamic&amp;quot;/&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;as-farm.map&amp;quot;&amp;gt;&lt;br /&gt;
			&amp;lt;meta&amp;gt;&lt;br /&gt;
				&amp;lt;author/&amp;gt;&lt;br /&gt;
				&amp;lt;version/&amp;gt;&lt;br /&gt;
				&amp;lt;name/&amp;gt;&lt;br /&gt;
				&amp;lt;description/&amp;gt;&lt;br /&gt;
			&amp;lt;/meta&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;-8.3976354598999&amp;quot; posX=&amp;quot;20.182683944702&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;32.166355133057&amp;quot; posX=&amp;quot;-46.90763092041&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;35.214984893799&amp;quot; posX=&amp;quot;-33.486911773682&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;35.214984893799&amp;quot; posX=&amp;quot;-33.486911773682&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;objective id=&amp;quot;first&amp;quot; type=&amp;quot;checkpoint&amp;quot; description=&amp;quot;Breach into the farm&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;pickup type=&amp;quot;weapon&amp;quot; ... /&amp;gt;&lt;br /&gt;
		&amp;lt;/map&amp;gt;&lt;br /&gt;
	&amp;lt;/resource&amp;gt;&lt;br /&gt;
&amp;lt;/root&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
===Пояснение===&lt;br /&gt;
This tree consists of a number of resource root elements, the [[Element/Console|server console]] and two [[player]] elements, that are direct children of the '''root''' element. All these resources have a ''dynamic map'' as child element (it is just not shown for most of them). These contain the elements that are created dynamically by this resource using scripts, for example a [[vehicle]]. If the resource has a map file, it is also a child element, itself containing all the elements in the .map file.&lt;br /&gt;
&lt;br /&gt;
Let's have a closer look at the '''assault''' resource: This contains just one ''dynamic'' map that has 2 teams, 3 blips, 1 marker and 1 colshape as child elements. These are the elements that are created by the script, for example the marker, the colshape and one of the blips are probably used for the objective.&lt;br /&gt;
&lt;br /&gt;
The '''as-farm''' resource's function on the contrary is to be a map for the '''assault''' gamemode. The dynamic map is empty (it could contain elements if there was a script in it though), while there is a map called 'as-farm.map', that contains a number of elements. These are mostly custom elements (like spawngroup, spawnarea, objective) but also a few elements that MTA creates automactically after loading the map (like pickup). In the brackets after the element type, you can see the element data it contains. These are identical with the attributes the .map file contains within these elements, while you can also set and get element data for any other elements (e.g. players) with [[setElementData]] and [[getElementData]].&lt;br /&gt;
&lt;br /&gt;
==Pratical application==&lt;br /&gt;
Elements can have as many children as they like. This does not directly affect the map in any way, but it comes in to its own when combined with the scripting system.&lt;br /&gt;
&lt;br /&gt;
===Setting data for elements===&lt;br /&gt;
If you call a set... function on a node of the element tree, the function will affect every element within it (that it can work on).&lt;br /&gt;
&lt;br /&gt;
So, the following code would set the size of every marker (the only type of element the setMarkerSize function can work on) that is below the root element to ''2.5''.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
setMarkerSize ( getRootElement(), 2.5 )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same can be done on any element, it is not restricted to the root element.&lt;br /&gt;
&lt;br /&gt;
===Менеджер карт===&lt;br /&gt;
The [[#Example|example above]] shows the way the [[map manager]] uses different resources. The 'assault' resource is the gamemode, that manages what happens on the server using scripts and thus by creating elements in the tree dynamically. When a map resource is started, the gamemode receives a [[resource|resource pointer]] referring to the started resource - in this case ''as-farm'' - from which you can retrieve and store the resource root element. Using this element in conjunction with functions like [[getElementsByType]], [[getElementData]] and various others, you can access any of the information that was loaded into the tree from the 'as-farm.map'-file through scripts in the gamemode resource.&lt;br /&gt;
&lt;br /&gt;
Another thing that has to be considered related to the tree of elements is the fact that when you change the map, you don't have to remove any elements you created within the map resource, while you '''do''' have to remove elements that are created within the gamemode resource, '''if''' they are specific to the map (which will be probably the case for those items you create based on information read from the map resource's .map files).&lt;br /&gt;
&lt;br /&gt;
==Element browser==&lt;br /&gt;
You can start the resource ''elementbrowser'' to see a live view of the element tree on your server. Just start the resource and browser to your server's web page and choose the ''Element browser'' option in the sidebar (firefox only currently).&lt;br /&gt;
[[Category:Scripting Concepts]]&lt;/div&gt;</summary>
		<author><name>WilliJ</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=RU/Element_tree&amp;diff=25833</id>
		<title>RU/Element tree</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=RU/Element_tree&amp;diff=25833"/>
		<updated>2011-05-17T16:47:52Z</updated>

		<summary type="html">&lt;p&gt;WilliJ: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{translate}}&lt;br /&gt;
В MTA используется так называемое ''Дерево элементов'', которое содержит все элементы, расположенные на сервере и клиенте. Это непосредственно связано с расположением работающих [[ресурсов]] и XML файлов карт, хотя может быть изменено во время работы с помощью скриптов.&lt;br /&gt;
&lt;br /&gt;
Если вы знакомы с компьютерным понятием ''Дерево''(ветка, куст и т.д.), то вам будет легче разобраться. Если вы не понимаете, о чем речь, то ''Дерево элементов'' можно представить как ''Семейное дерево'' - в нём каждый человек имеет родителя. Так же и здесь. Каждый [[элемент]](в дальнейшем потомок) имеет своего ''родителя''.&lt;br /&gt;
&lt;br /&gt;
Все элементы, которые созданы внутри скриптов или файлов карт, являются потомками ресурса, которому они принадлежат. По этому, большинство элементов (за исключением [[клиент]]ских) существуют только во время работы ресурсов и перестают работать при остановке этих ресурсов.&lt;br /&gt;
&lt;br /&gt;
==Дерево элементов==&lt;br /&gt;
* '''root'''(корень): Это самый главный начальный элемент - корень. Все элементы - потомки этого элемента.&lt;br /&gt;
* '''resource'''(ресурсы): Это прямой потомок корня, с одним для каждого запущенным ресурсом(ресурсов может быть множество). Его так же можно назвать ''корень ресурса''. Его ID номер - это название ресурса.&lt;br /&gt;
* '''map'''(карта): Каждый элемент ресурса может содержать по крайней мере один элемент карты - это так называемые &amp;quot;.map&amp;quot; файлы в ресурсах или же карта может быть создана скриптом - тогда такие карты называются ''динамическими''. Их ID номера содержат название карт, или дополнительно ''dynamic'' для динамических карт.&lt;br /&gt;
** Файлы карт могут содержать различное число [[элемент]ов.&lt;br /&gt;
&lt;br /&gt;
==Пример==&lt;br /&gt;
Этот пример для серверной стороны, который делает дамп дерева сервера в XML файл во время его работы.&lt;br /&gt;
''Просим заметить, что в некоторых местах имеются сокращения ради краткости обзора функции.''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;root&amp;gt;&lt;br /&gt;
	&amp;lt;console/&amp;gt;&lt;br /&gt;
	&amp;lt;player dontRespawn=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;player dontRespawn=&amp;quot;false&amp;quot; lastSpawnarea=&amp;quot;&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;resourcebrowser&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;ajax&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;resourcemanager&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;spawnmanager&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;mapmanager&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;runcode&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;fr&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;dynamic&amp;quot;&amp;gt;&lt;br /&gt;
			&amp;lt;vehicle/&amp;gt;&lt;br /&gt;
		&amp;lt;/map&amp;gt;&lt;br /&gt;
	&amp;lt;/resource&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;elementbrowser&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;assault&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;dynamic&amp;quot;&amp;gt;&lt;br /&gt;
			&amp;lt;team/&amp;gt;&lt;br /&gt;
			&amp;lt;team/&amp;gt;&lt;br /&gt;
			&amp;lt;blip/&amp;gt;&lt;br /&gt;
			&amp;lt;marker/&amp;gt;&lt;br /&gt;
			&amp;lt;colshape/&amp;gt;&lt;br /&gt;
			&amp;lt;blip/&amp;gt;&lt;br /&gt;
			&amp;lt;blip/&amp;gt;&lt;br /&gt;
		&amp;lt;/map&amp;gt;&lt;br /&gt;
	&amp;lt;/resource&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;as-farm&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;dynamic&amp;quot;/&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;as-farm.map&amp;quot;&amp;gt;&lt;br /&gt;
			&amp;lt;meta&amp;gt;&lt;br /&gt;
				&amp;lt;author/&amp;gt;&lt;br /&gt;
				&amp;lt;version/&amp;gt;&lt;br /&gt;
				&amp;lt;name/&amp;gt;&lt;br /&gt;
				&amp;lt;description/&amp;gt;&lt;br /&gt;
			&amp;lt;/meta&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;-8.3976354598999&amp;quot; posX=&amp;quot;20.182683944702&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;32.166355133057&amp;quot; posX=&amp;quot;-46.90763092041&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;35.214984893799&amp;quot; posX=&amp;quot;-33.486911773682&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;35.214984893799&amp;quot; posX=&amp;quot;-33.486911773682&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;objective id=&amp;quot;first&amp;quot; type=&amp;quot;checkpoint&amp;quot; description=&amp;quot;Breach into the farm&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;pickup type=&amp;quot;weapon&amp;quot; ... /&amp;gt;&lt;br /&gt;
		&amp;lt;/map&amp;gt;&lt;br /&gt;
	&amp;lt;/resource&amp;gt;&lt;br /&gt;
&amp;lt;/root&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
===Пояснение===&lt;br /&gt;
This tree consists of a number of resource root elements, the [[Element/Console|server console]] and two [[player]] elements, that are direct children of the '''root''' element. All these resources have a ''dynamic map'' as child element (it is just not shown for most of them). These contain the elements that are created dynamically by this resource using scripts, for example a [[vehicle]]. If the resource has a map file, it is also a child element, itself containing all the elements in the .map file.&lt;br /&gt;
&lt;br /&gt;
Let's have a closer look at the '''assault''' resource: This contains just one ''dynamic'' map that has 2 teams, 3 blips, 1 marker and 1 colshape as child elements. These are the elements that are created by the script, for example the marker, the colshape and one of the blips are probably used for the objective.&lt;br /&gt;
&lt;br /&gt;
The '''as-farm''' resource's function on the contrary is to be a map for the '''assault''' gamemode. The dynamic map is empty (it could contain elements if there was a script in it though), while there is a map called 'as-farm.map', that contains a number of elements. These are mostly custom elements (like spawngroup, spawnarea, objective) but also a few elements that MTA creates automactically after loading the map (like pickup). In the brackets after the element type, you can see the element data it contains. These are identical with the attributes the .map file contains within these elements, while you can also set and get element data for any other elements (e.g. players) with [[setElementData]] and [[getElementData]].&lt;br /&gt;
&lt;br /&gt;
==Pratical application==&lt;br /&gt;
Elements can have as many children as they like. This does not directly affect the map in any way, but it comes in to its own when combined with the scripting system.&lt;br /&gt;
&lt;br /&gt;
===Setting data for elements===&lt;br /&gt;
If you call a set... function on a node of the element tree, the function will affect every element within it (that it can work on).&lt;br /&gt;
&lt;br /&gt;
So, the following code would set the size of every marker (the only type of element the setMarkerSize function can work on) that is below the root element to ''2.5''.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
setMarkerSize ( getRootElement(), 2.5 )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same can be done on any element, it is not restricted to the root element.&lt;br /&gt;
&lt;br /&gt;
===Менеджер карт===&lt;br /&gt;
The [[#Example|example above]] shows the way the [[map manager]] uses different resources. The 'assault' resource is the gamemode, that manages what happens on the server using scripts and thus by creating elements in the tree dynamically. When a map resource is started, the gamemode receives a [[resource|resource pointer]] referring to the started resource - in this case ''as-farm'' - from which you can retrieve and store the resource root element. Using this element in conjunction with functions like [[getElementsByType]], [[getElementData]] and various others, you can access any of the information that was loaded into the tree from the 'as-farm.map'-file through scripts in the gamemode resource.&lt;br /&gt;
&lt;br /&gt;
Another thing that has to be considered related to the tree of elements is the fact that when you change the map, you don't have to remove any elements you created within the map resource, while you '''do''' have to remove elements that are created within the gamemode resource, '''if''' they are specific to the map (which will be probably the case for those items you create based on information read from the map resource's .map files).&lt;br /&gt;
&lt;br /&gt;
==Element browser==&lt;br /&gt;
You can start the resource ''elementbrowser'' to see a live view of the element tree on your server. Just start the resource and browser to your server's web page and choose the ''Element browser'' option in the sidebar (firefox only currently).&lt;br /&gt;
[[Category:Scripting Concepts]]&lt;/div&gt;</summary>
		<author><name>WilliJ</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=RU/Element_tree&amp;diff=25832</id>
		<title>RU/Element tree</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=RU/Element_tree&amp;diff=25832"/>
		<updated>2011-05-17T16:47:22Z</updated>

		<summary type="html">&lt;p&gt;WilliJ: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{translate}}&lt;br /&gt;
В MTA используется так называемое ''Дерево элементов'', которое содержит все элементы, расположенные на сервере и клиенте. Это непосредственно связано с расположением работающих [[ресурсов]] и XML файлов карт, хотя может быть изменено во время работы с помощью скриптов.&lt;br /&gt;
&lt;br /&gt;
Если вы знакомы с компьютерным понятием ''Дерево''(ветка, куст и т.д.), то вам будет легче разобраться. Если вы не понимаете, о чем речь, то ''Дерево элементов'' можно представить как ''Семейное дерево'' - в нём каждый человек имеет родителя. Так же и здесь. Каждый [[элемент]](в дальнейшем потомок) имеет своего ''родителя''.&lt;br /&gt;
&lt;br /&gt;
Все элементы, которые созданы внутри скриптов или файлов карт, являются потомками ресурса, которому они принадлежат. По этому, большинство элементов (за исключением [[клиент]]ских) существуют только во время работы ресурсов и перестают работать при остановке этих ресурсов.&lt;br /&gt;
&lt;br /&gt;
==Дерево элементов==&lt;br /&gt;
* '''root'''(корень): Это самый главный начальный элемент - корень. Все элементы - потомки этого элемента.&lt;br /&gt;
* '''resource'''(ресурсы): Это прямой потомок корня, с одним для каждого запущенным ресурсом(ресурсов может быть множество). Его так же можно назвать ''корень ресурса''. Его ID номер - это название ресурса.&lt;br /&gt;
* '''map'''(карта): Каждый элемент ресурса может содержать по крайней мере один элемент карты - это так называемые &amp;quot;.map&amp;quot; файлы в ресурсах или же карта может быть создана скриптом - тогда такие карты называются ''динамическая''кими. Их ID номера содержат название карт, или дополнительно ''dynamic'' для динамических карт.&lt;br /&gt;
** Файлы карт могут содержать различное число [[элемент]ов.&lt;br /&gt;
&lt;br /&gt;
==Пример==&lt;br /&gt;
Этот пример для серверной стороны, который делает дамп дерева сервера в XML файл во время его работы.&lt;br /&gt;
''Просим заметить, что в некоторых местах имеются сокращения ради краткости обзора функции.''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;root&amp;gt;&lt;br /&gt;
	&amp;lt;console/&amp;gt;&lt;br /&gt;
	&amp;lt;player dontRespawn=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;player dontRespawn=&amp;quot;false&amp;quot; lastSpawnarea=&amp;quot;&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;resourcebrowser&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;ajax&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;resourcemanager&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;spawnmanager&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;mapmanager&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;runcode&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;fr&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;dynamic&amp;quot;&amp;gt;&lt;br /&gt;
			&amp;lt;vehicle/&amp;gt;&lt;br /&gt;
		&amp;lt;/map&amp;gt;&lt;br /&gt;
	&amp;lt;/resource&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;elementbrowser&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;assault&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;dynamic&amp;quot;&amp;gt;&lt;br /&gt;
			&amp;lt;team/&amp;gt;&lt;br /&gt;
			&amp;lt;team/&amp;gt;&lt;br /&gt;
			&amp;lt;blip/&amp;gt;&lt;br /&gt;
			&amp;lt;marker/&amp;gt;&lt;br /&gt;
			&amp;lt;colshape/&amp;gt;&lt;br /&gt;
			&amp;lt;blip/&amp;gt;&lt;br /&gt;
			&amp;lt;blip/&amp;gt;&lt;br /&gt;
		&amp;lt;/map&amp;gt;&lt;br /&gt;
	&amp;lt;/resource&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;as-farm&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;dynamic&amp;quot;/&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;as-farm.map&amp;quot;&amp;gt;&lt;br /&gt;
			&amp;lt;meta&amp;gt;&lt;br /&gt;
				&amp;lt;author/&amp;gt;&lt;br /&gt;
				&amp;lt;version/&amp;gt;&lt;br /&gt;
				&amp;lt;name/&amp;gt;&lt;br /&gt;
				&amp;lt;description/&amp;gt;&lt;br /&gt;
			&amp;lt;/meta&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;-8.3976354598999&amp;quot; posX=&amp;quot;20.182683944702&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;32.166355133057&amp;quot; posX=&amp;quot;-46.90763092041&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;35.214984893799&amp;quot; posX=&amp;quot;-33.486911773682&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;35.214984893799&amp;quot; posX=&amp;quot;-33.486911773682&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;objective id=&amp;quot;first&amp;quot; type=&amp;quot;checkpoint&amp;quot; description=&amp;quot;Breach into the farm&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;pickup type=&amp;quot;weapon&amp;quot; ... /&amp;gt;&lt;br /&gt;
		&amp;lt;/map&amp;gt;&lt;br /&gt;
	&amp;lt;/resource&amp;gt;&lt;br /&gt;
&amp;lt;/root&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
===Пояснение===&lt;br /&gt;
This tree consists of a number of resource root elements, the [[Element/Console|server console]] and two [[player]] elements, that are direct children of the '''root''' element. All these resources have a ''dynamic map'' as child element (it is just not shown for most of them). These contain the elements that are created dynamically by this resource using scripts, for example a [[vehicle]]. If the resource has a map file, it is also a child element, itself containing all the elements in the .map file.&lt;br /&gt;
&lt;br /&gt;
Let's have a closer look at the '''assault''' resource: This contains just one ''dynamic'' map that has 2 teams, 3 blips, 1 marker and 1 colshape as child elements. These are the elements that are created by the script, for example the marker, the colshape and one of the blips are probably used for the objective.&lt;br /&gt;
&lt;br /&gt;
The '''as-farm''' resource's function on the contrary is to be a map for the '''assault''' gamemode. The dynamic map is empty (it could contain elements if there was a script in it though), while there is a map called 'as-farm.map', that contains a number of elements. These are mostly custom elements (like spawngroup, spawnarea, objective) but also a few elements that MTA creates automactically after loading the map (like pickup). In the brackets after the element type, you can see the element data it contains. These are identical with the attributes the .map file contains within these elements, while you can also set and get element data for any other elements (e.g. players) with [[setElementData]] and [[getElementData]].&lt;br /&gt;
&lt;br /&gt;
==Pratical application==&lt;br /&gt;
Elements can have as many children as they like. This does not directly affect the map in any way, but it comes in to its own when combined with the scripting system.&lt;br /&gt;
&lt;br /&gt;
===Setting data for elements===&lt;br /&gt;
If you call a set... function on a node of the element tree, the function will affect every element within it (that it can work on).&lt;br /&gt;
&lt;br /&gt;
So, the following code would set the size of every marker (the only type of element the setMarkerSize function can work on) that is below the root element to ''2.5''.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
setMarkerSize ( getRootElement(), 2.5 )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same can be done on any element, it is not restricted to the root element.&lt;br /&gt;
&lt;br /&gt;
===Менеджер карт===&lt;br /&gt;
The [[#Example|example above]] shows the way the [[map manager]] uses different resources. The 'assault' resource is the gamemode, that manages what happens on the server using scripts and thus by creating elements in the tree dynamically. When a map resource is started, the gamemode receives a [[resource|resource pointer]] referring to the started resource - in this case ''as-farm'' - from which you can retrieve and store the resource root element. Using this element in conjunction with functions like [[getElementsByType]], [[getElementData]] and various others, you can access any of the information that was loaded into the tree from the 'as-farm.map'-file through scripts in the gamemode resource.&lt;br /&gt;
&lt;br /&gt;
Another thing that has to be considered related to the tree of elements is the fact that when you change the map, you don't have to remove any elements you created within the map resource, while you '''do''' have to remove elements that are created within the gamemode resource, '''if''' they are specific to the map (which will be probably the case for those items you create based on information read from the map resource's .map files).&lt;br /&gt;
&lt;br /&gt;
==Element browser==&lt;br /&gt;
You can start the resource ''elementbrowser'' to see a live view of the element tree on your server. Just start the resource and browser to your server's web page and choose the ''Element browser'' option in the sidebar (firefox only currently).&lt;br /&gt;
[[Category:Scripting Concepts]]&lt;/div&gt;</summary>
		<author><name>WilliJ</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=RU/Element_tree&amp;diff=25831</id>
		<title>RU/Element tree</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=RU/Element_tree&amp;diff=25831"/>
		<updated>2011-05-17T16:26:50Z</updated>

		<summary type="html">&lt;p&gt;WilliJ: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{translate}}&lt;br /&gt;
В MTA используется так называемое ''Дерево элементов'', которое содержит все элементы, расположенные на сервере и клиенте. ИThis is directly related to the set of running [[resources]] and their map files' XML layout, although it can be changed at run-time by scripts.&lt;br /&gt;
&lt;br /&gt;
Если вы знакомы с компьютерным понятием ''Дерево''(ветка, куст и т.д.), то вам будет легче разобраться. Если вы не понимаете, о чем речь, то ''Дерево элементов'' можно представить как ''Семейное дерево'' - в нём каждый человек имеет родителя. Так же и здесь. Каждый [[элемент]] имеет своего ''родителя''.&lt;br /&gt;
&lt;br /&gt;
Все элементы, которые созданы внутри скриптов или файлов карт, являются потомками ресурса, которому они пренадлежат. По этому, большинство элементов (за исключением [[клиент]]ских) существуют только во время работы ресурсов и перестают работать при остановке этих ресурсов.&lt;br /&gt;
&lt;br /&gt;
==Дерево элементов==&lt;br /&gt;
* '''root'''(корень): Это самый главный начальный элемент - корень. Все элементы - потомки этого элемента.&lt;br /&gt;
* '''resource'''(ресурсы): Это прямой потомок корня, с одним для каждого запущенным ресурсом. Его так же можно назвать ''корень ресурсов''. Its ID holds the name of the resource.&lt;br /&gt;
* '''map'''(карта): Каждый элемент ресурса содержит по крайней мере один элемент карты - это так называемые &amp;quot;.map&amp;quot; файлы в ресурсах or the one containing the elements created by scripts (this is called the ''dynamic'' map). Their IDs contain the maps' filenames, or ''dynamic'' for the dynamic map.&lt;br /&gt;
** Файлы карт могут содержать Map files can contain a number of other [[element]]s as well as an unlimited number of custom elements.&lt;br /&gt;
&lt;br /&gt;
==Пример==&lt;br /&gt;
Этот пример для серверной стороны, который делает дамп дерева сервера в XML файл во время его работы.&lt;br /&gt;
''Просим заметить, что в некоторых местах имеются сокращения ради краткости обзора функции.''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;root&amp;gt;&lt;br /&gt;
	&amp;lt;console/&amp;gt;&lt;br /&gt;
	&amp;lt;player dontRespawn=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;player dontRespawn=&amp;quot;false&amp;quot; lastSpawnarea=&amp;quot;&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;resourcebrowser&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;ajax&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;resourcemanager&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;spawnmanager&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;mapmanager&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;runcode&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;fr&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;dynamic&amp;quot;&amp;gt;&lt;br /&gt;
			&amp;lt;vehicle/&amp;gt;&lt;br /&gt;
		&amp;lt;/map&amp;gt;&lt;br /&gt;
	&amp;lt;/resource&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;elementbrowser&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;assault&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;dynamic&amp;quot;&amp;gt;&lt;br /&gt;
			&amp;lt;team/&amp;gt;&lt;br /&gt;
			&amp;lt;team/&amp;gt;&lt;br /&gt;
			&amp;lt;blip/&amp;gt;&lt;br /&gt;
			&amp;lt;marker/&amp;gt;&lt;br /&gt;
			&amp;lt;colshape/&amp;gt;&lt;br /&gt;
			&amp;lt;blip/&amp;gt;&lt;br /&gt;
			&amp;lt;blip/&amp;gt;&lt;br /&gt;
		&amp;lt;/map&amp;gt;&lt;br /&gt;
	&amp;lt;/resource&amp;gt;&lt;br /&gt;
	&amp;lt;resource id=&amp;quot;as-farm&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;dynamic&amp;quot;/&amp;gt;&lt;br /&gt;
		&amp;lt;map id=&amp;quot;as-farm.map&amp;quot;&amp;gt;&lt;br /&gt;
			&amp;lt;meta&amp;gt;&lt;br /&gt;
				&amp;lt;author/&amp;gt;&lt;br /&gt;
				&amp;lt;version/&amp;gt;&lt;br /&gt;
				&amp;lt;name/&amp;gt;&lt;br /&gt;
				&amp;lt;description/&amp;gt;&lt;br /&gt;
			&amp;lt;/meta&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;-8.3976354598999&amp;quot; posX=&amp;quot;20.182683944702&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;32.166355133057&amp;quot; posX=&amp;quot;-46.90763092041&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;35.214984893799&amp;quot; posX=&amp;quot;-33.486911773682&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;spawngroup req=&amp;quot;&amp;quot; type=&amp;quot;attacker&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;spawnarea posY=&amp;quot;35.214984893799&amp;quot; posX=&amp;quot;-33.486911773682&amp;quot; skins=&amp;quot;9&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;/spawngroup&amp;gt;&lt;br /&gt;
			&amp;lt;objective id=&amp;quot;first&amp;quot; type=&amp;quot;checkpoint&amp;quot; description=&amp;quot;Breach into the farm&amp;quot; ... /&amp;gt;&lt;br /&gt;
			&amp;lt;pickup type=&amp;quot;weapon&amp;quot; ... /&amp;gt;&lt;br /&gt;
		&amp;lt;/map&amp;gt;&lt;br /&gt;
	&amp;lt;/resource&amp;gt;&lt;br /&gt;
&amp;lt;/root&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
===Пояснение===&lt;br /&gt;
This tree consists of a number of resource root elements, the [[Element/Console|server console]] and two [[player]] elements, that are direct children of the '''root''' element. All these resources have a ''dynamic map'' as child element (it is just not shown for most of them). These contain the elements that are created dynamically by this resource using scripts, for example a [[vehicle]]. If the resource has a map file, it is also a child element, itself containing all the elements in the .map file.&lt;br /&gt;
&lt;br /&gt;
Let's have a closer look at the '''assault''' resource: This contains just one ''dynamic'' map that has 2 teams, 3 blips, 1 marker and 1 colshape as child elements. These are the elements that are created by the script, for example the marker, the colshape and one of the blips are probably used for the objective.&lt;br /&gt;
&lt;br /&gt;
The '''as-farm''' resource's function on the contrary is to be a map for the '''assault''' gamemode. The dynamic map is empty (it could contain elements if there was a script in it though), while there is a map called 'as-farm.map', that contains a number of elements. These are mostly custom elements (like spawngroup, spawnarea, objective) but also a few elements that MTA creates automactically after loading the map (like pickup). In the brackets after the element type, you can see the element data it contains. These are identical with the attributes the .map file contains within these elements, while you can also set and get element data for any other elements (e.g. players) with [[setElementData]] and [[getElementData]].&lt;br /&gt;
&lt;br /&gt;
==Pratical application==&lt;br /&gt;
Elements can have as many children as they like. This does not directly affect the map in any way, but it comes in to its own when combined with the scripting system.&lt;br /&gt;
&lt;br /&gt;
===Setting data for elements===&lt;br /&gt;
If you call a set... function on a node of the element tree, the function will affect every element within it (that it can work on).&lt;br /&gt;
&lt;br /&gt;
So, the following code would set the size of every marker (the only type of element the setMarkerSize function can work on) that is below the root element to ''2.5''.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
setMarkerSize ( getRootElement(), 2.5 )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same can be done on any element, it is not restricted to the root element.&lt;br /&gt;
&lt;br /&gt;
===Менеджер карт===&lt;br /&gt;
The [[#Example|example above]] shows the way the [[map manager]] uses different resources. The 'assault' resource is the gamemode, that manages what happens on the server using scripts and thus by creating elements in the tree dynamically. When a map resource is started, the gamemode receives a [[resource|resource pointer]] referring to the started resource - in this case ''as-farm'' - from which you can retrieve and store the resource root element. Using this element in conjunction with functions like [[getElementsByType]], [[getElementData]] and various others, you can access any of the information that was loaded into the tree from the 'as-farm.map'-file through scripts in the gamemode resource.&lt;br /&gt;
&lt;br /&gt;
Another thing that has to be considered related to the tree of elements is the fact that when you change the map, you don't have to remove any elements you created within the map resource, while you '''do''' have to remove elements that are created within the gamemode resource, '''if''' they are specific to the map (which will be probably the case for those items you create based on information read from the map resource's .map files).&lt;br /&gt;
&lt;br /&gt;
==Element browser==&lt;br /&gt;
You can start the resource ''elementbrowser'' to see a live view of the element tree on your server. Just start the resource and browser to your server's web page and choose the ''Element browser'' option in the sidebar (firefox only currently).&lt;br /&gt;
[[Category:Scripting Concepts]]&lt;/div&gt;</summary>
		<author><name>WilliJ</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=RU/Debugging&amp;diff=25830</id>
		<title>RU/Debugging</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=RU/Debugging&amp;diff=25830"/>
		<updated>2011-05-17T15:36:42Z</updated>

		<summary type="html">&lt;p&gt;WilliJ: /* Вывод отладочных сообщений для проверки значения переменной */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;При написании скриптов вы обязательно столкнетесь с проблемами, которые не сможете решить немедленно. Цель этой страницы - показать вам основные способыы нахождения ошибок.&lt;br /&gt;
&lt;br /&gt;
==Консоль отладки==&lt;br /&gt;
MTA включает консоль, которая показывает отладочные сообщения, выводимые функциями MTA и скриптами. Вы можете открыть ее введя ''debugscript x'' в консоли, где ''x'' уровень отладки:&lt;br /&gt;
* '''1:''' только ошибки&lt;br /&gt;
* '''2:''' ошибки и предупреждения&lt;br /&gt;
* '''3:''' ошибки, предупреждения и информационные сообщения&lt;br /&gt;
Так, введя ''debugscript 3'', вы будете видеть все сообщения, этот или 2 уровень рекомендуется в большинстве случаев. Рекомендуем держать debugscript включенным всё время, пока вы тестируете свой скрипт, это поможет вам обнаружить мелкие ошибки и исправить их.&lt;br /&gt;
&lt;br /&gt;
===Пример===&lt;br /&gt;
Этот участок кода содержит две ошибки:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
if (getPlayerName(player) == &amp;quot;Fedor&amp;quot;)&lt;br /&gt;
	outputChatbox(&amp;quot;Hello Fedor&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
При попытке запуска скрипта, содержащего этот участо кода, debugscript выведет что-то похожее на:&lt;br /&gt;
{{Debug info|Loading script failed: C:\&amp;lt;server path&amp;gt;\mods\deathmatch\resources\myResource\script.lua:15: 'then' expected near ´outputChatbox'}}&lt;br /&gt;
Это означает, что скрипт не может быть обработан из-за синтаксической ошибки. Показывается путь к скрипту, поэтому вы можете увидеть, какому ресурсу он принадлежит, ('myResource' в данном случае) и, конечно же, имя скрипта. После имени файла показан номер строки и информация об ошибке. Теперь проблема легко решается, мы просто забыли написать ключевое слово 'then':&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
if (getPlayerName(player) == &amp;quot;Fedor&amp;quot;) then&lt;br /&gt;
	outputChatbox(&amp;quot;Hello Fedor&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Теперь скрипт загрузится нормально и не будет выводить ошибок пока не выполнится для игрока с ником 'Fedor'. Тогда debugscript выведет:&lt;br /&gt;
{{Debug error|C:\&amp;lt;server path&amp;gt;\mods\deathmatch\resources\d\script.lua:15: attempt to call global 'outputChatbox' (a nil value)}}&lt;br /&gt;
Это значит, вызванная вами функция не существует, оно и понятно, ведь правильное название этой функции ''outputChatBox'' (с заглавной буквы ''B''):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
if (getPlayerName(player) == &amp;quot;Fedor&amp;quot;) then&lt;br /&gt;
	outputChatBox(&amp;quot;Hello Fedor&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Конечно, это просто пример, есть множество других сообщений и сценариев.&lt;br /&gt;
&lt;br /&gt;
==Ведение лога==&lt;br /&gt;
Можно также включить режим дебаггера, отредактировав ''coreconfig.xml'' в папке GTA\MTA. Найдите в нем следующий тэг:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&amp;lt;debugfile/&amp;gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
И впишите туда адрес будущего лог-файла (путь указывайте, начиная с папки GTA):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&amp;lt;debugfile&amp;gt;MTA\debugscript.log&amp;lt;/debugfile&amp;gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
И теперь все сообщения дебаггера будут записываться в этот файл. Если хотите выключить ведение лога, оставьте содержимое тэга пустым:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&amp;lt;debugfile/&amp;gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Стратегии отладки==&lt;br /&gt;
Есть несколько методов, помогающих в поиске ошибок, кроме проверки всего кода. Большинство из них включает вывод различной информации, зависящей от конкретной ситуации.&lt;br /&gt;
&lt;br /&gt;
===Полезные функции===&lt;br /&gt;
Сперва несколько функций, которые можно использовать для отладки.&lt;br /&gt;
* [[outputDebugString]] или [[outputChatBox]] для вывода информации&lt;br /&gt;
* [http://www.lua.org/manual/5.1/manual.html#pdf-tostring tostring()] для преобразования значений переменных в строки, к примеру когда они содержат булевы значения&lt;br /&gt;
* [[getElementType]] для определения типа элемента MTA&lt;br /&gt;
&lt;br /&gt;
===Вывод отладочных сообщений для проверки ''как'', ''когда'' или ''как часто'' выполняется та или иная часть кода===&lt;br /&gt;
Простейшим примером является проверка, выполняется ли условие в операторе ''if''. Чтобы выполнить такую проверку, просто добавьте любое сообщение (которое вы сможете узнать впоследствии) внутрь секции, выполняемой при истинном условии в операторе ''if''.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
if (variable1 == variable2) then&lt;br /&gt;
	outputDebugString(&amp;quot;entered if&amp;quot;)&lt;br /&gt;
	-- do anything&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{translate}}&lt;br /&gt;
Another application would be to check when variable values are modified. First search for all occurences of the variable being edited and add a message just beside i&lt;br /&gt;
&lt;br /&gt;
===Вывод отладочных сообщений для проверки ''значения'' переменной===&lt;br /&gt;
Допустим, вы хотите создать маркер, но он не появляется в ожидаемом месте. Первое, что вы возможно захотите сделать - проверить, выполняется ли функция [[createMarker]].Но одновременно с этим можно также проверить передаваемые в функцию [[createMarker]] параметры.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
outputChatBox(tostring(x)..&amp;quot; &amp;quot;..tostring(y)..&amp;quot; &amp;quot;..tostring(z))&lt;br /&gt;
createMarker(x,y,z)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Этот код выведет 3 переменные - координаты маркера. Можно легко сравнить предполагаемые значения со значениями, выведенными при отладке. [http://www.lua.org/manual/5.1/manual.html#pdf-tostring tostring()] преобразует переменные в строки, даже если они имеют, например, логический тип.&lt;br /&gt;
&lt;br /&gt;
{{translate}}&lt;br /&gt;
&lt;br /&gt;
==Пример==&lt;br /&gt;
Imagine you created a colshape (collision shape) somewhere and you want a player to stay 10 seconds in it, then perform some action.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
When a player enters the colshape, debugscript outputs the following message:&lt;br /&gt;
{{Debug error|..[path]: attempt to index global 'colshapeTimer' (a nil value)}}&lt;br /&gt;
This means you tried to index a table that does not exist. In the example above, this is done when storing the timer id in the table. We need to add a check if the table exists and if not create it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we still get a warning when a player enters the colshape, waits for the message and leaves it again:&lt;br /&gt;
&lt;br /&gt;
{{Debug warning|[..]: Bad argument @ 'killTimer' Line: ..}}&lt;br /&gt;
&lt;br /&gt;
Except for that (we will talk about that later) everything seems to work fine. A player enters the colshape, the timer is started, if he stays the message occurs, if he leaves the timer is killed.&lt;br /&gt;
&lt;br /&gt;
===A more inconspicuous error===&lt;br /&gt;
But for some reason the message gets outputted twice when you stay in the colcircle while in a vehicle. Since it would appear some code is executed twice, we add debug messages to check this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a debug message&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit&amp;quot;)&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a debug message&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave&amp;quot;)&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we notice that both handler functions get executed twice when we are in a vehicle, but only once when we are on-foot. It would appear the vehicle triggers the colshape as well. To confirm this theory, we check the ''player'' variable that '''should''' contain a player element.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit &amp;quot;..getElementType(player))&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave &amp;quot;..getElementType(player))&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The debug messages tell us that one of the ''player'' variables is a player, the other one a vehicle element. Since we only want to react when a player enters the colshape, we add an ''if'' that will end the execution of the function if it's '''not''' an player element.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit &amp;quot;..getElementType(player))&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave &amp;quot;..getElementType(player))&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now the script should work as desired, but will still output the warning mentioned above. This happens because the timer we try to kill when a player leaves the colshape will not exist anymore when it reached the 10 seconds and is executed. There are different ways to get rid of that warning (since you know that the timer might not exist anymore and you only want to kill it if it is there). One way would be to check if the timer referenced in the table really exists. To do this, we need a little help function:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function isTimer(timer)&lt;br /&gt;
	local timers = getTimers()&lt;br /&gt;
	for k,v in ipairs(timers) do&lt;br /&gt;
		if (v == timer) then&lt;br /&gt;
			return true&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return false&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Which we will use when we kill the timer:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
if (isTimer(colshapeTimer[player])) then&lt;br /&gt;
	killTimer(colshapeTimer[player])&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the complete working code would be:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function colShapeHit(player)&lt;br /&gt;
	if (colshapeTimer == nil) then&lt;br /&gt;
		colshapeTimer = {}&lt;br /&gt;
	end&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeHit &amp;quot;..getElementType(player))&lt;br /&gt;
	-- set a timer to output a message (could as well execute another function)&lt;br /&gt;
	-- store the timer id in a table, using the player as index&lt;br /&gt;
	colshapeTimer[player] = setTimer(outputChatBox,10000,1,&amp;quot;The player stayed 10 seconds in the colshape!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeHit&amp;quot;,getRootElement(),colShapeHit)&lt;br /&gt;
&lt;br /&gt;
function colShapeLeave(player)&lt;br /&gt;
	-- add a check for the element type&lt;br /&gt;
	if (getElementType(player) ~= &amp;quot;player&amp;quot;) then return end&lt;br /&gt;
	-- add a debug message, with the element type&lt;br /&gt;
	outputDebugString(&amp;quot;colShapeLeave &amp;quot;..getElementType(player))&lt;br /&gt;
	-- kill the timer when the player leaves the colshape&lt;br /&gt;
	if (isTimer(colshapeTimer[player])) then&lt;br /&gt;
		killTimer(colshapeTimer[player])&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onColShapeLeave&amp;quot;,getRootElement(),colShapeLeave)&lt;br /&gt;
&lt;br /&gt;
function isTimer(timer)&lt;br /&gt;
	local timers = getTimers()&lt;br /&gt;
	for k,v in ipairs(timers) do&lt;br /&gt;
		if (v == timer) then&lt;br /&gt;
			return true&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return false&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Scripting Concepts]]&lt;br /&gt;
[[en:Debugging]]&lt;br /&gt;
[[it:Guida al Debug]]&lt;/div&gt;</summary>
		<author><name>WilliJ</name></author>
	</entry>
</feed>