<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=VenZ</id>
	<title>Multi Theft Auto: Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=VenZ"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/wiki/Special:Contributions/VenZ"/>
	<updated>2026-05-07T03:30:28Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=OnElementClicked&amp;diff=51918</id>
		<title>OnElementClicked</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=OnElementClicked&amp;diff=51918"/>
		<updated>2017-08-12T09:42:41Z</updated>

		<summary type="html">&lt;p&gt;VenZ: /* Examples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
{{Server event}}&lt;br /&gt;
This event is triggered when an element is clicked on by the client. These events can only trigger when the client has its cursor enabled. It triggers for all three mousebuttons in both their up and down states.&lt;br /&gt;
&lt;br /&gt;
==Parameters==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
string mouseButton, string buttonState, player playerWhoClicked, float clickPosX, float clickPosY, float clickPosZ&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
*'''mouseButton''': A string representing the mousebutton that was clicked. This might be ''left'', ''middle'' or ''right''.&lt;br /&gt;
*'''buttonState''': A string representing what state the button clicked is in. This might be ''up'' or ''down''.&lt;br /&gt;
*'''playerWhoClicked''': The player that clicked on the element&lt;br /&gt;
*'''clickPosX''': The X position in the world the player clicked at&lt;br /&gt;
*'''clickPosY''': The Y position in the world the player clicked at&lt;br /&gt;
*'''clickPosZ''': The Z position in the world the player clicked at&lt;br /&gt;
&lt;br /&gt;
==Source==&lt;br /&gt;
The [[event system#Event source|source]] of this event is the [[element]] that got clicked by the player.&lt;br /&gt;
&lt;br /&gt;
==Examples== &lt;br /&gt;
This example prints type of the element you clicked to chatbox when you click it.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function elementClicked( theButton, theState, thePlayer )&lt;br /&gt;
    if theButton == &amp;quot;left&amp;quot; and theState == &amp;quot;down&amp;quot; then -- if left mouse button was pressed down&lt;br /&gt;
        outputChatBox( &amp;quot;You clicked &amp;quot; .. getElementType( source ), thePlayer ) -- print the element type to players chatbox&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler( &amp;quot;onElementClicked&amp;quot;, getRootElement(), elementClicked ) -- add a handler function for the event&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example check if the clicked element is a vehicle. If is, then repairs it.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function repairClickedVehicle( button, state, player ) -- Add the function&lt;br /&gt;
    if button == &amp;quot;left&amp;quot; and state == &amp;quot;down&amp;quot; then&lt;br /&gt;
        if getElementType( source ) == &amp;quot;vehicle&amp;quot; then -- If the clicked element is a vehicle...&lt;br /&gt;
            local x, y, z = getElementPosition( player )&lt;br /&gt;
            local x1, y1, z1 = getElementPosition( source ) &lt;br /&gt;
            local distance = getDistanceBetweenPoints3D( x, y, z, x1, y1, z1 ) -- Some distance calculations&lt;br /&gt;
            if distance &amp;lt; 4 then -- Check if the player is near the vehicle&lt;br /&gt;
                if getElementHealth( source ) &amp;lt; 1000 then&lt;br /&gt;
                    fixVehicle( source )&lt;br /&gt;
                    outputChatBox( &amp;quot;You have repaired a &amp;quot;..getVehicleNameFromModel( getElementModel( source ) ), player, 0, 255, 0 )&lt;br /&gt;
                else&lt;br /&gt;
                    outputChatBox( &amp;quot;Vehicle is not damaged!&amp;quot;, player, 255, 0, 0 )&lt;br /&gt;
                end&lt;br /&gt;
            end&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler( &amp;quot;onElementClicked&amp;quot;, getRootElement( ), repairClickedVehicle ) -- Add the event handler&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
{{See also/Server event|Element events}}&lt;/div&gt;</summary>
		<author><name>VenZ</name></author>
	</entry>
</feed>