diff --git a/client/main.lua b/client/main.lua index 30bb4c13..e594e2cb 100644 --- a/client/main.lua +++ b/client/main.lua @@ -257,6 +257,10 @@ AddEventHandler('esx_property:hasEnteredMarker', function(name, part, parking) TriggerServerEvent('esx_garage:setParking', name, parking, vehicleProps) + if Config.EnableOwnedVehicles then + TriggerServerEvent('esx_garage:updateOwnedVehicle', vehicleProps) + end + end end diff --git a/config.lua b/config.lua index f53456ad..6bce9fc5 100644 --- a/config.lua +++ b/config.lua @@ -1,11 +1,12 @@ -Config = {} -Config.DrawDistance = 100.0 -Config.MarkerType = 1 -Config.MarkerSize = {x = 2.0, y = 2.0, z = 1.0} -Config.MarkerColor = {r = 204, g = 204, b = 0} -Config.ParkingMarkerSize = {x = 3.0, y = 3.0, z = 2.0} -Config.ParkingMarkerColor = {r = 102, g = 102, b = 204} -Config.ZDiff = 0.5 +Config = {} +Config.DrawDistance = 100.0 +Config.MarkerType = 1 +Config.MarkerSize = {x = 2.0, y = 2.0, z = 1.0} +Config.MarkerColor = {r = 204, g = 204, b = 0} +Config.ParkingMarkerSize = {x = 3.0, y = 3.0, z = 2.0} +Config.ParkingMarkerColor = {r = 102, g = 102, b = 204} +Config.ZDiff = 0.5 +Config.EnableOwnedVehicles = true Config.Locale = 'fr' diff --git a/server/main.lua b/server/main.lua index 458539bb..1a07fd5a 100644 --- a/server/main.lua +++ b/server/main.lua @@ -38,6 +38,49 @@ AddEventHandler('esx_garage:setParking', function(garage, zone, vehicleProps) end) +RegisterServerEvent('esx_vehicleshop:updateOwnedVehicle') +AddEventHandler('esx_vehicleshop:updateOwnedVehicle', function(vehicleProps) + + local _source = source + local xPlayer = ESX.GetPlayerFromId(source) + + MySQL.Async.fetchAll( + 'SELECT * FROM owned_vehicles WHERE owner = @owner', + { + ['@owner'] = xPlayer.identifier + }, + function(results) + + local foundVehicleId = nil + + for i=1, #result, 1 do + + local vehicle = json.decode(result[i].vehicle) + + if vehicle.plate == vehicleProps.plate then + foundVehicleId = result[i].id + break + end + + end + + if foundVehicleId ~= nil then + + MySQL.Async.execute( + 'UPDATE owned_vehicles SET vehicle = @vehicle WHERE id = @id', + { + ['@vehicle'] = json.encode(vehicleProps), + ['@id'] = foundVehicleId + } + ) + + end + + end + ) + +end) + ESX.RegisterServerCallback('esx_vehicleshop:getVehiclesInGarage', function(source, cb, garage) local xPlayer = ESX.GetPlayerFromId(source)