GetElementType: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
[[category:incomplete]]
__NOTOC__  
__NOTOC__  
This function is used to retrieve the type of an Element.
This function is used to retrieve the type of an Element.
Line 4: Line 5:
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
string getElementType ( element element )   
string getElementType ( element theElement )   
</syntaxhighlight>  
</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
*'''element:''' The element you wish to get the type of.
*'''theElement:''' The element you wish to get the type of.


===Returns===
===Returns===
Line 22: Line 23:
*'''"console":''' The server Console
*'''"console":''' The server Console
*'''"unknown":''' Unknown element type
*'''"unknown":''' Unknown element type
It is also possible to specify your own element types using [[setElementType]], or by specifying it in the xml file.
This function will return ''false'' if ''theElement'' is invalid.


==Example==  
==Example==  
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">
--Add an event, so the server knows to wait for someone to start targeting stuff
addEventHandler ( "onPlayerTargeted", root, "onPlayerTargeted" )
addEventHandler ( "onPlayerTargeted", root, "onPlayerTargeted" )
--Add the function that runs when the event is tripped
function onPlayerTargeted ( element )
function onPlayerTargeted ( element )
    --If the targetted object is a haystack remove it from the game.
     if ( getElementType ( element ) == "object" ) and ( getObjectModel ( element ) == 3374 ) then
     if ( getElementType ( element ) == "object" ) and ( getObjectModel ( element ) == 3374 ) then
         destroyElement ( element )
         destroyElement ( element )
Line 35: Line 43:


==See Also==
==See Also==
[[Elements]]
{{Element functions}}
{{Element functions}}

Revision as of 15:14, 22 August 2006


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

There are a total of 10 strings this function returns:

  • "player": A player connected to the server
  • "vehicle":: A vehicle
  • "object": An object
  • "pickup": A pickup
  • "blip": A blip
  • "marker": A marker
  • "spawnpoint": A spawnpoint
  • "remoteclient": A remote client connected to the server
  • "console": The server Console
  • "unknown": Unknown element type

It is also possible to specify your own element types using setElementType, or by specifying it in the xml file.

This function will return false if theElement is invalid.

Example

This example destroys a haystack when a player targets it

--Add an event, so the server knows to wait for someone to start targeting stuff
addEventHandler ( "onPlayerTargeted", root, "onPlayerTargeted" )
--Add the function that runs when the event is tripped
function onPlayerTargeted ( element )
    --If the targetted object is a haystack remove it from the game.
    if ( getElementType ( element ) == "object" ) and ( getObjectModel ( element ) == 3374 ) then
        destroyElement ( element )
    end
end     

See Also