mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-02 11:18:53 +00:00
Updated to support new vehicle system
This commit is contained in:
+1
-1
@@ -175,7 +175,7 @@ AddEventHandler('esx_property:hasEnteredMarker', function(name, part, parking)
|
||||
ESX.Game.SpawnLocalVehicle(vehicles[j].vehicle.model, {
|
||||
x = garage.Parkings[i].Pos.x,
|
||||
y = garage.Parkings[i].Pos.y,
|
||||
z = garage.Parkings[i].Pos.z + Config.ZDiff
|
||||
z = garage.Parkings[i].Pos.z + Config.ZDiff
|
||||
}, garage.Parkings[i].Heading, function(vehicle)
|
||||
ESX.Game.SetVehicleProperties(vehicle, vehicles[j].vehicle)
|
||||
end)
|
||||
|
||||
+38
-87
@@ -4,109 +4,60 @@ TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
|
||||
|
||||
RegisterServerEvent('esx_garage:setParking')
|
||||
AddEventHandler('esx_garage:setParking', function(garage, zone, vehicleProps)
|
||||
|
||||
local _source = source
|
||||
local xPlayer = ESX.GetPlayerFromId(_source)
|
||||
|
||||
if vehicleProps == false then
|
||||
|
||||
MySQL.Async.execute(
|
||||
'DELETE FROM `user_parkings` WHERE `identifier` = @identifier AND `garage` = @garage AND zone = @zone',
|
||||
{
|
||||
['@identifier'] = xPlayer.identifier,
|
||||
['@garage'] = garage;
|
||||
['@zone'] = zone
|
||||
}, function(rowsChanged)
|
||||
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('veh_released'))
|
||||
end
|
||||
)
|
||||
|
||||
MySQL.Async.execute('DELETE FROM `user_parkings` WHERE `identifier` = @identifier AND `garage` = @garage AND zone = @zone',
|
||||
{
|
||||
['@identifier'] = xPlayer.identifier,
|
||||
['@garage'] = garage;
|
||||
['@zone'] = zone
|
||||
}, function(rowsChanged)
|
||||
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('veh_released'))
|
||||
end)
|
||||
else
|
||||
|
||||
MySQL.Async.execute(
|
||||
'INSERT INTO `user_parkings` (`identifier`, `garage`, `zone`, `vehicle`) VALUES (@identifier, @garage, @zone, @vehicle)',
|
||||
{
|
||||
['@identifier'] = xPlayer.identifier,
|
||||
['@garage'] = garage;
|
||||
['@zone'] = zone,
|
||||
['vehicle'] = json.encode(vehicleProps)
|
||||
}, function(rowsChanged)
|
||||
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('veh_stored'))
|
||||
end
|
||||
)
|
||||
|
||||
MySQL.Async.execute('INSERT INTO `user_parkings` (`identifier`, `garage`, `zone`, `vehicle`) VALUES (@identifier, @garage, @zone, @vehicle)',
|
||||
{
|
||||
['@identifier'] = xPlayer.identifier,
|
||||
['@garage'] = garage;
|
||||
['@zone'] = zone,
|
||||
['vehicle'] = json.encode(vehicleProps)
|
||||
}, function(rowsChanged)
|
||||
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('veh_stored'))
|
||||
end)
|
||||
end
|
||||
|
||||
end)
|
||||
|
||||
RegisterServerEvent('esx_garage:updateOwnedVehicle')
|
||||
AddEventHandler('esx_garage: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(result)
|
||||
|
||||
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)
|
||||
AddEventHandler('esx_garage:updateOwnedVehicle', function(vehicleProps)
|
||||
MySQL.Async.execute('UPDATE owned_vehicles SET vehicle = @vehicle WHERE plate = @plate', {
|
||||
['@plate'] = vehicleProps.plate,
|
||||
['@vehicle'] = json.encode(vehicleProps)
|
||||
})
|
||||
end)
|
||||
|
||||
ESX.RegisterServerCallback('esx_vehicleshop:getVehiclesInGarage', function(source, cb, garage)
|
||||
|
||||
local _source = source
|
||||
local xPlayer = ESX.GetPlayerFromId(_source)
|
||||
|
||||
MySQL.Async.fetchAll(
|
||||
'SELECT * FROM `user_parkings` WHERE `identifier` = @identifier AND garage = @garage',
|
||||
{
|
||||
['@identifier'] = xPlayer.identifier,
|
||||
['@garage'] = garage
|
||||
},
|
||||
function(result)
|
||||
|
||||
local vehicles = {}
|
||||
|
||||
for i=1, #result, 1 do
|
||||
table.insert(vehicles, {
|
||||
zone = result[i].zone,
|
||||
vehicle = json.decode(result[i].vehicle)
|
||||
})
|
||||
end
|
||||
|
||||
cb(vehicles)
|
||||
MySQL.Async.fetchAll('SELECT * FROM `user_parkings` WHERE `identifier` = @identifier AND garage = @garage',
|
||||
{
|
||||
['@identifier'] = xPlayer.identifier,
|
||||
['@garage'] = garage
|
||||
}, function(result)
|
||||
|
||||
local vehicles = {}
|
||||
for i=1, #result, 1 do
|
||||
table.insert(vehicles, {
|
||||
zone = result[i].zone,
|
||||
vehicle = json.decode(result[i].vehicle)
|
||||
})
|
||||
end
|
||||
)
|
||||
|
||||
cb(vehicles)
|
||||
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user