diff --git a/[esx_addons]/esx_garage/client/main.lua b/[esx_addons]/esx_garage/client/main.lua index c89fa557..8e10fc97 100644 --- a/[esx_addons]/esx_garage/client/main.lua +++ b/[esx_addons]/esx_garage/client/main.lua @@ -27,24 +27,12 @@ RegisterNUICallback('escape', function(data, cb) end) RegisterNUICallback('spawnVehicle', function(data, cb) - local spawnCoords = { - x = data.spawnPoint.x, - y = data.spawnPoint.y, - z = data.spawnPoint.z - } - + local spawnCoords = vector3(data.spawnPoint.x, data.spawnPoint.y, data.spawnPoint.z) if thisGarage then if ESX.Game.IsSpawnPointClear(spawnCoords, 2.5) then - ESX.Game.SpawnVehicle(data.vehicleProps.model, spawnCoords, data.spawnPoint.heading, function(vehicle) - TaskWarpPedIntoVehicle(ESX.PlayerData.ped, vehicle, -1) - ESX.Game.SetVehicleProperties(vehicle, data.vehicleProps) - SetVehicleEngineOn(vehicle, (not GetIsVehicleEngineRunning(vehicle)), true, true) - end) - thisGarage = nil - - TriggerServerEvent('esx_garage:updateOwnedVehicle', false, nil, nil, data.vehicleProps) + TriggerServerEvent('esx_garage:updateOwnedVehicle', false, nil, nil, data, spawnCoords) TriggerEvent('esx_garage:closemenu') ESX.ShowNotification(TranslateCap('veh_released')) @@ -59,14 +47,6 @@ RegisterNUICallback('spawnVehicle', function(data, cb) if hasMoney then if ESX.Game.IsSpawnPointClear(spawnCoords, 2.5) then TriggerServerEvent('esx_garage:payPound', data.exitVehicleCost) - - ESX.Game.SpawnVehicle(data.vehicleProps.model, spawnCoords, data.spawnPoint.heading, - function(vehicle) - TaskWarpPedIntoVehicle(ESX.PlayerData.ped, vehicle, -1) - ESX.Game.SetVehicleProperties(vehicle, data.vehicleProps) - SetVehicleEngineOn(vehicle, (not GetIsVehicleEngineRunning(vehicle)), true, true) - end) - thisPound = nil TriggerServerEvent('esx_garage:updateOwnedVehicle', false, nil, nil, data.vehicleProps) diff --git a/[esx_addons]/esx_garage/server/main.lua b/[esx_addons]/esx_garage/server/main.lua index d4a35795..12cb30d4 100644 --- a/[esx_addons]/esx_garage/server/main.lua +++ b/[esx_addons]/esx_garage/server/main.lua @@ -1,13 +1,12 @@ RegisterServerEvent('esx_garage:updateOwnedVehicle') -AddEventHandler('esx_garage:updateOwnedVehicle', function(stored, parking, Impound, vehicleProps) +AddEventHandler('esx_garage:updateOwnedVehicle', function(stored, parking, Impound, data, spawn) local source = source local xPlayer = ESX.GetPlayerFromId(source) - MySQL.update('UPDATE owned_vehicles SET `stored` = @stored, `parking` = @parking, `pound` = @Impound, `vehicle` = @vehicle WHERE `plate` = @plate AND `owner` = @identifier', { ['@identifier'] = xPlayer.identifier, - ['@vehicle'] = json.encode(vehicleProps), - ['@plate'] = vehicleProps.plate, + ['@vehicle'] = json.encode(data.vehicleProps), + ['@plate'] = data.vehicleProps.plate, ['@stored'] = stored, ['@parking'] = parking, ['@Impound'] = Impound @@ -15,6 +14,15 @@ AddEventHandler('esx_garage:updateOwnedVehicle', function(stored, parking, Impou if stored then xPlayer.showNotification(TranslateCap('veh_stored')) + else + ESX.OneSync.SpawnVehicle(data.vehicleProps.model, spawn, data.spawnPoint.heading,data.vehicleProps, function(vehicle) + Wait(100) + local vehicle = NetworkGetEntityFromNetworkId(vehicle) + while GetVehicleNumberPlateText(vehicle) ~= data.vehicleProps.plate do + Wait(0) + end + TaskWarpPedIntoVehicle(GetPlayerPed(source), vehicle, -1) + end) end end)