如何将这两个不同的Lua脚本合并成一个?这是为我的罗技鼠标而设计的,我无法结合这两个切换脚本

大家好,我想将这两个切换脚本合并成一个。这是为了一个游戏。我对这个脚本不熟悉,需要合并脚本的帮助。我希望

  • 当我按下G7按钮时

    当我按下鼠标左键时,鼠标向下拽动x像素

  • 当我按下g8按钮时

    当我按下鼠标左键时,鼠标向下拽动y像素。

脚本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
  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

脚本2

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
点赞
用户1847592
用户1847592
   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

将上面的代码翻译成中文并保留原本的 markdown 格式,

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)
   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
2020-11-20 19:29:21
用户3342050
用户3342050

我不是完全确定你要做什么,但这听起来和你试图实现的很相似。你可能需要添加一些 MoveMouseRelative(x, y) 坐标对来使其正确瞄准,但这应该近似于你要寻找的逻辑。

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  --  通过按下按钮7来切换水平X点漂移

    elseif event == 'MOUSE_BUTTON_PRESSED' and arg == 1 and spot then
        while IsMouseButtonPressed( 1 ) do
            MoveMouseRelative( -1, 0 )  --  在X轴上左移,通过按钮7来启用/禁用
            Sleep( 2 )
        end

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

    elseif event == 'MOUSE_BUTTON_PRESSED' and arg == 8 then
        recoil = not recoil  --  通过按下按钮8来切换垂直Y方向反冲补偿

    elseif event == 'MOUSE_BUTTON_PRESSED' and arg == 1 and recoil then
        while IsMouseButtonPressed( 1 ) do
            MoveMouseRelative( 0, 1 )  --  在Y轴上向下移动,通过按钮8来启用/禁用
            Sleep( 2 )
        end
    end
end 
2020-11-20 19:33:32