OnClientGUIClick: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(typo) |
||
| (One intermediate revision by the same user not shown) | |||
| Line 11: | Line 11: | ||
*'''state:''' the state of the mouse button, will be ''down'' if the mouse button was pushed, or ''up'' if it was released. | *'''state:''' the state of the mouse button, will be ''down'' if the mouse button was pushed, or ''up'' if it was released. | ||
__NOTOC__ | __NOTOC__ | ||
{{New feature/item|3.0161|1.7.0|26369|'''down''' state is now supported as well.<br>To use this feature, you must also set '''< | {{New feature/item|3.0161|1.7.0|26369|'''down''' state is now supported as well.<br>To use this feature, you must also set '''<min_mta_version>''' to at least '''1.7.0-7.26369''' in '''meta.xml'''.<br>Please note that before this version only the '''up''' state worked.}} | ||
*'''absoluteX:''' the X position of the mouse cursor, in pixels, measured from the left side of the screen. | *'''absoluteX:''' the X position of the mouse cursor, in pixels, measured from the left side of the screen. | ||
*'''absoluteY:''' the Y position of the mouse cursor, in pixels, measured from the top of the screen. | *'''absoluteY:''' the Y position of the mouse cursor, in pixels, measured from the top of the screen. | ||
Latest revision as of 13:44, 10 March 2026
This event happens when any gui-element clicked.
Parameters
string button, string state, int absoluteX, int absoluteY
- button: the name of the button which will be clicked, it can be left, right, middle.
- state: the state of the mouse button, will be down if the mouse button was pushed, or up if it was released.
- absoluteX: the X position of the mouse cursor, in pixels, measured from the left side of the screen.
- absoluteY: the Y position of the mouse cursor, in pixels, measured from the top of the screen.
Source
The source of this event is the GUI element that was clicked.
Example
This example creates an edit box alongside an "Output!" button. When the button is clicked with the left mouse button, it will output the message in the edit box into the chat box.
-- When client's resource starts, create the GUI
function initGUI( )
-- Create our button
btnOutput = guiCreateButton( 0.7, 0.1, 0.2, 0.1, "Output!", true )
-- And attach our button to the outputEditBox function
addEventHandler ( "onClientGUIClick", btnOutput, outputEditBox, false )
-- Create an edit box and define it as "editBox".
editBox = guiCreateEdit( 0.3, 0.1, 0.4, 0.1, "Type your message here!", true )
guiEditSetMaxLength ( editBox, 128 ) -- The max chatbox text length is 128, so force this
end
addEventHandler( "onClientResourceStart", resourceRoot, initGUI )
-- Setup our function to output the message to the chatbox
function outputEditBox ( button )
if button == "left" then
local text = guiGetText ( editBox )-- Get the text from the edit box
outputChatBox ( text ) -- Output that text
end
end
See Also
Input
GUI
- onClientGUIAccepted
- onClientGUIBlur
- onClientGUIChanged
- onClientGUIClick
- onClientGUIComboBoxAccepted
- onClientGUIDoubleClick
- onClientGUIFocus
- onClientGUIMouseDown
- onClientGUIMouseUp
- onClientGUIMove
- onClientGUIScroll
- onClientGUISize
- onClientGUITabSwitched
- onClientMouseEnter
- onClientMouseLeave
- onClientMouseMove
- onClientMouseWheel
Client event functions
- triggerLatentServerEvent
- triggerServerEvent
- Shared
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled