Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Lua FiveM服务器,表索引为零&&;尝试索引nil值(本地,xPlayer)_Lua_Fivem - Fatal编程技术网

Lua FiveM服务器,表索引为零&&;尝试索引nil值(本地,xPlayer)

Lua FiveM服务器,表索引为零&&;尝试索引nil值(本地,xPlayer),lua,fivem,Lua,Fivem,因此,我为我的服务器安装了一些插件,并不断出现这两个错误 这是我的两个密码 1:表索引为零 ESX.RegisterServerCallback('esx_weashop:requestDBItems', function(source, cb) MySQL.Async.fetchAll( 'SELECT * FROM weashops', {}, function(result) local shopItems = {} for i=

因此,我为我的服务器安装了一些插件,并不断出现这两个错误

这是我的两个密码

1:表索引为零

ESX.RegisterServerCallback('esx_weashop:requestDBItems', function(source, cb)

  MySQL.Async.fetchAll(
    'SELECT * FROM weashops',
    {},
    function(result)

      local shopItems  = {}

      for i=1, #result, 1 do

        if shopItems[result[i].name] == nil then
          shopItems[result[i].name] = {}
        end

        table.insert(shopItems[result[i].name], {
          name  = result[i].item,
          price = result[i].price,
          label = ESX.GetWeaponLabel(result[i].item)
        })
      end
      
      if Config.EnableClipGunShop == true then
        table.insert(shopItems["GunShop"], {
          name  = "clip",
          price = GunShopPrice,--Config.EnableClip.GunShop.Price,
          label = GunShopLabel--Config.EnableClip.GunShop.label
        })
        end
        
        if Config.EnableClipGunShop == true then
        table.insert(shopItems["BlackWeashop"], {
          name  = "clip",
          price = BlackWeashopPrice,--Config.EnableClip.BlackWeashop.Price,
          label = BlackWeashopLabel--Config.EnableClip.BlackWeashop.label
        })
        end
      cb(shopItems)

    end
  )

end)
2:尝试索引nil值(本地,xPlayer)

@1表索引为零, 第一个错误告诉您正在使用nil值作为表索引。 我不能告诉你是哪一个,因为你没有用行号发布整个错误消息

它是由
a=b[c]
a={[c]=b}
引起的,其中
c
nil

因此,当使用
result[i].name
result[i].item
索引
shoppitems
时,它是
nil

@2尝试索引零值(本地,xPlayer) 这一点更为明显
xPlayer
nil
,因此您不能将其作为
xPlayer.identifier中的索引

因此,请确保
xPlayer
永远不为
nil
,或者仅在可索引的情况下对其进行索引

快速浏览一下节目


因此,根据手册,只有一个论点。当使用参数调用函数时,您有两个参数会使第二个参数变为
nil

这是ESX资源的常见错误,主要是因为未正确初始化。一个快速的解决方法是使用['@identifier']=GetPlayerIdentifiers(playerId)[1]而不是['@identifier']=xPlayer.identifier在第一个错误中我到底需要更改什么?@JayvanVeen可以做任何必要的事情,这样就不会将nil用作表值。通过确保该值不是nil或确保不将其用作表索引(如果为nil)。剩下的就交给你了,我不知道数据库里有什么,但看起来它不是你所期望的
AddEventHandler('esx:playerLoaded', function(playerId, xPlayer)
    MySQL.Async.fetchAll('SELECT status FROM users WHERE identifier = @identifier', {
        ['@identifier'] = xPlayer.identifier
    }, function(result)
        local data = {}

        if result[1].status then
            data = json.decode(result[1].status)
        end

        xPlayer.set('status', data)
        TriggerClientEvent('esx_status:load', playerId, data)
    end)
end)
RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(playerData)

end)