Skip to content

Commit f87bf48

Browse files
WIP element tree article
1 parent fed4a19 commit f87bf48

File tree

3 files changed

+112
-9
lines changed

3 files changed

+112
-9
lines changed

assets/element_tree.webp

13.3 KB
Binary file not shown.

web/src/overrides/Pagination.astro

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ import IconLinkCard from '@src/components/IconLinkCard.astro';
2323
<IconLinkCard
2424
icon="seti:plan"
2525
title="Elements"
26-
description="List of MTA:SA elements"
27-
href="/Element_tree" />
26+
description="List of all element types and their properties"
27+
href="/Element" />
28+
2829

2930
<IconLinkCard
3031
icon="discord"
@@ -38,10 +39,9 @@ import IconLinkCard from '@src/components/IconLinkCard.astro';
3839
description="Engage with the community in the old-fashioned way."
3940
href="https://forum.multitheftauto.com/" />
4041

42+
<IconLinkCard
43+
icon="github"
44+
title="GitHub Repository"
45+
description="Contribute to the Wiki project or report issues."
46+
href="https://github.com/multitheftauto/wiki.multitheftauto.com" />
4147
</CardGrid>
42-
43-
<IconLinkCard
44-
icon="github"
45-
title="GitHub Repository"
46-
description="Contribute to the Wiki project or report issues."
47-
href="https://github.com/multitheftauto/wiki.multitheftauto.com" />

web/src/pages/Element_tree.mdx

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,112 @@
11
import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';
2+
import { Image } from 'astro:assets';
3+
import treeImage from '../assets/element_tree.webp';
24

35
<StarlightPage frontmatter={{
46
template: 'doc',
57
title: 'Element tree',
68
tableOfContents: false,
79
}}>
8-
Coming soon
10+
MTA uses a so-called *element tree* to store all the elements that exist on the server and the client. 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.
11+
12+
If you are familiar with the concept of *trees* in computer-science, this should be easy to understand. If you are not, think of it as a family tree - except everyone only has a single parent. Every [[element]] has a *parent* element.
13+
14+
All elements that are created within scripts or from .map files are child elements of the resource they belong to. Thus, most elements (except for [[client]]s) exist only within resources and are also destroyed as soon as their resource is stopped.
15+
16+
<Image src={treeImage} alt="Element tree"/>
17+
18+
### Tree elements
19+
* **root**: This is at the very base of the tree - all elements are children (or descendants) of this element.
20+
```lua
21+
getRootElement()
22+
```
23+
* **resource**: These are direct children of the root element - with one for each *running* resource. This element is called the *resource root*. Its ID holds the name of the resource.
24+
```lua
25+
getResourceRootElement()
26+
```
27+
* **map**: Each resource element contains at least one map element, representing either a ".map" file in the resource 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.
28+
** Map files can contain a number of other [[element]]s as well as an unlimited number of custom elements.
29+
30+
### Example
31+
This in an example of a serverside tree dumped to XML from a running server.
32+
*Please note that it is shortened on some places for the sake of overview.*
33+
```xml
34+
<root>
35+
<console/>
36+
<player dontRespawn="false"/>
37+
<player dontRespawn="false" lastSpawnarea=""/>
38+
<resource id="resourcebrowser"/>
39+
<resource id="ajax"/>
40+
<resource id="resourcemanager"/>
41+
<resource id="spawnmanager"/>
42+
<resource id="mapmanager"/>
43+
<resource id="runcode"/>
44+
<resource id="fr">
45+
<map id="dynamic">
46+
<vehicle/>
47+
</map>
48+
</resource>
49+
<resource id="elementbrowser"/>
50+
<resource id="assault">
51+
<map id="dynamic">
52+
<team/>
53+
<team/>
54+
<blip/>
55+
<marker/>
56+
<colshape/>
57+
<blip/>
58+
<blip/>
59+
</map>
60+
</resource>
61+
<resource id="as-farm">
62+
<map id="dynamic"/>
63+
<map id="as-farm.map">
64+
<spawngroup req="" type="attacker">
65+
<spawnarea posY="-8.3976354598999" posX="20.182683944702" skins="9" ... />
66+
</spawngroup>
67+
<spawngroup req="" type="attacker">
68+
<spawnarea posY="32.166355133057" posX="-46.90763092041" skins="9" ... />
69+
</spawngroup>
70+
<spawngroup req="" type="attacker">
71+
<spawnarea posY="35.214984893799" posX="-33.486911773682" skins="9" ... />
72+
</spawngroup>
73+
<spawngroup req="" type="attacker">
74+
<spawnarea posY="35.214984893799" posX="-33.486911773682" skins="9" ... />
75+
</spawngroup>
76+
<objective id="first" type="checkpoint" description="Breach into the farm" ... />
77+
<pickup type="weapon" ... />
78+
</map>
79+
</resource>
80+
</root>
81+
```
82+
### Explanation
83+
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.
84+
85+
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.
86+
87+
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 automatically 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]].
88+
89+
### Practical application
90+
Elements can have as many children as they like. This does not directly affect the map in any way, but it comes into its own when combined with the scripting system.
91+
92+
### Setting data for elements
93+
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).
94+
95+
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*.
96+
```lua
97+
setMarkerSize ( root, 2.5 )
98+
```
99+
100+
The same can be done on any element, it is not restricted to the root element.
101+
102+
### Map manager
103+
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.
104+
105+
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).
106+
107+
### Element browser
108+
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).
109+
9110
</StarlightPage>
111+
112+
{/* TODO: see also */}

0 commit comments

Comments
 (0)