getRootElement | Multi Theft Auto: Wiki Skip to content

getRootElement

Client-side
Server-side
Shared

This function returns the root node of the element tree, called root. This node contains every other element - all resource root elements, players etc. It is never destroyed and cannot be destroyed using destroyElement. It is often used to attach handler functions to events triggered for any element, or also to make a scripting function affect all elements.

Note

All resources have a predefined global variable called root that has the root element as value. The variable exists server side as well as client side.

Syntax

element getRootElement ( )

Returns

  • element: root element

Returns the root element.

Code Examples

shared
local players = getElementsByType('player', getRootElement()) -- You can also use predefined global variable 'root' instead
outputChatBox("Players online: "..#players)
local vehicles = getElementsByType('vehicle', root) -- Use predefined global variable 'root'
outputChatBox("Vehicles on the map: "..#vehicles)

See Also

Element Functions