Skip to content

OnCursorClick

A mouse button was pressed while the player’s cursor is up.

Every press of the left, right or middle button while the cursor is up, with the pointer’s place in the UI space (GetScreenSize: 1080 rows high, the width following the screen’s shape) - the same space CreateUiRect and CreateUiText place things in, so a script can tell which of its own elements was clicked. The click is only observed: it also reaches what is on screen under the pointer - unless the script holds the mouse (SetMouseCapture). OnMouseButton hears the releases too.

function OnCursorClick(button, x, y)
-- ...
end
Parameter Type
button string "left", "right" or "middle"
x number the pointer’s place across, in the UI space
y number the pointer’s place down, in the UI space (0 at the top, 1080 at the bottom)

nothing

-- a button of the script's own at 100, 900, 200 wide and 60 high
CreateUiRect("door_btn", 100, 900, 200, 60, 0x302010, 80)
CreateUiText("door_txt", 200, 915, "Knock", COLOR_GOLD, 1, UI_ALIGN_CENTRE)
function OnCursorClick(button, x, y)
if button == "left" and x >= 100 and x <= 300 and y >= 900 and y <= 960 then
SendServerEvent("door.knock", "")
end
end

OnMouseButton · OnCursorChange · IsCursorShown · the The game’s UI for a script group of the index