Jump to content

getCursorMoveOn


Xwad

Recommended Posts

Posted

Why is ths code not working? i got it from the wiki:

https://wiki.multitheftauto.com/wiki/GetCursorMoveOn

debugscript:

ERROR: attempt to concatenate global 'moveOn (a nil value)

bad Argumentum outpuChatBox expected number at argument 2, got player

code client side

function getCursorMoveOn() 
    if ( isCursorShowing() ) then 
    left = "left" 
    right = "right" 
    up = "up" 
    down = "down" 
    zero = "nil" 
    if getElementData(localPlayer,"movew") == right then 
    return right 
    elseif getElementData(localPlayer,"movew") == left then 
    return left 
    elseif getElementData(localPlayer,"movew") == up then 
    return up 
    elseif getElementData(localPlayer,"movew") == down then 
    return down 
    elseif getElementData(localPlayer,"movew") == zero then 
    return false 
    end 
    end 
end 
  
function executeMoveOn(cursorX,cursorY) 
    if ( isCursorShowing() ) then 
    setElementData(localPlayer,"moveX",cursorX) 
    setElementData(localPlayer,"moveY",cursorY) 
         if cursorX > cX then 
         setElementData(localPlayer,"movew",right) 
         elseif cursorX < cX then 
         setElementData(localPlayer,"movew",left) 
         elseif cursorY > cY then 
         setElementData(localPlayer,"movew",down) 
         elseif cursorY < cY then 
         setElementData(localPlayer,"movew",up) 
         end 
    end 
end 
addEventHandler("onClientCursorMove",root,executeMoveOn) 
  
setTimer( 
function() 
    if ( isCursorShowing() ) then 
    local curX = getElementData(localPlayer,"moveX") 
    local curY = getElementData(localPlayer,"moveY") 
         if cursorX == cX then 
         setElementData(localPlayer,"movew",zero) 
         elseif cursorY == cY then 
         setElementData(localPlayer,"movew",zero) 
         end 
    end 
end 
,50,0) 
  
function previousM() 
   if ( isCursorShowing() ) then 
    cX = getElementData(localPlayer,"moveX") 
    cY = getElementData(localPlayer,"moveY") 
   end 
end 
setTimer(previousM,50,0) 
  
  
  
  
  
bindKey ("m", "down", 
function() 
showCursor( not isCursorShowing() ) 
end 
) 
  
addEventHandler("onClientCursorMove",root, 
function() 
    if ( isCursorShowing() ) then 
    moveOn = getCursorMoveOn() 
    outputChatBox("cursor is moving on : " .. moveOn, localPlayer) 
    end 
end 
) 
  
  
  

Posted

First error is caused by the function getCursorMoveOn, as it does not return any value in case isCursorShowing() returns false at line 2. Second error is because outputChatBox only accepts a player as second argument server-side (visibleTo), whilst client does not and thus expects a number (r).

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...