如何将两个 Lua 脚本结合起来?

我正在试图找到一种将这两个脚本结合起来的方法:

    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)  -- 防止它被卡住
      end
      if (event == "MOUSE_BUTTON_PRESSED" and arg == 5) then
        recoilx2 = not recoilx2
        spot = not spot
      end
      if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoilx2) then
        if recoilx2 then
          repeat
            MoveMouseRelative(0, 25)
            Sleep(1000)
          until not IsMouseButtonPressed(1)
        end
      end

      if IsMouseButtonPressed(1) then
        repeat
          PressMouseButton(1)
          Sleep(15)
          ReleaseMouseButton(1)
        until not IsMouseButtonPressed(1)
      end
    end

当我按下鼠标 5 激活第一段时,底部的重复单击部分不起作用。

点赞
用户2858170
用户2858170

当我按鼠标5键激活第一部分时,底部的重复点击部分不起作用。

当您第一次按下按钮5时,您会进入此条件语句

if (event == "MOUSE_BUTTON_PRESSED" and arg == 5) then
  recoilx2 = not recoilx2
  spot = not spot
end

这将将 true 分配给 recoilx2

在此之后,当您按下按钮1时,您将进入此条件语句:

if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoilx2) then
  if recoilx2 then
    repeat
      MoveMouseRelative(0, 25)
      Sleep(1000)
    until not IsMouseButtonPressed(1)
  end
end

在这里,您要等待直到按钮1不再被按下。

除非您再次按下按钮5以将 false 分配给 recoilx2,否则每次按下按钮1时都会进入此条件语句,并一直停留在那里,直到您松开按钮1。

因此,您永远无法进入此条件语句。

if IsMouseButtonPressed(1) then
  repeat
    PressMouseButton(1)
    Sleep(15)
    ReleaseMouseButton(1)
  until not IsMouseButtonPressed(1)
end
2020-03-04 09:43:47