From 8a586e433cd0f68f32cc1fdf56ab364df9e35d46 Mon Sep 17 00:00:00 2001 From: ElPumpo Date: Mon, 23 Mar 2020 13:58:41 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9A=A0=EF=B8=8F=E2=9A=A0=EF=B8=8FBREAKING=20?= =?UTF-8?q?COMMIT=E2=9A=A0=EF=B8=8F=E2=9A=A0=EF=B8=8F:=20mapmanager=20&=20?= =?UTF-8?q?spawnmanager=20ditch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make sure you remove or disable mapmanager and spawnmanager --- client/main.lua | 82 ++++++++++++++++++++++++++++++------------------- server/main.lua | 8 +++-- 2 files changed, 55 insertions(+), 35 deletions(-) diff --git a/client/main.lua b/client/main.lua index d768fc58..1b2803bb 100644 --- a/client/main.lua +++ b/client/main.lua @@ -1,17 +1,44 @@ local isLoadoutLoaded, isPaused, isDead, isFirstSpawn, pickups = false, false, false, true, {} +Citizen.CreateThread(function() + while true do + Citizen.Wait(0) + + if NetworkIsPlayerActive(PlayerId()) then + TriggerServerEvent('esx:onPlayerJoined') + break + end + end +end) + RegisterNetEvent('esx:playerLoaded') AddEventHandler('esx:playerLoaded', function(playerData) ESX.PlayerLoaded = true ESX.PlayerData = playerData + local defaultModel = GetHashKey('mp_m_freemode_01') + RequestModel(defaultModel) + + while not HasModelLoaded(defaultModel) do + Citizen.Wait(100) + end + + SetPlayerModel(PlayerId(), defaultModel) + local playerPed = PlayerPedId() + + SetPedDefaultComponentVariation(playerPed) + SetModelAsNoLongerNeeded(defaultModel) + FreezeEntityPosition(playerPed, false) + + if Config.EnablePvP then + SetCanAttackFriendly(playerPed, true, false) + NetworkSetFriendlyFireOption(true) + end + if Config.EnableHud then for k,v in ipairs(playerData.accounts) do local accountTpl = '
 {{money}}
' - - ESX.UI.HUD.RegisterElement('account_' .. v.name, k, 0, accountTpl, { - money = ESX.Math.GroupDigits(v.money) - }) + ESX.UI.HUD.RegisterElement('account_' .. v.name, k, 0, accountTpl, {money = ESX.Math.GroupDigits(v.money)}) end local jobTpl = '
{{job_label}} - {{grade_label}}
' @@ -25,43 +52,34 @@ AddEventHandler('esx:playerLoaded', function(playerData) grade_label = playerData.job.grade_label }) end + + ESX.Game.Teleport(playerPed, { + x = playerData.coords.x, + y = playerData.coords.y, + z = playerData.coords.z + 0.25, + heading = playerData.coords.heading + }, function() + isLoadoutLoaded, isDead = true, false + TriggerServerEvent('esx:onPlayerSpawn') + TriggerEvent('esx:onPlayerSpawn') + TriggerEvent('playerSpawned') -- compatibility with old scripts, will be removed soon + TriggerEvent('esx:restoreLoadout') + + Citizen.Wait(3000) + ShutdownLoadingScreen() + DoScreenFadeIn(10000) + end) end) RegisterNetEvent('esx:setMaxWeight') -AddEventHandler('esx:setMaxWeight', function(newMaxWeight) - ESX.PlayerData.maxWeight = newMaxWeight -end) - -AddEventHandler('playerSpawned', function() - if isFirstSpawn then - TriggerServerEvent('esx:playerJoined') - end - - while not ESX.PlayerLoaded do - Citizen.Wait(10) - end - - TriggerEvent('esx:restoreLoadout') - - if isFirstSpawn then - ESX.Game.Teleport(PlayerPedId(), ESX.PlayerData.coords) - isFirstSpawn = false - end - - isLoadoutLoaded, isDead = true, false - - if Config.EnablePvP then - SetCanAttackFriendly(PlayerPedId(), true, false) - NetworkSetFriendlyFireOption(true) - end -end) +AddEventHandler('esx:setMaxWeight', function(newMaxWeight) ESX.PlayerData.maxWeight = newMaxWeight end) AddEventHandler('esx:onPlayerDeath', function() isDead = true end) AddEventHandler('skinchanger:loadDefaultModel', function() isLoadoutLoaded = false end) AddEventHandler('skinchanger:modelLoaded', function() while not ESX.PlayerLoaded do - Citizen.Wait(1) + Citizen.Wait(100) end TriggerEvent('esx:restoreLoadout') diff --git a/server/main.lua b/server/main.lua index 4d63e12a..7150adad 100644 --- a/server/main.lua +++ b/server/main.lua @@ -1,6 +1,8 @@ -RegisterNetEvent('esx:playerJoined') -AddEventHandler('esx:playerJoined', function() - onPlayerJoined(source) +RegisterNetEvent('esx:onPlayerJoined') +AddEventHandler('esx:onPlayerJoined', function() + if not ESX.Players[source] then + onPlayerJoined(source) + end end) function onPlayerJoined(playerId)