How i can merge this 2 different Lua script in ONE? it is for my logitech mouse and i am not able to combine this 2 toggle script

筅森魡賤 提交于 2021-01-29 09:10:31

问题


Hello I want to combine this 2 toggle script. It is for a game. I am not good at this script and I need help for merge scripts. I would like

  • when I press G7 button
    the mouse pull down of x pixel when I press left button of mouse
  • when I press g8 button
    the mouse pull down of y pixel when I press left mouse button.

Script1

function OnEvent(event, arg)
  OutputLogMessage("event = %s, arg = %d\n", event, arg)
  if (event == "PROFILE_ACTIVATED") then
    EnablePrimaryMouseButtonEvents(true)
  elseif event == "PROFILE_DEACTIVATED" then
    ReleaseMouseButton(2) -- to prevent it from being stuck on
  end
  if (event == "MOUSE_BUTTON_PRESSED" and arg == 7) then
    recoil = not recoil
    spot = not spot
  end

  if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoil) then
    if recoil then
      repeat

        Sleep(2)
        MoveMouseRelative(-1, 1)
        Sleep(2)
        MoveMouseRelative( 0.5 , 2)
        Sleep(2)
        MoveMouseRelative( 1, 30)
        Sleep(6)

      until not IsMouseButtonPressed(1)

    end
  end
end

Script2

function OnEvent(event, arg)
  OutputLogMessage("event = %s, arg = %d\n", event, arg)
  if (event == "PROFILE_ACTIVATED") then
    EnablePrimaryMouseButtonEvents(true)
  elseif event == "PROFILE_DEACTIVATED" then
    ReleaseMouseButton(2) -- to prevent it from being stuck on
  end
  if (event == "MOUSE_BUTTON_PRESSED" and arg == 8) then
    recoil = not recoil
    spot = not spot
  end

  if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoil) then
    if recoil then
      repeat

        Sleep(2)
        MoveMouseRelative(-1, 1)
        Sleep(2)
        MoveMouseRelative( 0.5 , 2)
        Sleep(2)
        MoveMouseRelative( 1, 10)
        Sleep(6)

      until not IsMouseButtonPressed(1)

    end
  end
end

回答1:


function OnEvent(event, arg)
   OutputLogMessage("event = %s, arg = %d\n", event, arg)
   if event == "PROFILE_ACTIVATED" then
      EnablePrimaryMouseButtonEvents(true)
   elseif event == "PROFILE_DEACTIVATED" then
      ReleaseMouseButton(2) -- to prevent it from being stuck on
   elseif event == "MOUSE_BUTTON_PRESSED" and (arg == 7 or arg == 8) then     
      recoil = recoil ~= arg and arg
   elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoil == 7 then
      repeat
         Sleep(2)
         MoveMouseRelative(-1, 1)
         Sleep(2)
         MoveMouseRelative( 0.5 , 2)
         Sleep(2)
         MoveMouseRelative( 1, 30)
         Sleep(6)
      until not IsMouseButtonPressed(1)
   elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoil == 8 then
      repeat
         Sleep(2)
         MoveMouseRelative(-1, 1)
         Sleep(2)
         MoveMouseRelative( 0.5 , 2)
         Sleep(2)
         MoveMouseRelative( 1, 10)
         Sleep(6)
      until not IsMouseButtonPressed(1)
   end
end



回答2:


Not entirely certain what you are going for, but this sounds similar to what you are trying to achieve. You might need to add a few MoveMouseRelative(x, y) coordinate pairs to get it to aim right, but this should approximate the logic you're looking for.

function OnEvent( event, arg )
    OutputLogMessage( 'event = %s, arg = %d\n',  event,  arg )

    if event == 'PROFILE_ACTIVATED' then
        EnablePrimaryMouseButtonEvents( true )

    elseif event == 'PROFILE_DEACTIVATED' then
        EnablePrimaryMouseButtonEvents( false )

    --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    elseif event == 'MOUSE_BUTTON_PRESSED' and arg == 7 then
        spot = not spot  --  toggle horizontal X spot-drift by pressing button 7

    elseif event == 'MOUSE_BUTTON_PRESSED' and arg == 1 and spot then
        while IsMouseButtonPressed( 1 ) do
            MoveMouseRelative( -1, 0 )  --  left on the X axis, enable/disable with button 7
            Sleep( 2 )
        end

    --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    elseif event == 'MOUSE_BUTTON_PRESSED' and arg == 8 then
        recoil = not recoil  --  toggle vertical Y recoil-compensation by pressing button 8

    elseif event == 'MOUSE_BUTTON_PRESSED' and arg == 1 and recoil then
        while IsMouseButtonPressed( 1 ) do
            MoveMouseRelative( 0, 1 )  --  down on the Y axis, enable/disable with button 8
            Sleep( 2 )
        end
    end
end


来源:https://stackoverflow.com/questions/64932181/how-i-can-merge-this-2-different-lua-script-in-one-it-is-for-my-logitech-mouse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!