OnClientClick: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Restored old revision without the example in Turkish language)
Line 37: Line 37:
end
end
addEventHandler ( "onClientClick", getRootElement(), addLabelOnClick )
addEventHandler ( "onClientClick", getRootElement(), addLabelOnClick )
</syntaxhighlight>
==Example #2==
<syntaxhighlight lang="lua">
r, r1 = guiGetScreenSize();
function Ruzgar_Function( ... )
    buttonOlustur(r/2, r1/2,150, 50,"DX Button", 255,255,255)
end
addEventHandler("onClientRender", root, Ruzgar_Function)
function buttonOlustur(x, y, uzunluk, yukseklik, metin, r,g,b )
    degisken = metin;
    r = tonumber(r);
    g = tonumber(g);
    b = tonumber(b);
    alpha = tonumber(255);
            if isMouseInPosition(x, y, uzunluk, yukseklik) then
            r = tonumber(255);
          g = tonumber(138);
        b = tonumber(0);
end
    if x and y and uzunluk and yukseklik and metin and r and g and b then
        dxDrawRectangle(x, y, uzunluk, yukseklik,tocolor(r,g,b,alpha), false);
        dxDrawText(degisken, x+10-1, y+1-1, x+uzunluk-10-1, y+yukseklik-2-1, tocolor(0,0,0,255), 1.2, "default-bold", "center", "center", true, false, false, false);
        dxDrawText(degisken, x+10, y+1, x+uzunluk-10, y+yukseklik-2, tocolor(255,255,255,255), 1.2, "default-bold", "center", "center", true, false, false, false);
    else
        outputDebugString("buttonOlustur yanlış kullanılmış / buttonOlustur is Incorrectly used",1);
    end
end
function isMouseInPosition ( x, y, width, height )
    if ( not isCursorShowing( ) ) then
        return false
    end
    local sx, sy = guiGetScreenSize ( )
    local cx, cy = getCursorPosition ( )
    local cx, cy = ( cx * sx ), ( cy * sy )
    if ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) then
        return true
    else
        return false
    end
end
function tik_click( ... )
    if isMouseInPosition(r/2, r1/2,150, 50) and getKeyState("mouse1") then
        outputChatBox("buttonOlustur is Working")
    end
end
addEventHandler("onClientClick", root, tik_click)
</syntaxhighlight>
</syntaxhighlight>


Line 88: Line 42:
===GUI events===
===GUI events===
{{GUI_events}}
{{GUI_events}}
===Client event functions===
===Client event functions===
{{Client_event_functions}}
{{Client_event_functions}}
[[pl:onClientClick]]
[[tr:onClientClick]]

Revision as of 10:11, 13 May 2017

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.

Parameters

string button, string state, int absoluteX, int absoluteY, float worldX, float worldY, float worldZ, element clickedWorld
  • button: This refers the button used to click on the mouse, can be left, right, or middle
  • 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
  • absoluteX: This refers to the 2D x coordinate the user clicked on his screen, and is an absolute position in pixels.
  • absoluteY: This refers to the 2D y coordinate the user clicked on his screen, and is an absolute position in pixels.
  • worldX: This represents the 3D x coordinate the player clicked on the screen, and is relative to the GTA world.
  • worldY: This represents the 3D y coordinate the player clicked on the screen, and is relative to the GTA world.
  • worldZ: This represents the 3D z coordinate the player clicked on the screen, and is relative to the GTA world.
  • clickedWorld: This represents any physical entity elements that were clicked. If the player clicked on no MTA element, it's set to false.

Source

The source of this event is the client's root element.

Example

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.

local myLabel = guiCreateLabel  ( 0, 0, 1, 1, "", true )

function addLabelOnClick ( button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement )
        --if an element was clicked on screen
        if ( clickedElement ) then
                --retreive the element type
                local elementType = getElementType ( clickedElement )
                --change the label text to that element type
                guiSetText ( myLabel, elementType )
                --and place it in the position of where the element is
                guiSetPosition ( myLabel, absoluteX, absoluteY, false )
                --hide the text by passing an empty string 5 seconds later
                setTimer ( guiSetText, 5000, 1, myLabel, "" )
        end
end
addEventHandler ( "onClientClick", getRootElement(), addLabelOnClick )

See Also

GUI events

Input

GUI


Client event functions