diff --git a/[core]/es_extended/client/main.lua b/[core]/es_extended/client/main.lua index bbc9528d..6dab784d 100644 --- a/[core]/es_extended/client/main.lua +++ b/[core]/es_extended/client/main.lua @@ -18,54 +18,47 @@ RegisterNetEvent("esx:requestModel", function(model) ESX.Streaming.RequestModel(model) end) +function ESX.SpawnPlayer(skin, coords, cb) + local p = promise.new() + TriggerEvent("skinchanger:loadSkin", skin, function() + p:resolve() + end) + Citizen.Await(p) + + local playerPed = PlayerPedId() + FreezeEntityPosition(playerPed, true) + SetEntityCoordsNoOffset(playerPed, coords.x, coords.y, coords.z, false, false, false, true) + SetEntityHeading(playerPed, coords.heading) + while not HasCollisionLoadedAroundEntity(playerPed) do + Wait(0) + end + FreezeEntityPosition(playerPed, false) + cb() +end + RegisterNetEvent("esx:playerLoaded") AddEventHandler("esx:playerLoaded", function(xPlayer, isNew, skin) ESX.PlayerData = xPlayer - if Config.Multichar then - Wait(3000) - else - exports.spawnmanager:spawnPlayer({ - x = ESX.PlayerData.coords.x, - y = ESX.PlayerData.coords.y, - z = ESX.PlayerData.coords.z + 0.25, - heading = ESX.PlayerData.coords.heading, - model = `mp_m_freemode_01`, - skipFade = false, - }, function() - TriggerServerEvent("esx:onPlayerSpawn") + if not Config.Multichar then + ESX.SpawnPlayer(skin, ESX.PlayerData.coords, function() TriggerEvent("esx:onPlayerSpawn") TriggerEvent("esx:restoreLoadout") - - if isNew then - TriggerEvent("skinchanger:loadDefaultModel", skin.sex == 0) - elseif skin then - TriggerEvent("skinchanger:loadSkin", skin) - end - + TriggerServerEvent("esx:onPlayerSpawn") TriggerEvent("esx:loadingScreenOff") ShutdownLoadingScreen() ShutdownLoadingScreenNui() end) end - ESX.PlayerLoaded = true - - while ESX.PlayerData.ped == nil do + while not DoesEntityExist(ESX.PlayerData.ped) do Wait(20) end + + ESX.PlayerLoaded = true - while not HasCollisionLoadedAroundEntity(ESX.PlayerData.ped) do - Wait(0) - end - - if Config.EnablePVP then - SetCanAttackFriendly(ESX.PlayerData.ped, true, false) - NetworkSetFriendlyFireOption(true) - end - - local playerId = PlayerId() local metadata = ESX.PlayerData.metadata + if metadata.health then SetEntityHealth(ESX.PlayerData.ped, metadata.health) end @@ -74,6 +67,17 @@ AddEventHandler("esx:playerLoaded", function(xPlayer, isNew, skin) SetPedArmour(ESX.PlayerData.ped, metadata.armor) end + local timer = GetGameTimer() + while not HaveAllStreamingRequestsCompleted(ESX.PlayerData.ped) and (GetGameTimer() - timer) < 2000 do + Wait(0) + end + + if Config.EnablePVP then + SetCanAttackFriendly(ESX.PlayerData.ped, true, false) + NetworkSetFriendlyFireOption(true) + end + + local playerId = PlayerId() -- RemoveHudComponents for i = 1, #Config.RemoveHudComponents do if Config.RemoveHudComponents[i] then @@ -98,9 +102,9 @@ AddEventHandler("esx:playerLoaded", function(xPlayer, isNew, skin) end) end - if Config.DisableHealthRegeneration then - SetPlayerHealthRechargeMultiplier(playerId, 0.0) - end + --if Config.DisableHealthRegeneration then + --SetPlayerHealthRechargeMultiplier(playerId, 0.0) + --end if Config.DisableWeaponWheel or Config.DisableAimAssist or Config.DisableVehicleRewards then CreateThread(function() @@ -197,10 +201,15 @@ AddEventHandler("esx:playerLoaded", function(xPlayer, isNew, skin) end end + if IsScreenFadedOut() then + DoScreenFadeIn(500) + end + SetDefaultVehicleNumberPlateTextPattern(-1, Config.CustomAIPlates) StartServerSyncLoops() end) + RegisterNetEvent("esx:onPlayerLogout") AddEventHandler("esx:onPlayerLogout", function() ESX.PlayerLoaded = false diff --git a/[core]/es_extended/client/modules/actions.lua b/[core]/es_extended/client/modules/actions.lua index cbe34fa0..0fec4584 100644 --- a/[core]/es_extended/client/modules/actions.lua +++ b/[core]/es_extended/client/modules/actions.lua @@ -25,6 +25,7 @@ local function GetData(vehicle) end CreateThread(function() + while not ESX.PlayerLoaded do Wait(200) end while true do ESX.SetPlayerData("coords", GetEntityCoords(playerPed)) if playerPed ~= PlayerPedId() then