GetCursorMovedOn

From Multi Theft Auto: Wiki
Revision as of 17:08, 20 November 2017 by J.Chaikos (talk | contribs)
Jump to navigation Jump to search


This function checks in which way the cursor is currently moving.

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 onClientCursorMove(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)