GetCursorMovedOn: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
{{Useful Function}}
{{Useful Function}}
__NOTOC__
__NOTOC__
This function checks in which way the cursor is currently moving.
This function checks in which way the cursor is currently moving, it's updated version of https://wiki.multitheftauto.com/wiki/GetCursorMoveOn.
==Syntax==
==Syntax==
<syntaxhighlight lang="lua">string getCursorMoveOn( )</syntaxhighlight>
<syntaxhighlight lang="lua">string getCursorMoveOn( )</syntaxhighlight>
Line 22: Line 22:
end
end


function onClientCursorMove(cursorX, cursorY)
function onClientCursorMoved(cursorX, cursorY)
     if not isCursorShowing() then return end
     if not isCursorShowing() then return end



Revision as of 17:09, 20 November 2017


This function checks in which way the cursor is currently moving, it's updated version of https://wiki.multitheftauto.com/wiki/GetCursorMoveOn.

Syntax

string getCursorMoveOn( )

Returns

Returns "left", "right", "up" or "down", "nil" if cursor didn't move.

Code

Click to collapse [-]
Function source
local cP = {
    x = 0,
    y = 0,
    move = nil,
    timer = false,
}

function getCursorMoveOn()
    return cP.move
end

function onClientCursorMoved(cursorX, cursorY)
    if not isCursorShowing() then return end

	if cursorX > cP.x then
            cP.move = "right"
	elseif cursorX < cP.x then
	    cP.move = "left"
	elseif cursorY > cP.y then
	    cP.move = "up"
	elseif cursorY < cP.y then
	    cP.move = "down"
        end
	
	cP.x = cursorX
	cP.y = cursorY
	
	
	if isTimer(cP.timer) then
	    killTimer(cP.timer)
	end
	
	cP.timer = setTimer(
	    function ()
		cP.move = "nil"
	    end, 50, 1
	)
end
addEventHandler("onClientCursorMove",root,onClientCursorMove)