You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -7,11 +9,11 @@ import treeImage from '../../../assets/element_tree.webp';
7
9
title: 'Element tree',
8
10
tableOfContents: false,
9
11
}}>
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.
12
+
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](/resource) and their map files' XML layout, although it can be changed at run-time by scripts.
11
13
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.
14
+
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](/Element) has a *parent* element.
13
15
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.
16
+
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 [players](/player)) exist only within resources and are also destroyed as soon as their resource is stopped.
15
17
16
18
<Imagesrc={treeImage}alt="Element tree"/>
17
19
@@ -25,7 +27,7 @@ getRootElement()
25
27
getResourceRootElement()
26
28
```
27
29
***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.
30
+
* Map files can contain a number of other [elements](/Element) as well as an unlimited number of custom elements.
29
31
30
32
### Example
31
33
This in an example of a serverside tree dumped to XML from a running server.
@@ -80,11 +82,11 @@ This in an example of a serverside tree dumped to XML from a running server.
80
82
</root>
81
83
```
82
84
### 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.
85
+
This tree consists of a number of resource root elements, the [Server Console](/console) and two [player](/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](/vehicle). If the resource has a map file, it is also a child element, itself containing all the elements in the .map file.
84
86
85
87
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
88
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]].
89
+
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](/setElementData) and [getElementData](/getElementData).
88
90
89
91
### Practical application
90
92
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.
@@ -100,12 +102,16 @@ setMarkerSize ( root, 2.5 )
100
102
The same can be done on any element, it is not restricted to the root element.
101
103
102
104
### 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.
105
+
The example above shows the way the [map manager](/Resource:mapmanager) 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 pointer](/resource) 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](/getElementsByType), [getElementData](/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
106
105
107
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
108
107
109
### Element browser
108
110
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).
Copy file name to clipboardExpand all lines: web/src/pages/OOP_Introduction.mdx
+74-4Lines changed: 74 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -6,13 +6,24 @@ import SeeAlsoSection from '@src/components/SeeAlsoSection.astro';
6
6
7
7
<StarlightPagefrontmatter={{
8
8
template: 'doc',
9
-
title: 'OOP Introduction',
9
+
title: 'About OOP',
10
10
tableOfContents: false,
11
11
}}>
12
12
13
-
This is a scripting tutorial explaining to you what **object orientated programming** is and teaching you how to use the **OOP features of MTA**. This was originally created by qaisjp on June 8, 2014 ([Forum post](https://forum.multitheftauto.com/topic/65029-wikitut-oop-introduction/)).
14
13
15
-
### Introduction to OOP
14
+
Object Orientated Programming was introduced in MTA:SA 1.4 and comes with special utility classes like [Vector](/Vector) and [Matrix](/Matrix). This page contains general information about the OOP functions and provides useful links.
15
+
16
+
### Turning it on
17
+
18
+
By default, OOP is disabled (however, vectors and matrices are always available) - this is mainly because the vast majority of servers will prefer to stick to what they know - procedural programming. In fact, functions are still available even when OOP is enabled. Enabling OOP is as simple as adding the following line to the resource meta file:
19
+
20
+
```xml
21
+
<oop>true</oop>
22
+
```
23
+
24
+
### Introduction
25
+
26
+
This is a scripting tutorial explaining to you what **object orientated programming** is and teaching you how to use the **OOP features of MTA**. This was originally created by qaisjp on June 8, 2014 ([Forum post](https://forum.multitheftauto.com/topic/65029-wikitut-oop-introduction/)).
16
27
17
28
OOP stands for *object orientated programming*. Three simple words, and you'll probably understand the last word the most. OOP is where all functions relating to a single instance are called on that instance, an instance being a creation of a class — an element class, a database class, a player, a vehicle.
18
29
@@ -103,6 +114,11 @@ Timer(incrementDimension, 60*1000, 10) -- set a timer for sixty thousand millise
103
114
104
115
This code would take a random player and move them to the next dimension every minute for the next ten minutes.
105
116
117
+
118
+
### Vectors and Matrices
119
+
120
+
[Vectors](/Vector) and [Matrices](/Matrix) make it easier to drop the complex maths and go straight ahead with fun part of maths. As mentioned above, OOP does not have to be enabled in the server config for this to be enabled.
121
+
106
122
### Vectors
107
123
108
124
`player.position` works too! But how do you change three arguments... using one variable? **Vectors.**
@@ -154,8 +170,62 @@ The documentation for the OOP syntax intends to be very simplistic and is suppor
154
170
* Methods can either start like `player:` or `Player.` — the former is only for a function on an instance (like `setPlayerHealth`) and the latter is a static method (like `getRandomPlayer`).
155
171
* The counterpart section allows you to see at a glance how the variable can be used. In most cases, this can be inferred from the function page.
156
172
173
+
174
+
### OOP Metatable Structure (Advanced)
175
+
176
+
You will understand this if you're proficient with Lua and have a decent understanding of metatables. Understanding this section is not necessary to use OOP.
0 commit comments