【问题标题】:How to add a table using Lua如何使用 Lua 添加表格
【发布时间】:2022-06-16 06:41:52
【问题描述】:

软件 = 罗技 G 集线器

我是 Lua 的新手,我很难找到与我想要完成的任务直接相关的信息。

我正在尝试为我喜欢玩的游戏编写一个反冲脚本,但更重要的是同时实际学习一些新东西。

我已经设置了一个功能,当我想使用的枪被激活/停用的输出消息时显示。我还做了一个修改器,设置为 Left Ctrl 以补偿蹲伏与站立时较低的后坐力。

后坐力模式基本上是下降,然后向左下降,然后再次下降并回到左侧。

我尝试使用 MoveMouseRelative,但它只会将鼠标拉到我写的最后一个数字,例如 (-2,0)。

我怎样才能使它遵循一个模式?比如向下 1 秒,然后对角线 1 秒,依此类推......

我还想在我的脚本中添加 x 和 y 表,而不是逐行添加 MoveMouseRelative 但真的不知道。

---GUN MODES---
local AK47_ = 8
local AK47_Keyboard = nil


---RECOIL TABLES---
local recoil_table = {}

recoil_table["AK47"] = {
    basic = {20,20,20,20}
}



EnablePrimaryMouseButtonEvents(true);
local recoil = falseB
local weapon = 0
function OnEvent(event, arg)    
if (event == "MOUSE_BUTTON_PRESSED" and arg == AK47_) or
(event == "G_PRESSED" and arg == AK47_Keyboard) then
    recoil = not recoil
    weapon = arg
    if (recoil == false) then
      OutputLogMessage("OFF-Macro-AK47\n")
      if IsKeyLockOn("numlock") then
        PressAndReleaseKey("numlock")
      end
    else
      OutputLogMessage("ON-NoRecoil-AK47\n")
      if not IsKeyLockOn("numlock") then
        PressAndReleaseKey("numlock")
end
end


    elseif  weapon == AK47_ or weapon == AK47_Keyboard then if recoil ==true then
        if(IsModifierPressed("lctrl"))then
                AK47crouch()
            else
        AK47()
            end
end 

------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------

function AK47()
        if IsMouseButtonPressed(3) then
            repeat
        if IsMouseButtonPressed(1) then
            repeat
                MoveMouseRelative(-2, 4)
                Sleep(10)
                until not IsMouseButtonPressed(1)
            end

            until not IsMouseButtonPressed(3)
        end
    

end
end

function AK47crouch()
    if IsMouseButtonPressed(3) then
                    Sleep(20)
                repeat
            if IsMouseButtonPressed(1) then
                repeat
                Sleep(19)
                MoveMouseRelative(0,2)
                until not IsMouseButtonPressed(1)
                end

                until not IsMouseButtonPressed(3)
            end
end
end

【问题讨论】:

    标签: lua scripting macros logitech-gaming-software


    【解决方案1】:

    你应该使用函数GetRunningTime()来检查是否是时候改变反冲方向了。

    ---GUN MODES---
    local AK47_Mouse = 8
    local AK47_Keyboard = nil
    
    ------------- for adding another weapon -----------
    local AnotherWeapon_Mouse = 7
    local AnotherWeapon_Keyboard = nil
    ---------------------------------------------------
    
    local SpeedX2Modifier_Mouse = nil
    local SpeedX2Modifier_Keyboard = 1   -- key G1
    local SpeedX2 = false
    
    
    ---RECOIL TABLES---
    local recoil_table = {}
    
    recoil_table["AK47"] = {
       -- down for 1 second
       0, 0.5, 1000,  -- delta_x_per_10ms, delta_y_per_10ms, duration_in_ms
       -- diagonal for 1 second
       -2, 4, 1000,
       -- it stops moving after 2 seconds (even if LMB is still pressed)
    }
    
    recoil_table["AK47_crouch"] = {
       -- down forever (until LMB is released)
       0, 2, math.huge,  -- math.huge means "very big number of ms"
    }
    
    
    ------------- for adding another weapon -----------
    recoil_table["AnotherWeapon"] = {
       -- down for 1 second
       0, 0.5, 1000,  -- delta_x_per_10ms, delta_y_per_10ms, duration_in_ms
       -- diagonal for 1 second
       -2, 4, 1000,
       -- it stops moving after 2 seconds (even if LMB is still pressed)
    }
    
    recoil_table["AnotherWeapon_crouch"] = {
       -- down forever (until LMB is released)
       0, 2, math.huge,  -- math.huge means "very big number of ms"
    }
    ---------------------------------------------------
    
    local weapon
    
    function OnEvent(event, arg)
       if event == "PROFILE_ACTIVATED" then
          EnablePrimaryMouseButtonEvents(true)
       elseif (event == "MOUSE_BUTTON_PRESSED" and arg == AK47_Mouse) or (event == "G_PRESSED" and arg == AK47_Keyboard) then
          weapon = weapon ~= "AK47" and "AK47"
          if not weapon then
             OutputLogMessage("OFF-Macro-AK47\n")
             if IsKeyLockOn("numlock") then
                PressAndReleaseKey("numlock")
             end
          else
             OutputLogMessage("ON-NoRecoil-AK47\n")
             if not IsKeyLockOn("numlock") then
                PressAndReleaseKey("numlock")
             end
          end
       ------------- for adding another weapon -----------
       elseif (event == "MOUSE_BUTTON_PRESSED" and arg == AnotherWeapon_Mouse) or (event == "G_PRESSED" and arg == AnotherWeapon_Keyboard) then
          weapon = weapon ~= "AnotherWeapon" and "AnotherWeapon"
          if not weapon then
             OutputLogMessage("OFF-Macro-AnotherWeapon\n")
             if IsKeyLockOn("numlock") then
                PressAndReleaseKey("numlock")
             end
          else
             OutputLogMessage("ON-NoRecoil-AnotherWeapon\n")
             if not IsKeyLockOn("numlock") then
                PressAndReleaseKey("numlock")
             end
          end
       ---------------------------------------------------
       elseif (event == "MOUSE_BUTTON_PRESSED" and arg == SpeedX2Modifier_Mouse) or (event == "G_PRESSED" and arg == SpeedX2Modifier_Keyboard) then
          SpeedX2 = not SpeedX2
          if not SpeedX2 then
             OutputLogMessage("OFF-SpeedX2\n")
          else
             OutputLogMessage("ON-SpeedX2\n")
          end
        elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 and weapon and IsMouseButtonPressed(3) then
          local recoil_sequence = recoil_table[weapon..(IsModifierPressed("lctrl") and "_crouch" or "")] or {}
          local x, y, tm = 0, 0, GetRunningTime()
          for j = 3, #recoil_sequence, 3 do
             local dx_10ms = recoil_sequence[j-2]
             local dy_10ms = recoil_sequence[j-1]
             if SpeedX2 then
                dx_10ms = dx_10ms * 2
                dy_10ms = dy_10ms * 2
             end
             local duration = recoil_sequence[j]
             repeat
                Sleep(10)
                if not IsMouseButtonPressed(1) then break end
                local dt = math.min(GetRunningTime() - tm, duration)
                duration, tm = duration - dt, tm + dt
                x, y = x + dt/10 * dx_10ms, y + dt/10 * dy_10ms
                local int_x, int_y = math.floor(x), math.floor(y)
                x, y = x - int_x, y - int_y
                MoveMouseRelative(int_x, int_y)
             until duration == 0
             if not IsMouseButtonPressed(1) then break end
          end
       end
    end
    

    【讨论】:

    • 好吧,这似乎比我的基本理解要复杂得多,我该如何添加呢?如何在鼠标移动中进行更多步骤?有没有办法可以在其中添加随机化? PS你是个巫师哈哈
    • how can I make more steps in the mouse movements? - 只需在 recoil_table["AK47"] add randomizations into this? 中添加更多行 - 究竟应该随机化什么?请随机显示您的旧脚本。
    • 因为我还是编码新手,所以我完全不确定随机化,我什至不确定我是否需要它。更多的是确认问题,而不是任何事情哈哈。我一直在编辑您发送给我的代码并在表格中添加了更多行,现在它运行良好,非常感谢您。我的下一个任务是添加其他枪支。我怎样才能拿到我的剧本并添加多个武器?我可以复制相同的代码并编辑内容,以便当我按下鼠标上的另一个 g 按钮时,我可以使用不同的武器吗?
    • 答案已更新。
    • 那太好了,谢谢你,我现在拥有了按照我想要的方式构建脚本所需的一切。快速提问... 你为我写的这部分脚本“0, 0.5, 1000” 有什么理由说它是 0.5?我的理解是 MoveMouseRelative 不能使用小数。是 math.floor 通过向上或向下舍入来完成这项工作的吗?我之所以问这个只是因为我添加的新武器在 0、3、120 时有很大的后坐力补偿,而在 0、2、120 时还不够。我想知道是否有办法在不改变鼠标灵敏度的情况下让它恰到好处
    猜你喜欢
    • 2014-09-22
    • 2013-07-05
    • 2016-04-29
    • 2017-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-20
    • 1970-01-01
    相关资源
    最近更新 更多