So hi, im making a script so players come down to my custom dealership(and mechanic) so they go to a marker next to the store and then they sell there vehicle and the dealership gets the vehicle (so they can sell it again) and the player gets the money (from the society of the dealership) but i can not get it to work
here is my data base:
and here is the server script:
ESX.RegisterServerCallback('esx_amigos:resellVehicle', function (source, cb, plate, model)
local resellPrice = 0
-- calculate the resell price
for i=1, #Vehicles, 1 do
if GetHashKey(Vehicles[i].model) == model then
resellPrice = ESX.Math.Round(Vehicles[i].price / 100 * Config.ResellPercentage)
break
end
end
if resellPrice == 0 then
print(('esx_amigos: %s attempted to sell an unknown vehicle!'):format(GetPlayerIdentifiers(source)[1]))
cb(false)
end
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)
local vehicle = result[1].vehicle
local basePrice = result[1].base_price
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
if account.money >= resellPrice then
account.removeMoney(resellPrice)
MySQL.Async.execute('INSERT INTO amigos_vehicles (vehicle, price) VALUES (@vehicle, @price)',
{
['@vehicle'] = vehicle,
['@price'] = nil
})
MySQL.Async.execute('DELETE FROM owned_vehicles WHERE plate = @plate', {
['@plate'] = plate
})
cb(true)
else
print(('esx_amigos: %s attempted to sell an vehicle with plate mismatch!'):format(xPlayer.identifier))
cb(false)
end
else
print(('esx_amigos: %s attempted to sell an vehicle with model mismatch!'):format(xPlayer.identifier))
cb(false)
end
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
TriggerEvent('esx_addonaccount:getSharedAccount', 'society_' .. society, function (account)
if account.money >= resellPrice then
account.removeMoney(resellPrice)
MySQL.Async.execute('INSERT INTO amigos_vehicles (vehicle, price) VALUES (@vehicle, @price)',
{
['@vehicle'] = vehicle,
['@price'] = nil
})
MySQL.Async.execute('DELETE FROM owned_vehicles WHERE plate = @plate', {
['@plate'] = plate
})
cb(true)
else
print(('esx_amigos: %s attempted to sell an vehicle with plate mismatch!'):format(xPlayer.identifier))
cb(false)
end
end)
else
print(('esx_amigos: %s attempted to sell an vehicle with model mismatch!'):format(xPlayer.identifier))
cb(false)
end
else
cb(false)
end
end
end)
else
cb(false)
end
end
end
end)
end
end)
end)
error message: