diff --git a/client/main.lua b/client/main.lua index b378409..e423336 100644 --- a/client/main.lua +++ b/client/main.lua @@ -137,40 +137,52 @@ RegisterNetEvent('qb-multicharacter:client:chooseChar', function() end) RegisterNetEvent('qb-multicharacter:client:spawnLastLocation', function(coords, cData) - QBCore.Functions.TriggerCallback('apartments:GetOwnedApartment', function(result) - if result then - TriggerEvent('apartments:client:SetHomeBlip', result.type) - local ped = PlayerPedId() - SetEntityCoords(ped, coords.x, coords.y, coords.z) - SetEntityHeading(ped, coords.w) - FreezeEntityPosition(ped, false) - SetEntityVisible(ped, true) - local PlayerData = QBCore.Functions.GetPlayerData() - local insideMeta = PlayerData.metadata['inside'] - DoScreenFadeOut(500) - - if insideMeta.house then - TriggerEvent('qb-houses:client:LastLocationHouse', insideMeta.house) - elseif insideMeta.apartment.apartmentType and insideMeta.apartment.apartmentId then - TriggerEvent('qb-apartments:client:LastLocationHouse', insideMeta.apartment.apartmentType, insideMeta.apartment.apartmentId) - else + if GetResourceState('qb-apartement') == 'started' then + QBCore.Functions.TriggerCallback('apartments:GetOwnedApartment', function(result) + if result then + TriggerEvent('apartments:client:SetHomeBlip', result.type) + local ped = PlayerPedId() SetEntityCoords(ped, coords.x, coords.y, coords.z) SetEntityHeading(ped, coords.w) FreezeEntityPosition(ped, false) SetEntityVisible(ped, true) - end + local PlayerData = QBCore.Functions.GetPlayerData() + local insideMeta = PlayerData.metadata['inside'] + DoScreenFadeOut(500) - TriggerServerEvent('QBCore:Server:OnPlayerLoaded') - TriggerEvent('QBCore:Client:OnPlayerLoaded') - Wait(2000) - DoScreenFadeIn(250) - end - end, cData.citizenid) + if insideMeta.house then + TriggerEvent('qb-houses:client:LastLocationHouse', insideMeta.house) + elseif insideMeta.apartment.apartmentType and insideMeta.apartment.apartmentId then + TriggerEvent('qb-apartments:client:LastLocationHouse', insideMeta.apartment.apartmentType, insideMeta.apartment.apartmentId) + else + SetEntityCoords(ped, coords.x, coords.y, coords.z) + SetEntityHeading(ped, coords.w) + FreezeEntityPosition(ped, false) + SetEntityVisible(ped, true) + end + + TriggerServerEvent('QBCore:Server:OnPlayerLoaded') + TriggerEvent('QBCore:Client:OnPlayerLoaded') + Wait(2000) + DoScreenFadeIn(250) + end + end, cData.citizenid) + else + local ped = PlayerPedId() + SetEntityCoords(ped, coords.x, coords.y, coords.z) + SetEntityHeading(ped, coords.w) + FreezeEntityPosition(ped, false) + SetEntityVisible(ped, true) + TriggerServerEvent('QBCore:Server:OnPlayerLoaded') + TriggerEvent('QBCore:Client:OnPlayerLoaded') + Wait(2000) + DoScreenFadeIn(250) + end end) -- NUI Callbacks -RegisterNUICallback('closeUI', function(_, cb) +RegisterNUICallback('closeUI', function(data, cb) local cData = data.cData DoScreenFadeOut(10) TriggerServerEvent('qb-multicharacter:server:loadUserData', cData)