fix(es_extended/client/main): add missing Natives to ESX.SpawnPlayer

This should make spawning alot smoother without multicharacter
This commit is contained in:
Kasey FItton
2024-10-24 14:15:26 +01:00
parent 1beb0cf245
commit 7ef5c12de4
+22 -9
View File
@@ -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