From 7ef5c12de4a4a7564d812d13f7ec03e0d0675559 Mon Sep 17 00:00:00 2001 From: Kasey FItton Date: Thu, 24 Oct 2024 14:15:26 +0100 Subject: [PATCH] fix(es_extended/client/main): add missing Natives to ESX.SpawnPlayer This should make spawning alot smoother without multicharacter --- [core]/es_extended/client/main.lua | 31 +++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/[core]/es_extended/client/main.lua b/[core]/es_extended/client/main.lua index 01211f3b..cf942130 100644 --- a/[core]/es_extended/client/main.lua +++ b/[core]/es_extended/client/main.lua @@ -18,6 +18,21 @@ RegisterNetEvent("esx:requestModel", function(model) ESX.Streaming.RequestModel(model) end) +local function freezePlayer(freeze) + local player = PlayerId() + local ped = PlayerPedId() + SetPlayerControl(player, not freeze, 0) + + if freeze then + SetEntityCollision(ped, false, false) + FreezeEntityPosition(ped, true) + else + SetEntityCollision(ped, true, true) + FreezeEntityPosition(ped, false) + end +end + + function ESX.SpawnPlayer(skin, coords, cb) local p = promise.new() TriggerEvent("skinchanger:loadSkin", skin, function() @@ -30,15 +45,16 @@ function ESX.SpawnPlayer(skin, coords, cb) local playerPed = PlayerPedId() local timer = GetGameTimer() - FreezeEntityPosition(playerPed, true) - SetEntityCoordsNoOffset(playerPed, coords.x, coords.y, coords.z, false, false, false, true) + freezePlayer(true) + SetEntityCoordsNoOffset(playerPed, coords.x, coords.y, coords.z, false, false, true) SetEntityHeading(playerPed, coords.heading) + RequestCollisionAtCoord(coords.x, coords.y, coords.z) while not HasCollisionLoadedAroundEntity(playerPed) and (GetGameTimer() - timer) < 5000 do Wait(0) end - NetworkResurrectLocalPlayer(coords.x, coords.y, coords.z, coords.heading, true, true, false) + NetworkResurrectLocalPlayer(coords.x, coords.y, coords.z, coords.heading, 0, true) TriggerEvent('playerSpawned', coords) cb() end @@ -216,15 +232,12 @@ AddEventHandler("esx:playerLoaded", function(xPlayer, _, skin) Wait(0) end - if Config.EnablePVP then - SetCanAttackFriendly(ESX.PlayerData.ped, true, false) - NetworkSetFriendlyFireOption(true) - end - ApplyConfig() + ClearPedTasksImmediately(ESX.PlayerData.ped) + if not Config.Multichar then - FreezeEntityPosition(ESX.PlayerData.ped, false) + freezePlayer(false) end if IsScreenFadedOut() then