GetResourceMapRootElement: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(added example)
(add oop syntax)
 
(2 intermediate revisions by 2 users not shown)
Line 5: Line 5:
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
element getResourceMapRootElement ( resource theResource, string mapName )  
element getResourceMapRootElement ( resource theResource, string mapName )
</syntaxhighlight>  
</syntaxhighlight>
 
{{OOP||[[resource]]:getMapRootElement}}
===Required Arguments===  
===Required Arguments===  
*'''theResource:''' the resource where the map is located
*'''theResource:''' the resource where the map is located
Line 22: Line 22:
-- After resource start we must found all vehicles only from island_1.map and lock them.
-- After resource start we must found all vehicles only from island_1.map and lock them.


-- `resourceRoot` is predefined script variable containing current resource root pointer
addEventHandler( 'onResourceStart', resourceRoot,
addEventHandler( 'onResourceStart', resourceRoot,
     function()
     function()
        -- `resource` is predefined script variable containing current resource pointer
         local island_1_mapRoot = getResourceMapRootElement( resource, 'island_1.map' )
         local island_1_mapRoot = getResourceMapRootElement( resource, 'island_1.map' )
         local island_1_vehicles = getElementsByType( 'vehicle', island_1_mapRoot )
         local island_1_vehicles = getElementsByType( 'vehicle', island_1_mapRoot )
Line 36: Line 38:
==See Also==
==See Also==
{{Resource_functions}}
{{Resource_functions}}
[[Category:Needs_Example]]

Latest revision as of 16:33, 1 January 2015

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

Syntax

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

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

Example

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

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

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

See Also

Shared