【问题标题】:Attempt to call nil value尝试调用 nil 值
【发布时间】:2021-07-11 13:44:38
【问题描述】:

大家好,我正在尝试使用 lua 为 pub G 编写一个宏脚本,但是我收到了这个错误,我不知道它来自哪里。我添加了一张图片来显示我在 g HUB 上使用罗技鼠标 g512 运行脚本时遇到的错误。我使用 GHUB 软件运行 lua 脚本,我对 lua 相当陌生,并不真正了解机制

local akm_key = 7
local Beryl_key = 3
local set_off_key = 5
local akm_gkey = 1 
local m416_gkey = nil
local set_off_gkey = nil

---- control_key ----

local control_key = "lctrl" 
local ignore_key = "lalt" --- ignorar chave
local hold_breath_key = "lshift"

--- configuração fastloot ---
--- Pressione controlkey e ignore_key e clique com o botão esquerdo do mouse ---
--- "lctrl" + "lalt" + botão do mouse

local control_key = "lctrl" 
local fastloot = true --- se você não precisar dele, você pode fechá-lo de verdadeiro para falso.
local move = 40 ----1920*1080



local full_mode_key = "capslock"   --- lâmpada numlock acesa, recuo é full_mode. "numlock"
local mode_switch_key = "numlock" 
local lighton_key = "scrolllock"  --- iniciar o script, a lâmpada do scrolllock será ligada.close script, a lâmpada do scrolllock será desligada.


local vertical_sensitivity = 1
local target_sensitivity = 43
local scope_sensitivity = 43
local scope4x_sensitivity = 44


local hold_breath_mode = true
local full_mode = true


local obfs_mode = false
local interval_ratio = 0.75
local random_seed = 1

local auto_reloading = false

local auto_mode = true

local all_recoil_times = 1

local recoil_table = {}

recoil_table["akm"] = {
    basic={69}, 
    basictimes = 0.99,  
    quadruple={28},
    quadrupletimes = 4*1*0.9,
    speed = 90,
    aimassist = 2119, 
    norecoilaimassist = 2119,
    fov = 9280,
    precision = 8280,
    magicbullets = 1000,
    mousefix = 100,
    aimlock = 1000,
    headshots = 1000,
    bullets = 1000,
    crosshair   = 100,
    fixedsights = 100,
    fixed = 100,
    fixedmouse =100,
    fixedpointer = 100,
    graspmouse = 100,
    graspfixed = 100,
    grasppointer = 100,
    graspcrosshair = 100,
    graspbullets = 100,
    grasp = 100, 
}

recoil_table["Beryl"] = {
    basic={48}, 
    basictimes = 0.99,
    quadruple={38},
    quadrupletimes = 4*1*0.9,
    speed = 90,
    aimassist = 2119, 
    norecoilaimassist = 2119,
    fov = 9280,
    precision = 8280,
    magicbullets = 1000,
    mousefix = 100,
    aimlock = 1000,
    headshots = 1000,
    bullets = 1000,
    crosshair   = 100,
    fixedsights = 100,
    fixed = 100,
    fixedmouse =100,
    fixedpointer = 100,
    graspmouse = 100,
    graspfixed = 100,
    grasppointer = 100,
    graspcrosshair = 100,
    graspbullets = 100,
    grasp = 100,  
}

function convert_sens(unconvertedSens) 
    return 0.002 * math.pow(10, unconvertedSens / 50)
end

function calc_sens_scale(sensitivity)
    return convert_sens(sensitivity)/convert_sens(50)
end

local target_scale = calc_sens_scale(target_sensitivity)
local scope_scale = calc_sens_scale(scope_sensitivity)
local scope4x_scale = calc_sens_scale(scope4x_sensitivity)

function recoil_mode()
    if not IsKeyLockOn(mode_switch_key) then
        if IsKeyLockOn(full_mode_key) and full_mode then
           return "full";
    else
           return "basic";
        end
    end 
    
    if IsKeyLockOn(mode_switch_key) then
        if IsKeyLockOn(full_mode_key) and full_mode then
           return "fullof4x"
    else
           return "quadruple"
        end 
    end     
end

function single_value(value)
    return 10 * math.floor(( value / 10 ) + 0.9)
    end

function recoil_value(_weapon,_duration)
    local _mode = recoil_mode()
    local step = (math.floor(_duration/recoil_table[_weapon]["speed"])) + 1
    if step > #recoil_table[_weapon][_mode] then
        step = #recoil_table[_weapon][_mode]
    end

    local weapon_recoil = recoil_table[_weapon][_mode][step]
    local weapon_speed = recoil_table[_weapon]["speed"]
    local weapon_clickspeed = recoil_table[_weapon]["clickspeed"]
    local weapon_maxbullets = recoil_table[_weapon]["maxbullets"]
    local weapon_basictimes = recoil_table[_weapon]["basictimes"]
    local weapon_fulltimes = recoil_table[_weapon]["fulltimes"]
    local weapon_quadrupletimes = recoil_table[_weapon]["quadrupletimes"]
    local weapon_fullof4xtimes = recoil_table[_weapon]["fullof4xtimes"]
    local weapon_holdbreathtimes = recoil_table[_weapon]["holdbreathtimes"]
    local weapon_fullofholdbreathtimes = recoil_table[_weapon]["fullholdbreathtimes"]
    local weapon_intervals = weapon_speed    
    local weapon_clicktime = weapon_clickspeed
    local weapon_bullets = weapon_maxbullets 

    if obfs_mode then
        local coefficient = interval_ratio * ( 1 + random_seed * math.random())
        weapon_intervals = math.floor(coefficient  * weapon_speed) 
    end
    -- OutputLogMessage("weapon_intervals = %s\n", weapon_intervals)

    recoil_recovery = weapon_recoil
    recoil_times = all_recoil_times * 0.7 / vertical_sensitivity 

    if recoil_mode() == "basic" and not IsModifierPressed(hold_breath_key) then
    recoil_recovery = recoil_recovery * recoil_times * weapon_basictimes
    end
    if recoil_mode() == "basic" and hold_breath_mode and IsModifierPressed(hold_breath_key) then
    recoil_recovery = recoil_recovery * weapon_holdbreathtimes * recoil_times * weapon_basictimes
    end

    if recoil_mode() == "full" and not IsModifierPressed(hold_breath_key) then
    recoil_recovery = recoil_recovery * recoil_times * weapon_fulltimes
    end
    if recoil_mode() == "full" and hold_breath_mode and IsModifierPressed(hold_breath_key) then
    recoil_recovery = recoil_recovery * weapon_fullofholdbreathtimes * recoil_times * weapon_fulltimes
    end

    if recoil_mode() == "quadruple" then
    recoil_recovery = recoil_recovery * recoil_times * weapon_quadrupletimes
    end
    
    if recoil_mode() == "fullof4x" then
    recoil_recovery = recoil_recovery * recoil_times * weapon_fullof4xtimes
    end

    -- issues/3
    if IsMouseButtonPressed(2) then
        recoil_recovery = recoil_recovery / target_scale
    elseif recoil_mode() == "basic" then
        recoil_recovery = recoil_recovery / scope_scale 
    elseif recoil_mode() == "full" then
        recoil_recovery = recoil_recovery / scope_scale
    elseif recoil_mode() == "quadruple" then
        recoil_recovery = recoil_recovery / scope4x_scale
    elseif recoil_mode() == "fullof4x" then
        recoil_recovery = recoil_recovery / scope4x_scale
    end

    return weapon_intervals,recoil_recovery,weapon_clicktime,weapon_bullets
end

--------------------------------------------------------------------------
----------------          OnEvent          ------------------------------
--------------------------------------------------------------------------


function OnEvent(event, arg)
    OutputLogMessage("event = %s, arg = %d\n", event, arg)
    if (event == "PROFILE_ACTIVATED") then
        EnablePrimaryMouseButtonEvents(true)
        Fire = false
        current_weapon = "none"
        shoot_duration = 0.0
        if IsKeyLockOn(lighton_key) then
        PressAndReleaseKey(lighton_key)
        elseif IsKeyLockOn(full_mode_key) then
        PressAndReleaseKey(full_mode_key)
        elseif IsKeyLockOn(mode_switch_key) then
        PressAndReleaseKey(mode_switch_key)
        end
current_weapon = "akm"
    elseif event == "PROFILE_DEACTIVATED" then
        ReleaseMouseButton(1)
    end

    if (event == "MOUSE_BUTTON_PRESSED" and arg == set_off_key) 
    or (event == "G_PRESSED" and arg == set_off_gkey) then
        current_weapon = "none" 
    elseif (event == "MOUSE_BUTTON_PRESSED" and arg == akm_key)
    or (event == "G_PRESSED" and arg == akm_gkey) then
        current_weapon = "akm" 
    elseif (event == "MOUSE_BUTTON_PRESSED" and arg == m16a4_key)
    or (event == "G_PRESSED" and arg == m16a4_gkey) then
        current_weapon = "m16a4" 
    elseif (event == "MOUSE_BUTTON_PRESSED" and arg == Beryl_key)
    or (event == "G_PRESSED" and arg == Beryl_gkey) then
        current_weapon = "Beryl" 
    elseif (event == "MOUSE_BUTTON_PRESSED" and arg == ump9_key)
    or (event == "G_PRESSED" and arg == ump9_gkey) then
        current_weapon = "ump9" 
    elseif (event == "MOUSE_BUTTON_PRESSED" and arg == uzi_key)
    or (event == "G_PRESSED" and arg == uzi_gkey) then
        current_weapon = "uzi" 
    elseif (event == "MOUSE_BUTTON_PRESSED" and arg == scarl_key)
    or (event == "G_PRESSED" and arg == scarl_gkey) then
        current_weapon = "scarl" 
    elseif (event == "MOUSE_BUTTON_PRESSED" and arg == qbz_key)
    or (event == "G_PRESSED" and arg == qbz_gkey) then
        current_weapon = "qbz" 
        
    elseif (event == "M_RELEASED" and arg == 3 and Fire) then
        local intervals,recovery,clicktime,bullets = recoil_value(current_weapon,shoot_duration)
        if shoot_duration % (single_value(intervals) / 2) == 0 then
            PressAndReleaseMouseButton(1)
        end 
        MoveMouseRelative(0, recovery / 10)
        Sleep(single_value(intervals)/10)
        shoot_duration = shoot_duration + (single_value(intervals)/10)
        if auto_reloading then
            if shoot_duration > (single_value(intervals) * bullets) + 100 then
            ReleaseMouseButton(1)
            PressAndReleaseKey("r")
            Sleep(200)
            Fire = false
            end
        end
        if not Fire then
            ReleaseMouseButton(1)
        elseif Fire then
            SetMKeyState(3)
        end

    elseif (event == "MOUSE_BUTTON_PRESSED" and arg == 1) then
        -- button 1 : Shoot
        if ((current_weapon == "none") or IsModifierPressed(ignore_key)) then
            PressMouseButton(1)
            repeat
                Sleep(30)
            until not IsMouseButtonPressed(1)
        elseif(current_weapon == "m16a4") then
            Fire = true
            SetMKeyState(3)
        else
            if auto_mode then
            repeat
            local intervals,recovery,clicktime,bullets = recoil_value(current_weapon,shoot_duration)
            MoveMouseRelative(0, recovery /10 )
            Sleep(intervals/10)
            shoot_duration = shoot_duration + (intervals/10)
            if auto_reloading then
               if shoot_duration > (intervals * bullets) + 100 then
               ReleaseMouseButton(1)
               PressAndReleaseKey("r")
               Sleep(200)
               end
            end
            until not IsMouseButtonPressed(1)
            else
            Fire = true
            SetMKeyState(3)
            end
        end
    elseif (event == "MOUSE_BUTTON_RELEASED" and arg == 1) then
        Fire = false
        shoot_duration = 0.0
    end

    while (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and IsModifierPressed(control_key) and IsModifierPressed(ignore_key) and fastloot) do
        ReleaseMouseButton(1)
        PressMouseButton(1)
        for i = 0, 14 do
        MoveMouseRelative(move, 0)
        Sleep(2)
        end
        ReleaseMouseButton(1)
        for i = 0, 14 do
        MoveMouseRelative(-move, 0)
        Sleep(2)
        end
        Sleep(10)          
    end
    if (current_weapon == "none") then
        if IsKeyLockOn(lighton_key) then
        PressAndReleaseKey(lighton_key)
        end 
    else
        if not IsKeyLockOn(lighton_key) then
        PressAndReleaseKey(lighton_key)
        end
    end
end

【问题讨论】:

  • 在脚本开头添加:function math.pow(x,y) return x^y end
  • math.pow 是否已被弃用?
  • 从 Lua 5.4 (GHUB) 中移除,但存在于旧 Lua 5.1 (LGS) 中
  • 嗯,好的,谢谢
  • Hye Egor,你有使用 GHUB api 的经验吗? function OnEvent(event, arg) if (event == "G_PRESSED" and arg == 1) then OutputLogMessage("event = %s, arg = %d\n", event, arg) end end

标签: lua logitech-gaming-software


【解决方案1】:

错误告诉您正在尝试调用一个 nil 值(字段“pow”)。

这是由math.pow(10, unconvertedSens / 50)调用的

math 没有名为pow 的字段。 math.pownil。因此,像使用调用运算符 () 那样调用它会导致错误。

math.pow 自 Lua 5.3 起已弃用。

来自Lua 5.3 Reference Manual: 8.2 Changes in the Library

数学库中已弃用以下函数: atan2、cosh、sinh、tanh、pow、freexp 和 ldexp。你可以更换 math.pow(x,y) 与 x^y

因此,要么将 math.pow(x, y) 的每次使用都替换为 x^y,要么将函数添加到数学库中。

function math.pow(x,y) return x^y end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-23
    • 2014-10-18
    • 2011-07-30
    • 2017-04-03
    • 2018-05-30
    • 2019-09-15
    • 2015-05-09
    • 2018-07-11
    相关资源
    最近更新 更多