getCursorPosition
Client-side
Server-side
Shared
Pair: setCursorPosition
This function gets the current position of the mouse cursor.
Note
- If you want the exact world point (similar to onClientClick), use processLineOfSight between the camera position and the world x/y/z result of this function.
- For performance reasons, the world position returned is always 300 units away.
Syntax
float|false, float, float, float, float getCursorPosition ( )Returns
Returns 5 values: cursorX, cursorY, worldX, worldY, worldZ. The first two values are the 2D relative screen coordinates of the cursor. The last 3 values are the 3D world map coordinates that the cursor points at. If the cursor isn't showing, returns false as the first value.
- float|false: cursorX
- float: cursorY
- float: worldX
- float: worldY
- float: worldZ
Code Examples
client
This example prints your cursors current world coordinates and relative screen coordinates to chatbox after using /cursorpos command.
function cursorInfo() -- is the cursor showing? if isCursorShowing() then -- get the cursor postion local screenx, screeny, worldx, worldy, worldz = getCursorPosition()
-- make the accuracy of floats 4 decimals and print to chatbox outputChatBox(string.format("Cursor screen position (relative): X=%.4f Y=%.4f",screenx, screeny)) outputChatBox(string.format("Cursor world position: X=%.4f Y=%.4f Z=%.4f", worldx,worldy, worldz)) else outputChatBox("Your cursor is not showing.") endendaddCommandHandler("cursorpos", cursorInfo)