ESX.RegisterServerCallback('esx_vehicleshop:buyVehicle', function(source, cb, model, plate)
local xPlayer = ESX.GetPlayerFromId(source)
local modelPrice
for k,v in ipairs(vehicles) do
if model == v.model then
modelPrice = v.price
break
end
end
if modelPrice and xPlayer.getMoney() >= modelPrice then
xPlayer.removeMoney(modelPrice)
exports.ghmattimysql:execute('INSERT INTO owned_vehicles (owner, plate, vehicle) VALUES (@owner, @plate, @vehicle)', {
['@owner'] = xPlayer.identifier,
['@plate'] = plate,
['@vehicle'] = json.encode({model = GetHashKey(model), plate = plate})
}, function(rowsChanged)
xPlayer.showNotification(_U('vehicle_belongs', plate))
info = {
model = v.model,
plaka = plate,
}
xPlayer.addInventoryItem('vehiclekey', 1, false, info)
cb(true)
end)
else
cb(false)
end
end)