Lua 代码构建 Fortnite 问题与重复功能

Lua code Building Fortnite issues with repeat function

你好,我被要求按问题提问我的整个代码。

这段代码是我通过在我的 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?

谢谢

So how can i have both loops repeating together please?

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

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

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

谢谢 Egor,你太棒了 ;)

   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