From Multi Theft Auto: Wiki
Jump to navigation Jump to search

This function retrieves the root element of a certain map in a specified resource.


element getResourceMapRootElement ( resource theResource, string mapName )

OOP Syntax Help! I don't understand this!

Method: resource:getMapRootElement(...)

Required Arguments

  • theResource: the resource where the map is located
  • mapName: name of the maps which root element we want to retrieve, file extension is required


Returns an the resource's map root element if the map exists and resource specified was valid and active (currently running), false otherwise.


This example shows how to get all elements of specific type only from one map.

-- We have 2 map files in our meta.xml:,
-- These maps contains objects, vehicles, pickups, etc.
-- After resource start we must found all vehicles only from and lock them.

-- `resourceRoot` is predefined script variable containing current resource root pointer
addEventHandler( 'onResourceStart', resourceRoot,
        -- `resource` is predefined script variable containing current resource pointer
        local island_1_mapRoot = getResourceMapRootElement( resource, '' )
        local island_1_vehicles = getElementsByType( 'vehicle', island_1_mapRoot )
        for vehicle in ipairs(island_1_vehicles) do
            setVehicleLocked( vehicle, true )

See Also