【问题标题】:How can I make this no recoil script do an additional movement of my mouse?我怎样才能让这个无后坐力脚本额外移动我的鼠标?
【发布时间】:2021-04-02 16:42:05
【问题描述】:

我是脚本新手,不知道自己在做什么。在网上找到下面的代码,希望它做出调整。所以基本上,在辐射 4 中,假设枪的后坐力最初是向上和向左移动,但在射击中途它会向右移动。我希望脚本最初能够将鼠标向下和向右拉,然后(当枪的后坐力开始朝另一个方向移动时)向左移动。这可能吗?


EnablePrimaryMouseButtonEvents (true);

function OnEvent(event,arg)
   if IsKeyLockOn("numlock")then
      if IsMouseButtonPressed(3)then
         repeat
            if IsMouseButtonPressed(1) then
               repeat
                  MoveMouseRelative(-1,13)
                  Sleep(75)
               until not IsMouseButtonPressed(1)
            end
         until not IsMouseButtonPressed(3)
      end
   end
end

上面是我在《辐射 4》中按下射击按钮时用来向下移动鼠标的脚本,因为我遇到了一些问题,无法应对后坐力。

我希望脚本不仅向下移动并稍微向左移动 (MoveMouseRelative(-1,13)),而且我希望能够指定在一定时间后,然后我希望脚本移入另一个方向,我可以再次指定。

我该怎么做?我相信这是一个 LUA 脚本之类的,我使用的是罗技鼠标

【问题讨论】:

    标签: lua scripting mouse logitech-gaming-software aim


    【解决方案1】:
    EnablePrimaryMouseButtonEvents(true)
    
    function OnEvent(event, arg)
    
       if event == "MOUSE_BUTTON_PRESSED" and arg == 1 and IsMouseButtonPressed(3) and IsKeyLockOn("numlock") then
          -- first group of moves: 10 steps in direction (-1,13), total group time = 750 ms
          for i = 1, 10 do
             MoveMouseRelative(-1,13)
             Sleep(75)
             if not IsMouseButtonPressed(1) then return end
          end
          -- second group of moves: 5 steps in direction (1,12), total group time = 375 ms
          for i = 1, 5 do
             MoveMouseRelative(1,12)
             Sleep(75)
             if not IsMouseButtonPressed(1) then return end
          end
          -- you can add more groups
       end
    
       if event == "MOUSE_BUTTON_PRESSED" and arg == 1 and IsMouseButtonPressed(3) and IsKeyLockOn("scrolllock") then
          -- first group of moves: 10 steps in direction (-1,13), total group time = 750 ms
          for i = 1, 10 do
             MoveMouseRelative(-1,13)
             Sleep(75)
             if not IsMouseButtonPressed(1) then return end
          end
          -- second group of moves: 5 steps in direction (1,12), total group time = 375 ms
          for i = 1, 5 do
             MoveMouseRelative(1,12)
             Sleep(75)
             if not IsMouseButtonPressed(1) then return end
          end
          -- you can add more groups
       end
    
    end
    

    更新:

    第 0 步。
    您即将修改鼠标左键的行为。
    这是一个潜在的危险操作:没有 LMB,您几乎无法在计算机上执行任何操作。
    所以你必须创建一个“备用 LMB”。
    例如,如果您不使用 Mouse Button 8,您可以让它在 LMB 上像克隆一样。
    转到 LGS 中的大鼠标图片并将命令“左键单击”分配给您的物理 MB#8。
    现在,如果出现问题并且您的 LMB 停止工作,您可以按 MB#8 而不是 LMB。


    第 1 步。
    你在游戏中使用鼠标键 4(“返回”)吗?

    • 如果是(游戏中某些动作设置为 MB#4),请继续执行“步骤 2”。
    • 如果否(游戏忽略 MB#4 按下),请跳过“步骤 2”并继续执行“步骤 3”。

    第 2 步。
    您必须将游戏动作从 MB#4 重新映射到其他键。
    执行以下操作:

    • 选择您当前未在游戏中使用的键盘键
      (假设当前未使用 F12 键)
    • 转到 LGS 中的大鼠标图片并将命令 F12 分配给您的物理 MB#4
    • 转到您的游戏设置并将游戏操作设置为 F12 而不是 MB#4

    因此,当您按下物理 MB#4 时,游戏会收到 F12 并激活游戏动作。
    现在跳过“第 3 步”并继续“第 4 步”。


    第 3 步。
    转到LGS中的大鼠标图片。
    从物理 MB#4 中取消分配标准命令“Back”(从下拉菜单中选择“Unassign”)。


    第 4 步。
    设置脚本(见下文)。


    第 5 步。
    转到LGS中的大鼠标图片。
    将命令“返回”分配给您的物理 LMB。
    您将看到有关潜在危险操作的警告。
    允许此操作,因为如果出现问题,您有“备用 LMB”。

    
    -- rapid fire (CAPSLOCK) is independent from anti-recoil (NUMLOCK and SCROLLLOCK)
    
    local rapid_fire_interval = 30  -- milliseconds between LMB press/release simulation
    
    local LMB_down, rapid_fire, prev_time, next_LMB_time
    
    local function PressOrReleaseLMB(only_release)
       if LMB_down then
          ReleaseMouseButton(1)
          LMB_down = false
       elseif not only_release then
          PressMouseButton(1)
          LMB_down = true
       end
    end
    
    local function Sleep_with_rapid_fire(ms)
       -- returns true if LMB was released by user
       prev_time = prev_time + ms
       while GetRunningTime() < prev_time do
          Sleep(10)
          if not IsMouseButtonPressed(4) then
             return true
          end
          while rapid_fire and GetRunningTime() >= next_LMB_time then
             next_LMB_time = next_LMB_time + rapid_fire_interval
             PressOrReleaseLMB()  -- press LMB (if it's up) or release LMB (if it's down)
          end
       end
    end
    
    function OnEvent(event, arg)
       if event == "PROFILE_ACTIVATED" then
          EnablePrimaryMouseButtonEvents(true)
       elseif event == "PROFILE_DEACTIVATED" or event == "MOUSE_BUTTON_RELEASED" and arg == 1 then
          PressOrReleaseLMB(true)  -- release LMB
       elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 then
          PressOrReleaseLMB()  -- press LMB
          prev_time = GetRunningTime()
          next_LMB_time = prev_time + rapid_fire_interval
          rapid_fire = IsKeyLockOn("capslock")
          if IsMouseButtonPressed(3) then  -- RMB pressed
             if IsKeyLockOn("numlock") then
    
                -- first group of moves: 10 steps in direction (-1,13), total group time = 750 ms
                for i = 1, 10 do
                   MoveMouseRelative(-1,13)
                   if Sleep_with_rapid_fire(75) then return end
                end
                -- second group of moves: 5 steps in direction (1,12), total group time = 375 ms
                for i = 1, 5 do
                   MoveMouseRelative(1,12)
                   if Sleep_with_rapid_fire(75) then return end
                end
                -- you can add more groups
    
             elseif IsKeyLockOn("scrolllock") then
    
                -- first group of moves: 10 steps in direction (-1,13), total group time = 750 ms
                for i = 1, 10 do
                   MoveMouseRelative(-1,13)
                   if Sleep_with_rapid_fire(75) then return end
                end
                -- second group of moves: 5 steps in direction (1,12), total group time = 375 ms
                for i = 1, 5 do
                   MoveMouseRelative(1,12)
                   if Sleep_with_rapid_fire(75) then return end
                end
                -- you can add more groups
    
             end
          end
          Sleep_with_rapid_fire(math.huge)  -- until user released LMB
       end
    end
    

    【讨论】:

    • “for i = 1, 10 do”部分是什么意思?我将如何进行更改?比如说 2 秒内我希望鼠标向下拉,然后 2 秒后我希望它向上拉?
    • What does the "for i = 1, 10 do" part mean? - 意思是“重复 10 次”。 10*75 = 750ms如果需要2秒,试试27*75
    • MoveMouseRelative(0,12) - 向下,MoveMouseRelative(0,-12) - 向上
    • 我只想说我真的很感谢你的帮助,所以对于任何愚蠢的问题哈哈!如何让脚本无限地继续最后一个“MoveMouseRelative”,直到我松开鼠标 1 和 3 按钮?在原始脚本中,我让 MoveMouseRelative 永远持续下去,直到我改变了松开鼠标 1 和 3,这也是我想在这里实现的目标
    • How would I make the script just continue the very last 'MoveMouseRelative' infinitely - 设置非常大的循环限制,例如,for i = 1, 1000000 do
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-14
    • 2021-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多