From 978ffe74f7841b018d43ede00d8aa033d42c5d5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20N=27gadi?= Date: Wed, 2 Aug 2017 14:10:31 +0200 Subject: [PATCH] Fix triggerservercallback too early --- client/main.lua | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/client/main.lua b/client/main.lua index 1be6f35f..0da41a9e 100644 --- a/client/main.lua +++ b/client/main.lua @@ -22,6 +22,8 @@ local HasAlreadyEnteredMarker = false local CurrentAction = nil local CurrentActionMsg = '' local CurrentActionData = {} +local FirstSpawn = true +local PlayerLoaded = false function DrawSub(text, time) ClearPrints() @@ -791,16 +793,22 @@ function OpenPlayerInventoryMenu(property) end -local FirstSpawn = true - AddEventHandler('playerSpawned', function() if FirstSpawn then - ESX.TriggerServerCallback('esx_property:getLastProperty', function(propertyName) - if propertyName ~= nil then - EnterProperty(propertyName) + Citizen.CreateThread(function() + + while not PlayerLoaded do + Citizen.Wait(0) end + + ESX.TriggerServerCallback('esx_property:getLastProperty', function(propertyName) + if propertyName ~= nil then + EnterProperty(propertyName) + end + end) + end) FirstSpawn = false @@ -808,6 +816,11 @@ AddEventHandler('playerSpawned', function() end) +RegisterNetEvent('esx:playerLoaded') +AddEventHandler('esx:playerLoaded', function(xPlayer) + PlayerLoaded = true +end) + AddEventHandler('esx_property:getProperties', function(cb) cb(GetProperties()) end)