<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/wiki/TR/OnClientClick?action=history&amp;feed=atom</id>
	<title>TR/OnClientClick - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/wiki/TR/OnClientClick?action=history&amp;feed=atom"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=TR/OnClientClick&amp;action=history"/>
	<updated>2026-04-05T22:50:24Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=TR/OnClientClick&amp;diff=50963&amp;oldid=prev</id>
		<title>Necktrox: Copied from the English page</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=TR/OnClientClick&amp;diff=50963&amp;oldid=prev"/>
		<updated>2017-05-13T10:10:26Z</updated>

		<summary type="html">&lt;p&gt;Copied from the English page&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Client event}}&lt;br /&gt;
__NOTOC__ &lt;br /&gt;
This event triggers whenever the user clicks his mouse.  This is linked to the GTA world, as oppose to GUI for which [[onClientGUIClick]] is to be used.  This event allows detection of click positions of the 3D world.&lt;br /&gt;
&lt;br /&gt;
==Parameters==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;string button, string state, int absoluteX, int absoluteY, float worldX, float worldY, float worldZ, element clickedWorld&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* '''button''':  This refers the button used to click on the mouse, can be ''left'', ''right'', or ''middle''&lt;br /&gt;
* '''state''': This can be used to tell if the user released or pressed the mouse button, where ''up'' is passed if the button is released, and ''down'' is passed if the button is pushed&lt;br /&gt;
* '''absoluteX''': This refers to the 2D ''x coordinate'' the user clicked on his screen, and is an ''absolute'' position in pixels.&lt;br /&gt;
* '''absoluteY''': This refers to the 2D ''y coordinate'' the user clicked on his screen, and is an ''absolute'' position in pixels.&lt;br /&gt;
* '''worldX''': This represents the 3D ''x coordinate'' the player clicked on the screen, and is relative to the GTA world.&lt;br /&gt;
* '''worldY''': This represents the 3D ''y coordinate'' the player clicked on the screen, and is relative to the GTA world.&lt;br /&gt;
* '''worldZ''': This represents the 3D ''z coordinate'' the player clicked on the screen, and is relative to the GTA world.&lt;br /&gt;
* '''clickedWorld''': This represents any physical [[entity]] elements that were clicked. If the player clicked on no MTA element, it's set to false.&lt;br /&gt;
&lt;br /&gt;
==Source==&lt;br /&gt;
The [[event system#Event source|source]] of this event is the client's [[root element]].&lt;br /&gt;
&lt;br /&gt;
==Example== &lt;br /&gt;
This example creates a label when an element is clicked, the label displays in the position of the element telling you what kind of element you have clicked.  It hides after 5 seconds.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local myLabel = guiCreateLabel  ( 0, 0, 1, 1, &amp;quot;&amp;quot;, true )&lt;br /&gt;
&lt;br /&gt;
function addLabelOnClick ( button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement )&lt;br /&gt;
        --if an element was clicked on screen&lt;br /&gt;
        if ( clickedElement ) then&lt;br /&gt;
                --retreive the element type&lt;br /&gt;
                local elementType = getElementType ( clickedElement )&lt;br /&gt;
                --change the label text to that element type&lt;br /&gt;
                guiSetText ( myLabel, elementType )&lt;br /&gt;
                --and place it in the position of where the element is&lt;br /&gt;
                guiSetPosition ( myLabel, absoluteX, absoluteY, false )&lt;br /&gt;
                --hide the text by passing an empty string 5 seconds later&lt;br /&gt;
                setTimer ( guiSetText, 5000, 1, myLabel, &amp;quot;&amp;quot; )&lt;br /&gt;
        end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler ( &amp;quot;onClientClick&amp;quot;, getRootElement(), addLabelOnClick )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
r, r1 = guiGetScreenSize();&lt;br /&gt;
function Ruzgar_Function( ... )&lt;br /&gt;
    buttonOlustur(r/2, r1/2,150, 50,&amp;quot;DX Button&amp;quot;, 255,255,255)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onClientRender&amp;quot;, root, Ruzgar_Function)&lt;br /&gt;
function buttonOlustur(x, y, uzunluk, yukseklik, metin, r,g,b )&lt;br /&gt;
    degisken = metin;&lt;br /&gt;
    r = tonumber(r);&lt;br /&gt;
    g = tonumber(g);&lt;br /&gt;
    b = tonumber(b);&lt;br /&gt;
    alpha = tonumber(255);&lt;br /&gt;
            if isMouseInPosition(x, y, uzunluk, yukseklik) then&lt;br /&gt;
            r = tonumber(255);&lt;br /&gt;
          g = tonumber(138);&lt;br /&gt;
        b = tonumber(0);&lt;br /&gt;
end&lt;br /&gt;
    if x and y and uzunluk and yukseklik and metin and r and g and b then&lt;br /&gt;
        dxDrawRectangle(x, y, uzunluk, yukseklik,tocolor(r,g,b,alpha), false);&lt;br /&gt;
        dxDrawText(degisken, x+10-1, y+1-1, x+uzunluk-10-1, y+yukseklik-2-1, tocolor(0,0,0,255), 1.2, &amp;quot;default-bold&amp;quot;, &amp;quot;center&amp;quot;, &amp;quot;center&amp;quot;, true, false, false, false);&lt;br /&gt;
        dxDrawText(degisken, x+10, y+1, x+uzunluk-10, y+yukseklik-2, tocolor(255,255,255,255), 1.2, &amp;quot;default-bold&amp;quot;, &amp;quot;center&amp;quot;, &amp;quot;center&amp;quot;, true, false, false, false);&lt;br /&gt;
    else&lt;br /&gt;
        outputDebugString(&amp;quot;buttonOlustur yanlış kullanılmış / buttonOlustur is Incorrectly used&amp;quot;,1);&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
function isMouseInPosition ( x, y, width, height )&lt;br /&gt;
    if ( not isCursorShowing( ) ) then&lt;br /&gt;
        return false&lt;br /&gt;
    end&lt;br /&gt;
    local sx, sy = guiGetScreenSize ( )&lt;br /&gt;
    local cx, cy = getCursorPosition ( )&lt;br /&gt;
    local cx, cy = ( cx * sx ), ( cy * sy )&lt;br /&gt;
    if ( cx &amp;gt;= x and cx &amp;lt;= x + width ) and ( cy &amp;gt;= y and cy &amp;lt;= y + height ) then&lt;br /&gt;
        return true&lt;br /&gt;
    else&lt;br /&gt;
        return false&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
function tik_click( ... )&lt;br /&gt;
    if isMouseInPosition(r/2, r1/2,150, 50) and getKeyState(&amp;quot;mouse1&amp;quot;) then&lt;br /&gt;
        outputChatBox(&amp;quot;buttonOlustur is Working&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onClientClick&amp;quot;, root, tik_click)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
===GUI events===&lt;br /&gt;
{{GUI_events}}&lt;br /&gt;
&lt;br /&gt;
===Client event functions===&lt;br /&gt;
{{Client_event_functions}}&lt;br /&gt;
&lt;br /&gt;
[[en:onClientClick]]&lt;br /&gt;
[[pl:onClientClick]]&lt;/div&gt;</summary>
		<author><name>Necktrox</name></author>
	</entry>
</feed>