错误脚本:@swerve-basics/client/cl_teleprot.lua:60 中出现错误参数#1的 'pairs'(需要表格但得到nil)

错误发生在这行上:

for zone, data in pairs(Config.zones) do

我是新手(我已经做过Python编程),我真的需要修复这个错误,如果你能帮我并引导我如何修复这个错误,我将不胜感激!!标题中的错误。

完整代码:

ESX = nil local CurrentAction = nil local CurrentActionMsg = '' local HasAlreadyEnteredMarker = false local LastZone = nil

Citizen.CreateThread(function()
    while ESX == nil do
        TriggerEvent('esx:getSharedObject', function(obj)ESX = obj end)
        Citizen.Wait(0)
    end end)

AddEventHandler('tp:hasEnteredMarker', function(zone)
    if zone == 'MethEnter' then
        CurrentAction = zone
    end

    if zone == 'MethExit' then
        CurrentAction = zone
    end

    if zone == 'WeedEnter' then
        CurrentAction = zone
    end         if zone == 'WeedExit' then
        CurrentAction = zone
    end

    if zone == 'MoneyWashEnter' then
        CurrentAction = zone
    end         if zone == 'MoneyWashExit' then
        CurrentAction = zone
    end

    if zone == 'CokeEnter' then
        CurrentAction = zone
    end

    if zone == 'CokeExit' then
        CurrentAction = zone
    end end)

AddEventHandler('tp:hasExitedMarker', function(zone)
    CurrentAction = nil end)

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(3)

        local coords = GetEntityCoords(PlayerPedId())
        local isInMarker = false
        local currentZone = nil

        for zone, data in pairs(Config.zones) do
            local dist = #(coords - vector3(data.x, data.y, data.z));

            if dist < (data.w) then
                isInMarker = true
                currentZone = zone
                ESX.Game.Teleport(PlayerPedId(), {
                    x = Config.point[zone].x,
                    y = Config.point[zone].y,
                    z = Config.point[zone].z
                })
                CurrentAction = nil
                break
            end

            if data.visible and dist < 10 then
                DrawMarker(
                    data.t,
                    data.x,
                    data.y,
                    data.z,
                    0.0,
                    0.0,
                    0.0,
                    0,
                    0.0,
                    0.0,
                    data.w,
                    data.w,
                    data.h,
                    data.color.r,
                    data.color.g,
                    data.color.b,
                    255,
                    false,
                    true,
                    2,
                    false,
                    false,
                    false,
                    false
                )
            end
        end

        if (isInMarker and not HasAlreadyEnteredMarker) or (isInMarker and LastZone ~= currentZone) then
            HasAlreadyEnteredMarker = true
            LastZone = currentZone
            TriggerEvent('tp:hasEnteredMarker', currentZone)
        end

        if not isInMarker and HasAlreadyEnteredMarker then
            HasAlreadyEnteredMarker = false
            TriggerEvent('tp:hasExitedMarker', LastZone)
        end

    end end)

原文链接 https://stackoverflow.com/questions/69338060

点赞
stackoverflow用户17180433
stackoverflow用户17180433

请检查您的配置文件,确保您使用的是大小写一致的 "Config.zones",而不是 "Config.Zones"。如果您使用的是前者,并且仍然出现问题,则可能是您没有正确输入任何内容到 Config.zones 中,或者您输入的格式不正确。

2021-10-18 08:19:56