OnPlayerClick: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (See Also for server events)
(Added an example.)
Line 21: Line 21:


==Example==  
==Example==  
<!-- Explain what the example is in a single sentance -->
This example outputs the state of the button they just pressed.
This example does...
<!-- Add the code below, an emphasis should be on making it clear, not optimized. You could provide two versions if you wish, one clear and well commented, the other optimized -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--This line does...
function outputClick(mouseButton,buttonState)
blah()
outputChatBox("Your "..mouseButton.." mouse button is now "..buttonState,source,255,255,0) -- output the state of the button they just pressed.
--This line does this...
end
mooo
addEventHandler("onPlayerClick",getRootElement(),outputClick) -- When a player clicks trigger the outputClick function
</syntaxhighlight>
</syntaxhighlight>


{{See also/Server event|Player events}}
{{See also/Server event|Player events}}
[[Category:Needs Example]]

Revision as of 03:44, 5 June 2010

This event is triggered when a player clicks using the mouse cursor.

Parameters

string mouseButton, string buttonState, element clickedElement, float worldPosX, float worldPosY, float worldPosZ, float screenPosX, float screenPosY
  • mouseButton: A string representing the mousebutton that was pressed. Value can be left, middle or right.
  • buttonState: A string representing the button state. Value can be up or down.
  • clickedElement: The element the player clicked on. This value is nil if none.
  • worldPosX: The X position in the world the player clicked on
  • worldPosY: The Y position in the world the player clicked on
  • worldPosZ: The Z position in the world the player clicked on
  • screenPosX: The X position on the screen the player clicked on
  • screenPosY: The Y position on the screen the player clicked on

Source

The source of this event is the player that clicked.

Example

This example outputs the state of the button they just pressed.

function outputClick(mouseButton,buttonState)
	outputChatBox("Your "..mouseButton.." mouse button is now "..buttonState,source,255,255,0) -- output the state of the button they just pressed.
end
addEventHandler("onPlayerClick",getRootElement(),outputClick) -- When a player clicks trigger the outputClick function

See Also

Player events


Event functions