I love this script and am working on a way to minimize the impact of cheats and remove some of the mystery that can surround sales gone wrong. I figure one way to do that is to make it so when a vehicle sells, it makes an entry into a db table, listing the following information. Name of buyer, vehicle, plate, seller and date/time of sale. Mostly it’s working great, except I am stumbling on pulling the seller id from the vehicles_for_sale table. Can any wizard coders take a look at my work please?
I’ve added various lines after line 74 in the server/main.lua and obviously a db table to match.
ESX.RegisterServerCallback("esx-qalle-sellvehicles:buyVehicle", function(source, cb, vehProps, price)
local src = source
local xPlayer = ESX.GetPlayerFromId(src)
local plate = vehProps["plate"]
local seller = MySQL.Sync.fetchAll('SELECT seller FROM vehicles_for_sale WHERE vehicleProps LIKE "%' .. plate .. '%"')
local price = price
local dateNow = os.date('%Y-%m-%d %H:%M')
if xPlayer.getAccount("bank")["money"] >= price or price == 0 then
xPlayer.removeAccountMoney("bank", price)
MySQL.Async.execute("INSERT INTO owned_vehicles (plate, owner, vehicle) VALUES (@plate, @identifier, @vehProps)",
{
["@plate"] = plate,
["@identifier"] = xPlayer["identifier"],
["@vehProps"] = json.encode(vehProps)
}
)
MySQL.Async.execute("INSERT INTO vehicle_sold_used (buyer, vehicle, plate, seller, date) VALUES (@buyer, @vehProps, @plate, @seller, @date)",
{
["@buyer"] = xPlayer.getName(),
["@vehProps"] = json.encode(vehProps),
["@plate"] = plate,
["@seller"] = seller,
["@date"] = dateNow
}
)
im having the issue where when i click to sell it just does nothing, i can set the price but not sell. and yes it was installed the right way. any help?
When you add a police vehicle it dosent and buy it off the lot it dosent go back to the Police garage, i looked in the SQL and its under Null how do i fix this if i wanted to add police cars? for the garage??
I get the 11 vehicle error and when I sell a car it disappears if I own the car If I don’t own the car I can’t sell it also when I sell the car there is no way to buy it