【问题标题】:Lua code Building Fortnite issues with repeat functionLua 代码使用重复功能构建 Fortnite 问题
【发布时间】:2021-12-12 14:30:56
【问题描述】:

您好,我被问到我在整个代码中遇到的问题。

这个代码是我在 G502 Lightspeed 上按下 MB4 和 MB5 来建造墙壁和地板的代码:

----------------
-- Boutton 4 sol ou sol et toit - MB4 floor or floor and roof
----------------

                if (event == "MOUSE_BUTTON_PRESSED" and arg == 4) then
                  PlayMacro("PlusReso")

                  if not IsMouseButtonPressed(3) then
                    FastSleep(1)
                    PressAndReleaseKey("F2")-- Sol - Floor
                       FastSleep(1)
                    PressKey("F6")-- Construire - Place Building
                       FastSleep(1)

                  end

                  if IsMouseButtonPressed(3) then
                    PressAndReleaseKey(7)
                    FastSleep(1)
                    -- Petite Boucle - Little Loop
                    for i=1, 20 do
                    for j=1, 5 do
                    PressAndReleaseKey("F4")-- Toit - Roof
                       FastSleep(1)
                    PressKey("F6")-- Construire - Place Building
                       FastSleep(1)
                    end
                    for j=1, 5 do
                    PressAndReleaseKey("F2")-- Sol - Floor
                       FastSleep(1)
                    PressKey("F6")-- Construire - Place Building
                       FastSleep(1)
                    end
                    end

                  end

                  elseif (event == "MOUSE_BUTTON_RELEASED" and arg == 4) then
                    if not IsMouseButtonPressed(5) then
                    ReleaseKey("F6")
                    PressAndReleaseKey(7) -- Alterner les raccourcis - Switch Quickbar
                    PlayMacro("MoinsReso")
                    end

                end

----------------
-- Boutton 5 mur ou sol et mur - MB5 wall or wall and floor
----------------

                if (event == "MOUSE_BUTTON_PRESSED" and arg == 5) then
                    PlayMacro("PlusReso")

                    if IsMouseButtonPressed(4) then
                    repeat
                    FastSleep(1)
                    PressAndReleaseKey("F2")-- Sol - Floor
                    FastSleep(1)
                    PressKey("F6")-- Construire - Place Building
                    FastSleep(1)

                    FastSleep(1)
                    PressAndReleaseKey("F1")-- Mode construction Mur
                    FastSleep(1)
                    PressKey("F6")-- Construire - Place Building
                    FastSleep(1)
                    until not IsMouseButtonPressed(4)
                    ReleaseKey("F6")
                    PressAndReleaseKey(7) -- Alterner les raccourcis - Switch Quickbar
                    end

                    if not IsMouseButtonPressed(4) then
                    repeat
                    FastSleep(1)
                    PressAndReleaseKey("F1")-- Mode construction Mur
                    FastSleep(1)
                    PressKey("F6")-- Construire - Place Building
                    FastSleep(1)
                    until not IsMouseButtonPressed(5)
                    if not IsMouseButtonPressed(4) then
                    ReleaseKey("F6")-- Construire - Place Building
                    PressAndReleaseKey(7) -- Alterner les raccourcis - Switch Quickbar
                    PlayMacro("MoinsReso")
                    end
                    end
                end
            

我的第一个代码更简单,在 MB4 和 MB5 上重复循环,但是当两者都被按下时,它们不能一起工作。

类似这样的:

如果按下 MB4 重复地板建造 直到没有按下 MB4

如果按下 MB 重复地板建造 直到没有按下 MB5

在此之前,我只是在 MB4 和 MB5 上使用宏来构建。很好,但是当我快速移动鼠标时,有些墙壁或地板没有建成。 Lua 让我拥有非常快速的构建体验。

那么我怎样才能让两个循环一起重复呢?我错过了什么?

第二个问题是宏观增减dpi(PlusReso和MoinsReso)。它工作得很好,但有时我在释放所有鼠标按钮后仍然卡在高 dpi 中,无法瞄准。

我们是否可以编写一个简单的代码来增加和减少 dpi,而不使用宏,并确保在释放一个或几个按钮后不会仍然停留在高 dpi?

谢谢

【问题讨论】:

  • PlusResoMoinsReso 是如何定义的?
  • 它们是罗技 Ghub 上的宏,未绑定到任何按钮。宏的工作很简单。 PlusReso 只是增加 DPI 而 MoinsReso 减少它。我的默认 DPI 设置为 800,而我的鼠标上只有另一个定义为 3000。
  • 尝试在PlayMacro("MoinsReso")前后插入Sleep(30)
  • @EgorSkriptnuff 感谢您提供以下代码。起初它不起作用,但突然它起作用了。不要问我为什么。好消息是无论首先按下哪个按钮,墙壁和地板都可以非常快速地构建在一起。带屋顶的人民币也是如此。
  • 请帮助我理解=为什么在脚本开头而不是在脚本末尾使用本地?我试图将楼梯添加到您的代码中,但本地 MB6 = IsMouseButtonPressed(6) 给出错误(我知道但我尝试过)并且本地 MB6 = (event == "MOUSE_BUTTON_PRESSED" and arg == 6) 不起作用。你猜我的楼梯是MB6,不能改变。谢谢

标签: lua macros logitech-gaming-software


【解决方案1】:

那么我怎样才能让两个循环一起重复呢?

if event == "MOUSE_BUTTON_PRESSED" and (arg == 4 or arg == 5) then
   Sleep(10)
   local MB4 = IsMouseButtonPressed(4)
   local MB5 = IsMouseButtonPressed(5)
   if MB4 or MB5 then
      PlayMacro("PlusReso")
      repeat
         local RMB = IsMouseButtonPressed(3)

         if MB4 then
            PressAndReleaseKey("F2")-- Sol - Floor
            FastSleep(1)
            PressKey("F6")-- Construire - Place Building
            FastSleep(1)
         end

         if MB5 then
            PressAndReleaseKey("F1")-- Mode construction Mur
            FastSleep(1)
            PressKey("F6")-- Construire - Place Building
            FastSleep(1)
         end

         if RMB then
            PressAndReleaseKey("F4")-- Toit - Roof
            FastSleep(1)
            PressKey("F6")-- Construire - Place Building
            FastSleep(1)
         end

         MB4 = IsMouseButtonPressed(4)
         MB5 = IsMouseButtonPressed(5)
      until not (MB4 or MB5)
      ReleaseKey("F6")
      PressAndReleaseKey(7) -- Alterner les raccourcis - Switch Quickbar
      PlayMacro("MoinsReso")
   end
end

【讨论】:

    【解决方案2】:

    这是最终代码。我使用了“rctrl”,它工作得几乎完美、快速且在构建过程中没有任何问题。 当按下 RMB 时,我在 MB4 和 MB6 上添加了几个动作,通过按下或不按下 RMB,每个鼠标按钮给我两个动作。 我必须使用 RMB 向 MB5 添加相同的操作,否则我遇到了停止循环或 DPI 问题之类的问题!如果需要,我可以在此处执行其他操作。

    唯一的问题是,有时我在使用我的其余代码进行编辑时仍然停留在高 DPI(在游戏中比在 creatif 中更常见),但这是另一个问题。

    感谢叶戈尔,你摇滚;)

       if event == "MOUSE_BUTTON_PRESSED" and (arg == 4 or arg == 5 or arg == 6) then
       
            FastSleep(10)
            local MB4 = IsMouseButtonPressed(4)
            local MB5 = IsMouseButtonPressed(5)
            local MB6 = IsModifierPressed("rctrl")
       
           if MB4 or MB5 or MB6 then
              PlayMacro("PlusReso")
            repeat
                local RMB = IsMouseButtonPressed(3)
    
                if MB4 then
                    PressAndReleaseKey("F2")-- Sol - Floor
                    FastSleep(1)
                    PressKey("F6")-- Construire - Place Building
                    FastSleep(1)
                end
    
                if MB5 then
                    if not RMB then
                    PressAndReleaseKey("F1")-- Mur - Wall
                    FastSleep(1)
                    PressKey("F6")-- Construire - Place Building
                    FastSleep(1)
                    end
                end
             
                if MB6 then
                    PressAndReleaseKey("F3")-- Escalier - Stair
                    FastSleep(1)
                    PressKey("F6")-- Construire - Place Building
                    FastSleep(1)
                end
    
                if RMB and MB4 then
                    PressAndReleaseKey("F4")-- Toit - Roof
                    FastSleep(1)
                    PressKey("F6")-- Construire - Place Building
                    FastSleep(1)
                end
                
                if RMB and MB5 then
                    PressAndReleaseKey("F1")-- Mur - Wall
                    FastSleep(1)
                    PressKey("F6")-- Construire - Place Building
                    FastSleep(1)
                end
                
                if RMB and MB6 then
                    PressAndReleaseKey("F3")-- Escalier - Stair
                    FastSleep(1)
                    PressKey("F6")-- Construire - Place Building
                    FastSleep(1)
                    
                    PressAndReleaseKey("F4")-- Toit - Roof
                    FastSleep(1)
                    PressKey("F6")-- Construire - Place Building
                    FastSleep(1)
                    
                    PressAndReleaseKey("F2")-- Sol - Floor
                    FastSleep(1)
                    PressKey("F6")-- Construire - Place Building
                    FastSleep(1)
                    
                end
                
                    MB4 = IsMouseButtonPressed(4)
                    MB5 = IsMouseButtonPressed(5)
                    MB6 = IsModifierPressed("rctrl")
                    
              until not (MB4 or MB5 or MB6)
                ReleaseKey("F6")
                PressAndReleaseKey(7) -- Alterner les raccourcis - Switch Quickbar
                PlayMacro("MoinsReso")
           end
        end
    

    【讨论】:

    • 嗨。我仍在尝试使用此代码改进 DPI 问题。没有任何工作。我希望能起作用的一件事是从我的脚本中删除 => PlayMacro("PlusReso") 和 PlayMacro("MoinsReso") 并创建一个向上(按下时)和向下(释放时)我的 DPI 的宏并将其绑定到我需要的每个按钮。问题是当宏在 G4、5 或 6 上绑定时,lua 脚本不再起作用。好像它没有看到这些按钮中的任何一个被按下!任何帮助请让宏和lua一起工作。
    猜你喜欢
    • 2021-12-13
    • 1970-01-01
    • 2015-02-21
    • 1970-01-01
    • 2017-02-07
    • 1970-01-01
    • 2021-12-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多