You can use this simple function:
function isMouseInPosition ( x, y, width, height )
if ( not isCursorShowing ( ) ) then
return false
end
local sx, sy = guiGetScreenSize ( ) -- Get the player screen resolution
local cx, cy = getCursorPosition ( ) -- Get the cursor position
local cx, cy = ( cx * sx ), ( cy * sy ) -- Convert relative positions to absolute
if ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) then
return true
else
return false
end
end
Example:
addEventHandler ( "onClientRender", root,
function ( )
local color = tocolor ( 0, 0, 0 )
if isMouseInPosition ( 200, 200, 50, 50 ) then
color = tocolor ( 255, 0, 0 )
end
dxDrawRectangle ( 200, 200, 50, 50, color )
end
)