OnClientClick: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
[[Category:Incomplete Event]]
{{Client event}}
 
__NOTOC__  
__NOTOC__  
This event is blahblah and is used for blahblah.
This event triggers whenever the user clicks his mouse.  This is linked to the GTA world, as appose to GUI for which [[onClientGUIClick]] is to be used.  This event allows detection of click positions of the 3D world.


==Syntax==  
==Parameters==
<syntaxhighlight lang="lua">void onClientClick ( string button, string state, int absoluteX, int absoluteY, float worldX, float worldY, float worldZ, element clickedWorld, bool clickedGUI )
<syntaxhighlight lang="lua">string button, string state, int absoluteX, int absoluteY, float worldX, float worldY, float worldZ, element clickedWorld
</syntaxhighlight>
</syntaxhighlight>
* '''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.


==Example==  
==Example==  
This example does...
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.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--This line does...
local myLabel = guiCreateLabel  ( 0, 0, 1, 1, "", true )
blabhalbalhb --abababa
 
--This line does this...
function addLabelOnClick ( button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement )
mooo
        --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 )
</syntaxhighlight>
</syntaxhighlight>

Revision as of 12:08, 22 October 2007

This event triggers whenever the user clicks his mouse. This is linked to the GTA world, as appose 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.


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 )