diff --git a/[core]/es_extended/client/common.lua b/[core]/es_extended/client/common.lua index e86221c3..a1c1a8da 100644 --- a/[core]/es_extended/client/common.lua +++ b/[core]/es_extended/client/common.lua @@ -1,8 +1,30 @@ -exports("getSharedObject", function() - return ESX -end) +Core = {} +ESX.PlayerData = {} +ESX.PlayerLoaded = false +Core.Input = {} +ESX.UI = {} +ESX.UI.Menu = {} +ESX.UI.Menu.RegisteredTypes = {} +ESX.UI.Menu.Opened = {} -AddEventHandler("esx:getSharedObject", function() - local Invoke = GetInvokingResource() - error(("Resource ^5%s^7 Used the ^5getSharedObject^7 Event, this event ^1no longer exists!^7 Visit https://documentation.esx-framework.org/tutorials/tutorials-esx/sharedevent for how to fix!"):format(Invoke)) +ESX.Game = {} +ESX.Game.Utils = {} + +ESX.Scaleform = {} +ESX.Scaleform.Utils = {} + +ESX.Streaming = {} + +CreateThread(function() + while not Config.Multichar do + Wait(100) + + if NetworkIsPlayerActive(PlayerId()) then + exports.spawnmanager:setAutoSpawn(false) + DoScreenFadeOut(0) + Wait(500) + TriggerServerEvent("esx:onPlayerJoined") + break + end + end end) diff --git a/[core]/es_extended/client/functions.lua b/[core]/es_extended/client/functions.lua index c5c5bd84..5957831a 100644 --- a/[core]/es_extended/client/functions.lua +++ b/[core]/es_extended/client/functions.lua @@ -1,21 +1,3 @@ -ESX = {} -Core = {} -ESX.PlayerData = {} -ESX.PlayerLoaded = false -Core.Input = {} -ESX.UI = {} -ESX.UI.Menu = {} -ESX.UI.Menu.RegisteredTypes = {} -ESX.UI.Menu.Opened = {} - -ESX.Game = {} -ESX.Game.Utils = {} - -ESX.Scaleform = {} -ESX.Scaleform.Utils = {} - -ESX.Streaming = {} - function ESX.IsPlayerLoaded() return ESX.PlayerLoaded end @@ -68,6 +50,48 @@ function ESX.SetPlayerData(key, val) end end +function Core.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() + p:resolve() + end) + Citizen.Await(p) + + RequestCollisionAtCoord(coords.x, coords.y, coords.z) + + local playerPed = PlayerPedId() + local timer = GetGameTimer() + + Core.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, 0, true) + TriggerEvent('playerSpawned', coords) + cb() +end + + function ESX.Progressbar(...) return IsResourceFound('esx_progressbar') and exports['esx_progressbar']:Progressbar(...) end diff --git a/[core]/es_extended/client/main.lua b/[core]/es_extended/client/main.lua index acdb6831..9a22d02d 100644 --- a/[core]/es_extended/client/main.lua +++ b/[core]/es_extended/client/main.lua @@ -1,63 +1,9 @@ local pickups = {} -CreateThread(function() - while not Config.Multichar do - Wait(100) - - if NetworkIsPlayerActive(PlayerId()) then - exports.spawnmanager:setAutoSpawn(false) - DoScreenFadeOut(0) - Wait(500) - TriggerServerEvent("esx:onPlayerJoined") - break - end - end -end) - 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() - p:resolve() - end) - Citizen.Await(p) - - RequestCollisionAtCoord(coords.x, coords.y, coords.z) - - local playerPed = PlayerPedId() - local timer = GetGameTimer() - - 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, 0, true) - TriggerEvent('playerSpawned', coords) - cb() -end local function EnablePvP() if Config.EnablePVP then @@ -237,7 +183,7 @@ AddEventHandler("esx:playerLoaded", function(xPlayer, _, skin) ClearPedTasksImmediately(ESX.PlayerData.ped) if not Config.Multichar then - freezePlayer(false) + Core.FreezePlayer(false) end if IsScreenFadedOut() then diff --git a/[core]/es_extended/common/main.lua b/[core]/es_extended/common/main.lua new file mode 100644 index 00000000..168d6f60 --- /dev/null +++ b/[core]/es_extended/common/main.lua @@ -0,0 +1,10 @@ +ESX = {} + +exports("getSharedObject", function() + return ESX +end) + +AddEventHandler("esx:getSharedObject", function() + local Invoke = GetInvokingResource() + error(("Resource ^5%s^7 Used the ^5getSharedObject^7 Event, this event ^1no longer exists!^7 Visit https://documentation.esx-framework.org/tutorials/tutorials-esx/sharedevent for how to fix!"):format(Invoke)) +end) diff --git a/[core]/es_extended/fxmanifest.lua b/[core]/es_extended/fxmanifest.lua index 9028fbd2..0a281abb 100644 --- a/[core]/es_extended/fxmanifest.lua +++ b/[core]/es_extended/fxmanifest.lua @@ -11,6 +11,10 @@ shared_scripts { 'config.lua', 'config.weapons.lua', + + 'common/main.lua', + 'common/functions.lua', + 'common/modules/*.lua', } server_scripts { @@ -27,24 +31,19 @@ server_scripts { 'server/main.lua', 'server/commands.lua', - 'common/modules/*.lua', - 'common/functions.lua', 'server/modules/actions.lua', 'server/modules/npwd.lua', 'server/modules/createJob.lua' } client_scripts { - 'client/common.lua', + 'client/common.lua', 'client/functions.lua', 'client/wrapper.lua', 'client/modules/callback.lua', 'client/main.lua', - 'common/modules/*.lua', - 'common/functions.lua', - 'client/modules/actions.lua', 'client/modules/death.lua', 'client/modules/npwd.lua', diff --git a/[core]/es_extended/server/common.lua b/[core]/es_extended/server/common.lua index 58326b42..46479283 100644 --- a/[core]/es_extended/server/common.lua +++ b/[core]/es_extended/server/common.lua @@ -1,4 +1,3 @@ -ESX = {} ESX.Players = {} ESX.Jobs = {} ESX.JobsPlayerCount = {} @@ -18,15 +17,6 @@ RegisterNetEvent("esx:onPlayerSpawn", function() ESX.Players[source].spawned = true end) -AddEventHandler("esx:getSharedObject", function() - local Invoke = GetInvokingResource() - error(("Resource ^5%s^7 Used the ^5getSharedObject^7 Event, this event ^1no longer exists!^7 Visit https://documentation.esx-framework.org/tutorials/tutorials-esx/sharedevent for how to fix!"):format(Invoke)) -end) - -exports("getSharedObject", function() - return ESX -end) - if Config.OxInventory then Config.PlayerFunctionOverride = "OxInventory" SetConvarReplicated("inventory:framework", "esx")