mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-04 08:13:21 +00:00
Proper cb usage
This commit is contained in:
+57
-70
@@ -71,7 +71,7 @@ AddEventHandler('esx_vehicleshop:setVehicleOwnedPlayerId', function (playerId, v
|
||||
['@vehicle'] = json.encode(vehicleProps)
|
||||
}, function (rowsChanged)
|
||||
TriggerClientEvent('esx:showNotification', playerId, _U('vehicle_belongs', vehicleProps.plate))
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
RegisterServerEvent('esx_vehicleshop:setVehicleOwnedSociety')
|
||||
@@ -166,7 +166,7 @@ AddEventHandler('esx_vehicleshop:getStockItem', function (itemName, count)
|
||||
|
||||
-- is there enough in the society?
|
||||
if count > 0 and item.count >= count then
|
||||
|
||||
|
||||
-- can the player carry the said amount of x item?
|
||||
if sourceItem.limit ~= -1 and (sourceItem.count + count) > sourceItem.limit then
|
||||
TriggerClientEvent('esx:showNotification', _source, _U('player_cannot_hold'))
|
||||
@@ -240,8 +240,7 @@ ESX.RegisterServerCallback('esx_vehicleshop:buyVehicleSociety', function (source
|
||||
if account.money >= vehicleData.price then
|
||||
account.removeMoney(vehicleData.price)
|
||||
|
||||
MySQL.Async.execute('INSERT INTO cardealer_vehicles (vehicle, price) VALUES (@vehicle, @price)',
|
||||
{
|
||||
MySQL.Async.execute('INSERT INTO cardealer_vehicles (vehicle, price) VALUES (@vehicle, @price)', {
|
||||
['@vehicle'] = vehicleData.model,
|
||||
['@price'] = vehicleData.price
|
||||
}, function(rowsChanged)
|
||||
@@ -292,7 +291,7 @@ AddEventHandler('esx_vehicleshop:returnProvider', function(vehicleModel)
|
||||
|
||||
TriggerClientEvent('esx:showNotification', _source, _U('vehicle_sold_for', vehicleModel, ESX.Math.GroupDigits(price)))
|
||||
else
|
||||
|
||||
|
||||
print(('esx_vehicleshop: %s attempted selling an invalid vehicle!'):format(GetPlayerIdentifiers(_source)[1]))
|
||||
end
|
||||
|
||||
@@ -323,8 +322,7 @@ ESX.RegisterServerCallback('esx_vehicleshop:giveBackVehicle', function (source,
|
||||
local vehicle = result[1].vehicle
|
||||
local basePrice = result[1].base_price
|
||||
|
||||
MySQL.Async.execute('INSERT INTO cardealer_vehicles (vehicle, price) VALUES (@vehicle, @price)',
|
||||
{
|
||||
MySQL.Async.execute('INSERT INTO cardealer_vehicles (vehicle, price) VALUES (@vehicle, @price)', {
|
||||
['@vehicle'] = vehicle,
|
||||
['@price'] = basePrice
|
||||
})
|
||||
@@ -355,80 +353,69 @@ ESX.RegisterServerCallback('esx_vehicleshop:resellVehicle', function (source, cb
|
||||
if resellPrice == 0 then
|
||||
print(('esx_vehicleshop: %s attempted to sell an unknown vehicle!'):format(GetPlayerIdentifiers(source)[1]))
|
||||
cb(false)
|
||||
end
|
||||
else
|
||||
MySQL.Async.fetchAll('SELECT * FROM rented_vehicles WHERE plate = @plate', {
|
||||
['@plate'] = plate
|
||||
}, function (result)
|
||||
if result[1] then -- is it a rented vehicle?
|
||||
cb(false) -- it is, don't let the player sell it since he doesn't own it
|
||||
else
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
|
||||
MySQL.Async.fetchAll('SELECT * FROM rented_vehicles WHERE plate = @plate', {
|
||||
['@plate'] = plate
|
||||
}, function (result)
|
||||
if result[1] then -- is it a rented vehicle?
|
||||
cb(false) -- it is, don't let the player sell it since he doesn't own it
|
||||
else
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
MySQL.Async.fetchAll('SELECT * FROM owned_vehicles WHERE owner = @owner AND @plate = plate', {
|
||||
['@owner'] = xPlayer.identifier,
|
||||
['@plate'] = plate
|
||||
}, function (result)
|
||||
if result[1] then -- does the owner match?
|
||||
local vehicle = json.decode(result[1].vehicle)
|
||||
|
||||
MySQL.Async.fetchAll('SELECT * FROM owned_vehicles WHERE owner = @owner AND @plate = plate', {
|
||||
['@owner'] = xPlayer.identifier,
|
||||
['@plate'] = plate
|
||||
}, function (result)
|
||||
|
||||
if result[1] then -- does the owner match?
|
||||
|
||||
local vehicle = json.decode(result[1].vehicle)
|
||||
|
||||
if vehicle.model == model then
|
||||
if vehicle.plate == plate then
|
||||
xPlayer.addMoney(resellPrice)
|
||||
RemoveOwnedVehicle(plate)
|
||||
|
||||
cb(true)
|
||||
if vehicle.model == model then
|
||||
if vehicle.plate == plate then
|
||||
xPlayer.addMoney(resellPrice)
|
||||
RemoveOwnedVehicle(plate)
|
||||
cb(true)
|
||||
else
|
||||
print(('esx_vehicleshop: %s attempted to sell an vehicle with plate mismatch!'):format(xPlayer.identifier))
|
||||
cb(false)
|
||||
end
|
||||
else
|
||||
print(('esx_vehicleshop: %s attempted to sell an vehicle with plate mismatch!'):format(xPlayer.identifier))
|
||||
print(('esx_vehicleshop: %s attempted to sell an vehicle with model mismatch!'):format(xPlayer.identifier))
|
||||
cb(false)
|
||||
end
|
||||
else
|
||||
print(('esx_vehicleshop: %s attempted to sell an vehicle with model mismatch!'):format(xPlayer.identifier))
|
||||
cb(false)
|
||||
end
|
||||
if xPlayer.job.grade_name == 'boss' then
|
||||
MySQL.Async.fetchAll('SELECT * FROM owned_vehicles WHERE owner = @owner AND @plate = plate', {
|
||||
['@owner'] = 'society:' .. xPlayer.job.name,
|
||||
['@plate'] = plate
|
||||
}, function (result)
|
||||
if result[1] then
|
||||
local vehicle = json.decode(result[1].vehicle)
|
||||
|
||||
else
|
||||
|
||||
if xPlayer.job.grade_name == 'boss' then
|
||||
MySQL.Async.fetchAll('SELECT * FROM owned_vehicles WHERE owner = @owner AND @plate = plate', {
|
||||
['@owner'] = 'society:' .. xPlayer.job.name,
|
||||
['@plate'] = plate
|
||||
}, function (result)
|
||||
|
||||
if result[1] then
|
||||
|
||||
local vehicle = json.decode(result[1].vehicle)
|
||||
|
||||
if vehicle.model == model then
|
||||
if vehicle.plate == plate then
|
||||
xPlayer.addMoney(resellPrice)
|
||||
RemoveOwnedVehicle(plate)
|
||||
|
||||
cb(true)
|
||||
if vehicle.model == model then
|
||||
if vehicle.plate == plate then
|
||||
xPlayer.addMoney(resellPrice)
|
||||
RemoveOwnedVehicle(plate)
|
||||
cb(true)
|
||||
else
|
||||
print(('esx_vehicleshop: %s attempted to sell an vehicle with plate mismatch!'):format(xPlayer.identifier))
|
||||
cb(false)
|
||||
end
|
||||
else
|
||||
print(('esx_vehicleshop: %s attempted to sell an vehicle with plate mismatch!'):format(xPlayer.identifier))
|
||||
print(('esx_vehicleshop: %s attempted to sell an vehicle with model mismatch!'):format(xPlayer.identifier))
|
||||
cb(false)
|
||||
end
|
||||
else
|
||||
print(('esx_vehicleshop: %s attempted to sell an vehicle with model mismatch!'):format(xPlayer.identifier))
|
||||
cb(false)
|
||||
end
|
||||
|
||||
else
|
||||
cb(false)
|
||||
end
|
||||
|
||||
end)
|
||||
else
|
||||
cb(false)
|
||||
end)
|
||||
else
|
||||
cb(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
@@ -440,13 +427,13 @@ end)
|
||||
|
||||
ESX.RegisterServerCallback('esx_vehicleshop:getPlayerInventory', function (source, cb)
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
local items = xPlayer.inventory
|
||||
local items = xPlayer.inventory
|
||||
|
||||
cb({ items = items })
|
||||
cb({items = items})
|
||||
end)
|
||||
|
||||
ESX.RegisterServerCallback('esx_vehicleshop:isPlateTaken', function (source, cb, plate)
|
||||
MySQL.Async.fetchAll('SELECT * FROM owned_vehicles WHERE plate = @plate', {
|
||||
MySQL.Async.fetchAll('SELECT 1 FROM owned_vehicles WHERE plate = @plate', {
|
||||
['@plate'] = plate
|
||||
}, function (result)
|
||||
cb(result[1] ~= nil)
|
||||
|
||||
Reference in New Issue
Block a user