GetElementType: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
m (fixed a mistake)
 
(12 intermediate revisions by 12 users not shown)
Line 1: Line 1:
[[category:incomplete]]
{{Server client function}}
__NOTOC__  
__NOTOC__
This function is used to retrieve the type of an Element.
This function is used to retrieve the type of an element.


==Syntax==  
==Syntax==  
Line 7: Line 7:
string getElementType ( element theElement )   
string getElementType ( element theElement )   
</syntaxhighlight>  
</syntaxhighlight>  
{{OOP||[[element]]:getType|type|}}


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


===Returns===
===Returns===
There are a total of 10 strings this function returns:
Returns a ''string'' containing the element type, ''false'' if invalid arguments were passed.
*'''"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==  
==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">
--Add an event, so the server knows to wait for someone to start targeting stuff
function onPlayerTarget ( targetElem )
addEventHandler ( "onPlayerTargeted", root, "onPlayerTargeted" )
     -- if the targeted object is a haystack (an object with model ID 3374) remove it from the game
--Add the function that runs when the event is tripped
     if getElementType ( targetElem ) == "object" and getElementModel ( targetElem ) == 3374 then
function onPlayerTargeted ( element )
         destroyElement ( targetElem )
     --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
end    
end
addEventHandler ( "onPlayerTarget", root, onPlayerTarget )    -- add above function as handler for targeting event
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Element functions}}
{{Element functions}}
[[pt-br:getElementType]]

Latest revision as of 14:25, 27 April 2021

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

Syntax

string getElementType ( element theElement )  

OOP Syntax Help! I don't understand this!

Method: element:getType(...)
Variable: .type


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 getElementModel ( targetElem ) == 3374 then
        destroyElement ( targetElem )
    end
end
addEventHandler ( "onPlayerTarget", root, onPlayerTarget )    -- add above function as handler for targeting event

See Also

Shared