GetElementType: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (→‎Required Arguments: Linked "element" to the associated wiki page)
Line 15: Line 15:


==Example==  
==Example==  
<section name="Server" class="server" show="true">
This example destroys a haystack when a player targets it
This example destroys a haystack when a player targets it
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function onPlayerTargeted ( targetElem )
function onPlayerTarget ( targetElem )
     -- if the targeted object is a haystack (an object with model ID 3374) remove it from the game.
     -- if the targeted object is a haystack (an object with model ID 3374) remove it from the game
     if ( getElementType ( targetElem ) == "object" ) and ( getObjectModel ( targetElem ) == 3374 ) then
     if getElementType ( targetElem ) == "object" and getObjectModel ( targetElem ) == 3374 then
         destroyElement ( targetElem )
         destroyElement ( targetElem )
     end
     end
end
end
addEventHandler ( "onPlayerTargeted", getRootElement(), onPlayerTargeted )    -- add above function as handler for targeting event
addEventHandler ( "onPlayerTarget", getRootElement(), onPlayerTarget )    -- add above function as handler for targeting event
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Element functions}}
{{Element functions}}

Revision as of 11:51, 20 June 2008

This function is used to retrieve the type of an element.

Syntax

string getElementType ( element theElement )  

Required Arguments

  • theElement: The element you wish to get the type of.

Returns

Returns a string containing the element type, false if invalid arguments were passed.

Example

Click to collapse [-]
Server

This example destroys a haystack when a player targets it

function onPlayerTarget ( targetElem )
    -- if the targeted object is a haystack (an object with model ID 3374) remove it from the game
    if getElementType ( targetElem ) == "object" and getObjectModel ( targetElem ) == 3374 then
        destroyElement ( targetElem )
    end
end
addEventHandler ( "onPlayerTarget", getRootElement(), onPlayerTarget )    -- add above function as handler for targeting event

See Also