onClientGUIMouseDown | Multi Theft Auto: Wiki Skip to content

onClientGUIMouseDown

Client-side
Server-side
Shared

This event is fired when the user clicks certain mouse button on a GUI element.

Parameters

string button, int absoluteX, int absoluteY
  • button: the name of the mouse button that the GUI element was clicked with, can be left, right, or middle.
  • 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

element: The source of this event is the GUI element that was clicked.

Code Examples

client

This example show how to add very basicclick'n'dragfeature for GUI elements (only for those which parent element is gui-root)

addEventHandler( "onClientGUIMouseDown", root,
function ( btn, x, y )
if btn == "left" then
clickedElement = source; -- store the clicked element in a global variable
local elementPos = { guiGetPosition( source, false ) };
offsetPos = { x - elementPos[ 1 ], y - elementPos[ 2 ] }; -- get the offset position
end
end
);
addEventHandler( "onClientGUIMouseUp", root,
function ( btn, x, y )
if btn == "left" then
clickedElement = nil;
end
end
);
addEventHandler( "onClientCursorMove", root,
function ( _, _, x, y )
if clickedElement then
guiSetPosition( clickedElement, x - offsetPos[ 1 ], y - offsetPos[ 2 ], false );
end
end
);