feat(esx_garage): Onesync Vehicle Spawning

This commit is contained in:
Mycroft
2022-10-14 17:21:45 +01:00
parent febb89bf58
commit fc87fe5c2d
2 changed files with 14 additions and 26 deletions
+2 -22
View File
@@ -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)
+12 -4
View File
@@ -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)