xPlayer 在玩家登录后为空

我在服务器端有一个FiveM脚本。当我连接时,该脚本无法设置 xPlayer,但一旦连接到服务器并重新加载脚本,一切都按预期工作。

RegisterServerEvent("eventScript:Ping", function()
     local _source = source
      Citizen.Wait(3000)
     print('Source: '.._source)
     local xPlayer = ESX.GetPlayerFromId(_source)
      print('xPlayer : '..ESX.GetPlayerFromId(_source))
    if not gameInfo.PlayerTeams[_source] then
        gameInfo.PlayerTeams[_source] = {
            ["Team"] = xPlayer.job.name == 'army' and team2 or team1,
            ["Position"] = GetEntityCoords(GetPlayerPed(_source)),
            ["IsConnected"] = true
        }
    end
end)
点赞
用户12387791
用户12387791

如果您怀疑玩家尚未正确加载或未分配所有标识符,则需等待playerJoining事件触发才能在服务器上访问该客户端的属性。这并不是特定于ESX。

2022-01-16 07:00:02