Element tree

From Multi Theft Auto: Wiki
Revision as of 17:37, 8 August 2007 by Driver2 (talk | contribs)
Jump to navigation Jump to search

MTA uses a so-called element tree to store the elements that make up the map. This is directly related to the XML map file's layout, although it can be changed at run-time by scripts.

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 like a family tree - except everyone only has a single parent. Every element has a parent element. This element is the element that it is contained within in the map file. For example:


<map>
   <marker>
      <vehicle/>
   </marker>
</map>

Example

*  root
         o console
         o resourcebrowser: resource
         o ajax: resource
         o resourcemanager: resource
         o spawnmanager: resource
         o echobot: resource
         o mapmanager: resource
         o playerblips: resource
         o runcode: resource
         o fr: resource
               + dynamic: map
                     # vehicle 
         o player {dontRespawn = false, lastSpawnarea = [object Object]}
         o elementbrowser: resource
         o player {dontRespawn = false}
         o assault: resource
               + dynamic: map
                     # team
                     # team
                     # blip
                     # marker
                     # colshape
                     # blip
                     # blip 
         o as-farm: resource
               + dynamic: map
               + as-farm.map: map
                     # meta
                           * author
                           * version
                           * name
                           * description 
                     # spawngroup {req = , type = attacker}
                           * spawnarea {posY = -8.3976354598999, posX = 20.182683944702, skins = 9, ..} 
                     # spawngroup {req = first, type = attacker}
                           * spawnarea {posY = 32.166355133057, posX = -46.90763092041, skins = 9, ..
                     # spawngroup {req = , type = defender}
                           * spawnarea {posY = 35.214984893799, posX = -33.486911773682, skins = 9, ..} 
                     # spawngroup {req = first, type = defender}
                           * spawnarea {posY = 120.22289276123, posX = -37.031703948975, skins = 9, ..} 
                     # first: objective {type = checkpoint, description = Breach into the farm, id = first, ..}
                     # pickup {posY = 37.083660125732, type = weapon, ..}


In this example, the vehicle element's parent is the marker element. As such, we call the vehicle element a child element of the marker element.

When this map is loaded, it is placed within the server's element tree. This tree has a number of "special" elements.

  • A root element. This is at the very base of the tree - all elements are children (or grand children etc) of this element.
  • Resource elements. These are direct children of the root element - with one for each running resource.
  • Map elements. Each resource element contains at least 1 map element, representing either a ".map" file in the resource or containing the elements created by scripts (this is called the "dynamic" map).

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.

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).

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.

setMarkerSize ( getRootElement(), 2.5 )

The same can be done on any element, it is not restricted to the root element.