mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-30 09:48:52 +00:00
c5376b64c6
* Update for newest ESX * Minor cleanup * Update readme * Link fix in readme * I forgot this * And this * Minor cleanup 2
62 lines
1.8 KiB
Lua
62 lines
1.8 KiB
Lua
ESX = nil
|
|
|
|
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)
|
|
xPlayer.showNotification(_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)
|
|
xPlayer.showNotification(_U('veh_stored'))
|
|
end)
|
|
end
|
|
end)
|
|
|
|
RegisterServerEvent('esx_garage:updateOwnedVehicle')
|
|
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 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)
|
|
|
|
end)
|
|
end)
|