GetCursorPosition: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 12: Line 12:


===Returns===
===Returns===
Returns 5 values: cursorX, cursorY, worldX, worldY, worldZ. The first two values are the 2D relative screen coordinates of the cursor: cursorX goes from 0 (left side of the screen) to 1 (right side), cursorY goes from 0 (top) to 1 (bottom). The 3 values that follow are the 3D world map coordinates that the cursor points at.
Returns 5 values: cursorX, cursorY, worldX, worldY, worldZ. The first two values are the 2D relative screen coordinates of the cursor: cursorX goes from 0 (left side of the screen) to 1 (right side), cursorY goes from 0 (top) to 1 (bottom). The 3 values that follow are the 3D world map coordinates that the cursor points at. If the cursor isn't showing, returns ''false'' as the first value.


==Example==
==Example==
This example prints your cursors current world coordinates and relative screen coordinates to chatbox after typing ''cursorpos''.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function cursorInfo()
function cursorInfo()
local screenx, screeny, worldx, worldy, worldz = getCursorPosition()
  local screenx, screeny, worldx, worldy, worldz = getCursorPosition()
outputChatBox("Cursor screen position: X=" .. screenx .. " Y=" .. screeny)
  if screenx then -- if the cursor is showing
outputChatBox("Cursor world position: X=" .. worldx .. " Y=" .. worldy .. " Z=" .. worldz)
      outputChatBox( string.format( "Cursor screen position (relative): X=%.4f Y=%.4f", screenx, screeny ) ) -- make the accuracy of floats 4 decimals
      outputChatBox( string.format( "Cursor world position: X=%.4f Y=%.4f Z=%.4f", worldx, worldy, worldz ) ) -- make the accuracy of floats 4 decimals accurate
  else
      outputChatBox( "Your cursor is not showing." )
  end
end
end
addCommandHandler( "cursorpos", cursorInfo )
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Client_input_functions}}
{{Client_input_functions}}
[[Category:Needs_Example]]

Revision as of 11:37, 3 April 2008

This function gets the current position of the mouse cursor.

Syntax

float float float float float getCursorPosition ( )

Required Arguments

None

Returns

Returns 5 values: cursorX, cursorY, worldX, worldY, worldZ. The first two values are the 2D relative screen coordinates of the cursor: cursorX goes from 0 (left side of the screen) to 1 (right side), cursorY goes from 0 (top) to 1 (bottom). The 3 values that follow are the 3D world map coordinates that the cursor points at. If the cursor isn't showing, returns false as the first value.

Example

This example prints your cursors current world coordinates and relative screen coordinates to chatbox after typing cursorpos.

function cursorInfo()
   local screenx, screeny, worldx, worldy, worldz = getCursorPosition()
   if screenx then -- if the cursor is showing
      outputChatBox( string.format( "Cursor screen position (relative): X=%.4f Y=%.4f", screenx, screeny ) ) -- make the accuracy of floats 4 decimals
      outputChatBox( string.format( "Cursor world position: X=%.4f Y=%.4f Z=%.4f", worldx, worldy, worldz ) ) -- make the accuracy of floats 4 decimals accurate
   else
      outputChatBox( "Your cursor is not showing." )
   end
end
addCommandHandler( "cursorpos", cursorInfo )

See Also