Esx_vehicleshop

Hey at First!
I created a Second vehicleshop but i want to offer different cars in both shops and i dont know how to change this With the databse and the Script. Is there anyone help me?

Sorry. I am a lazy fatass and don’t feel like helping. Good luck!

4 Likes

You’ll duplicate the tables with a different name, and then update those names in the server file.

1 Like

Ok and at which Location i Must change It?

In the database 20 char

in which database ??

what database do you use?

no where can i change the location?

e.x. phpmyadmin, mysql, couchdb?

i mean the location where i can change which databse should be use

What location? 20 char

where i can change the location which table with vehicles should be use in this cardealer

I think you need to read up about databases and study some before administering a server.

1 Like

my once problem is that i dont know where the location is for change which table will be use

Exactly… See my above post. You need to familiarize yourself with general database knowledge. If you have that, my first answer will suffice. You duplicate the resource, duplicate the table in the database, and rename the table in the server.lua file.

1 Like

Ok, Thank you 20 char

How did you add multiple locations for the vehicle shop?

Hello, I would like to have a second vehicle store but with exclusive vehicles, in a nutshell with a different database, could someone help me how can I do that?

Okay for the people how cant under stand this you go to your esx_vehicleshop and copy that and rename it to esx_vehicleshop2 in the esx_vehicleshop in server/main.lua you se the following code:
line 53 -61

	MySQL.Async.execute('INSERT INTO owned_vehicles (owner, plate, vehicle) VALUES (@owner, @plate, @vehicle)',
	{
		['@owner']   = xPlayer.identifier,
		['@plate']   = vehicleProps.plate,
		['@vehicle'] = json.encode(vehicleProps)
	}, function (rowsChanged)
		TriggerClientEvent('esx:showNotification', _source, _U('vehicle_belongs', vehicleProps.plate))
	end)
end)

chage it to

	MySQL.Async.execute('INSERT INTO owned_vehicles2 (owner, plate, vehicle) VALUES (@owner, @plate, @vehicle)',
	{
		['@owner']   = xPlayer.identifier,
		['@plate']   = vehicleProps.plate,
		['@vehicle'] = json.encode(vehicleProps)
	}, function (rowsChanged)
		TriggerClientEvent('esx:showNotification', _source, _U('vehicle_belongs', vehicleProps.plate))
	end)
end)

next to change go to line 76 -75

	MySQL.Async.execute('INSERT INTO owned_vehicles (owner, plate, vehicle) VALUES (@owner, @plate, @vehicle)',
	{
		['@owner']   = xPlayer.identifier,
		['@plate']   = vehicleProps.plate,
		['@vehicle'] = json.encode(vehicleProps)
	}, function (rowsChanged)
		TriggerClientEvent('esx:showNotification', playerId, _U('vehicle_belongs', vehicleProps.plate))
	end)
end)

change it to :

	MySQL.Async.execute('INSERT INTO owned_vehicles2 (owner, plate, vehicle) VALUES (@owner, @plate, @vehicle)',
	{
		['@owner']   = xPlayer.identifier,
		['@plate']   = vehicleProps.plate,
		['@vehicle'] = json.encode(vehicleProps)
	}, function (rowsChanged)
		TriggerClientEvent('esx:showNotification', playerId, _U('vehicle_belongs', vehicleProps.plate))
	end)
end)

go to the next line 77-90

RegisterServerEvent('esx_vehicleshop:setVehicleOwnedSociety')
AddEventHandler('esx_vehicleshop:setVehicleOwnedSociety', function (society, vehicleProps)
	local _source = source
	local xPlayer = ESX.GetPlayerFromId(_source)

	MySQL.Async.execute('INSERT INTO owned_vehicles (owner, plate, vehicle) VALUES (@owner, @plate, @vehicle)',
	{
		['@owner']   = 'society:' .. society,
		['@plate']   = vehicleProps.plate,
		['@vehicle'] = json.encode(vehicleProps),
	}, function (rowsChanged)

	end)
end)

change it to :

RegisterServerEvent('esx_vehicleshop:setVehicleOwnedSociety')
AddEventHandler('esx_vehicleshop:setVehicleOwnedSociety', function (society, vehicleProps)
	local _source = source
	local xPlayer = ESX.GetPlayerFromId(_source)

	MySQL.Async.execute('INSERT INTO owned_vehicles2 (owner, plate, vehicle) VALUES (@owner, @plate, @vehicle)',
	{
		['@owner']   = 'society:' .. society,
		['@plate']   = vehicleProps.plate,
		['@vehicle'] = json.encode(vehicleProps),
	}, function (rowsChanged)

	end)
end)

go to the next line ***92-103***

RegisterServerEvent('esx_vehicleshop:sellVehicle')
AddEventHandler('esx_vehicleshop:sellVehicle', function (vehicle)
	MySQL.Async.fetchAll('SELECT * FROM cardealer_vehicles WHERE vehicle = @vehicle LIMIT 1', {
		['@vehicle'] = vehicle
	}, function (result)
		local id = result[1].id

		MySQL.Async.execute('DELETE FROM cardealer_vehicles WHERE id = @id', {
			['@id'] = id
		})
	end)
end)

change it to :

RegisterServerEvent('esx_vehicleshop:sellVehicle')
AddEventHandler('esx_vehicleshop:sellVehicle', function (vehicle)
	MySQL.Async.fetchAll('SELECT * FROM cardealer_vehicles2 WHERE vehicle = @vehicle LIMIT 1', {
		['@vehicle'] = vehicle
	}, function (result)
		local id = result[1].id

		MySQL.Async.execute('DELETE FROM cardealer_vehicles2 WHERE id = @id', {
			['@id'] = id
		})
	end)
end)

go to the next line : 105-122

RegisterServerEvent('esx_vehicleshop:addToList')
AddEventHandler('esx_vehicleshop:addToList', function(target, model, plate)
	local xPlayer, xTarget = ESX.GetPlayerFromId(source), ESX.GetPlayerFromId(target)
	local dateNow = os.date('%Y-%m-%d %H:%M')

	if xPlayer.job.name ~= 'cardealer' then
		print(('esx_vehicleshop: %s attempted to add a sold vehicle to list!'):format(xPlayer.identifier))
		return
	end

	MySQL.Async.execute('INSERT INTO vehicle_sold (client, model, plate, soldby, date) VALUES (@client, @model, @plate, @soldby, @date)', {
		['@client'] = xTarget.getName(),
		['@model'] = model,
		['@plate'] = plate,
		['@soldby'] = xPlayer.getName(),
		['@date'] = dateNow
	})
end)

go to the next line : 124-129

ESX.RegisterServerCallback('esx_vehicleshop:getSoldVehicles', function (source, cb)

	MySQL.Async.fetchAll('SELECT * FROM vehicle_sold', {}, function(result)
		cb(result)
	end)
end)

change it to :

ESX.RegisterServerCallback('esx_vehicleshop:getSoldVehicles', function (source, cb)

	MySQL.Async.fetchAll('SELECT * FROM vehicle_sold2', {}, function(result)
		cb(result)
	end)
end)

go to the next Line 131-156 :

RegisterServerEvent('esx_vehicleshop:rentVehicle')
AddEventHandler('esx_vehicleshop:rentVehicle', function (vehicle, plate, playerName, basePrice, rentPrice, target)
	local xPlayer = ESX.GetPlayerFromId(target)

	MySQL.Async.fetchAll('SELECT * FROM cardealer_vehicles WHERE vehicle = @vehicle LIMIT 1', {
		['@vehicle'] = vehicle
	}, function (result)
		local id    = result[1].id
		local price = result[1].price
		local owner = xPlayer.identifier

		MySQL.Async.execute('DELETE FROM cardealer_vehicles WHERE id = @id', {
			['@id'] = id
		})

		MySQL.Async.execute('INSERT INTO rented_vehicles (vehicle, plate, player_name, base_price, rent_price, owner) VALUES (@vehicle, @plate, @player_name, @base_price, @rent_price, @owner)',
		{
			['@vehicle']     = vehicle,
			['@plate']       = plate,
			['@player_name'] = playerName,
			['@base_price']  = basePrice,
			['@rent_price']  = rentPrice,
			['@owner']       = owner
		})
	end)
end)```

change it to: 

RegisterServerEvent(‘esx_vehicleshop:rentVehicle’)
AddEventHandler(‘esx_vehicleshop:rentVehicle’, function (vehicle, plate, playerName, basePrice, rentPrice, target)
local xPlayer = ESX.GetPlayerFromId(target)

MySQL.Async.fetchAll('SELECT * FROM cardealer_vehicles WHERE vehicle = @vehicle LIMIT 1', {
	['@vehicle'] = vehicle
}, function (result)
	local id    = result[1].id
	local price = result[1].price
	local owner = xPlayer.identifier

	MySQL.Async.execute('DELETE FROM cardealer_vehicles2 WHERE id = @id', {
		['@id'] = id
	})

	MySQL.Async.execute('INSERT INTO rented_vehicles2 (vehicle, plate, player_name, base_price, rent_price, owner) VALUES (@vehicle, @plate, @player_name, @base_price, @rent_price, @owner)',
	{
		['@vehicle']     = vehicle,
		['@plate']       = plate,
		['@player_name'] = playerName,
		['@base_price']  = basePrice,
		['@rent_price']  = rentPrice,
		['@owner']       = owner
	})
end)

end)


go to the next line 229-254:

ESX.RegisterServerCallback(‘esx_vehicleshop:buyVehicleSociety’, function (source, cb, society, vehicleModel)
local vehicleData = nil

for i=1, #Vehicles, 1 do
	if Vehicles[i].model == vehicleModel then
		vehicleData = Vehicles[i]
		break
	end
end

TriggerEvent('esx_addonaccount:getSharedAccount', 'society_' .. society, function (account)
	if account.money >= vehicleData.price then
		account.removeMoney(vehicleData.price)

		MySQL.Async.execute('INSERT INTO cardealer_vehicles (vehicle, price) VALUES (@vehicle, @price)', {
			['@vehicle'] = vehicleData.model,
			['@price']   = vehicleData.price
		}, function(rowsChanged)
			cb(true)
		end)

	else
		cb(false)
	end
end)

end)


change it to : 

ESX.RegisterServerCallback(‘esx_vehicleshop:buyVehicleSociety’, function (source, cb, society, vehicleModel)
local vehicleData = nil

for i=1, #Vehicles, 1 do
	if Vehicles[i].model == vehicleModel then
		vehicleData = Vehicles[i]
		break
	end
end

TriggerEvent('esx_addonaccount:getSharedAccount', 'society_' .. society, function (account)
	if account.money >= vehicleData.price then
		account.removeMoney(vehicleData.price)

		MySQL.Async.execute('INSERT INTO cardealer_vehicles2 (vehicle, price) VALUES (@vehicle, @price)', {
			['@vehicle'] = vehicleData.model,
			['@price']   = vehicleData.price
		}, function(rowsChanged)
			cb(true)
		end)

	else
		cb(false)
	end
end)

end)


go to the next line 256-269 :

ESX.RegisterServerCallback(‘esx_vehicleshop:buyVehicleSociety’, function (source, cb, society, vehicleModel)
local vehicleData = nil

for i=1, #Vehicles, 1 do
	if Vehicles[i].model == vehicleModel then
		vehicleData = Vehicles[i]
		break
	end
end

TriggerEvent('esx_addonaccount:getSharedAccount', 'society_' .. society, function (account)
	if account.money >= vehicleData.price then
		account.removeMoney(vehicleData.price)

		MySQL.Async.execute('INSERT INTO cardealer_vehicles (vehicle, price) VALUES (@vehicle, @price)', {
			['@vehicle'] = vehicleData.model,
			['@price']   = vehicleData.price
		}, function(rowsChanged)
			cb(true)
		end)

	else
		cb(false)
	end
end)

end)


change it to : 

ESX.RegisterServerCallback(‘esx_vehicleshop:getCommercialVehicles’, function (source, cb)
MySQL.Async.fetchAll(‘SELECT * FROM cardealer_vehicles2 ORDER BY vehicle ASC’, {}, function (result)
local vehicles = {}

	for i=1, #result, 1 do
		table.insert(vehicles, {
			name  = result[i].vehicle,
			price = result[i].price
		})
	end

	cb(vehicles)
end)

end)


go to the next line 272-299:

RegisterServerEvent(‘esx_vehicleshop:returnProvider’)
AddEventHandler(‘esx_vehicleshop:returnProvider’, function(vehicleModel)
local _source = source

MySQL.Async.fetchAll('SELECT * FROM cardealer_vehicles WHERE vehicle = @vehicle LIMIT 1', {
	['@vehicle'] = vehicleModel
}, function (result)

	if result[1] then
		local id    = result[1].id
		local price = ESX.Math.Round(result[1].price * 0.75)

		TriggerEvent('esx_addonaccount:getSharedAccount', 'society_cardealer', function(account)
			account.addMoney(price)
		end)

		MySQL.Async.execute('DELETE FROM cardealer_vehicles WHERE id = @id', {
			['@id'] = id
		})

		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

end)

end)


change it to : 

RegisterServerEvent(‘esx_vehicleshop:returnProvider’)
AddEventHandler(‘esx_vehicleshop:returnProvider’, function(vehicleModel)
local _source = source

MySQL.Async.fetchAll('SELECT * FROM cardealer_vehicles2 WHERE vehicle = @vehicle LIMIT 1', {
	['@vehicle'] = vehicleModel
}, function (result)

	if result[1] then
		local id    = result[1].id
		local price = ESX.Math.Round(result[1].price * 0.75)

		TriggerEvent('esx_addonaccount:getSharedAccount', 'society_cardealer', function(account)
			account.addMoney(price)
		end)

		MySQL.Async.execute('DELETE FROM cardealer_vehicles2 WHERE id = @id', {
			['@id'] = id
		})

		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

end)

end)


go to the next line 301-315:

ESX.RegisterServerCallback(‘esx_vehicleshop:getRentedVehicles’, function (source, cb)
MySQL.Async.fetchAll(‘SELECT * FROM rented_vehicles ORDER BY player_name ASC’, {}, function (result)
local vehicles = {}

	for i=1, #result, 1 do
		table.insert(vehicles, {
			name       = result[i].vehicle,
			plate      = result[i].plate,
			playerName = result[i].player_name
		})
	end

	cb(vehicles)
end)

end)


change it to : 

ESX.RegisterServerCallback(‘esx_vehicleshop:getRentedVehicles’, function (source, cb)
MySQL.Async.fetchAll(‘SELECT * FROM rented_vehicles2 ORDER BY player_name ASC’, {}, function (result)
local vehicles = {}

	for i=1, #result, 1 do
		table.insert(vehicles, {
			name       = result[i].vehicle,
			plate      = result[i].plate,
			playerName = result[i].player_name
		})
	end

	cb(vehicles)
end)

end)


go to the next line 317-340: 

ESX.RegisterServerCallback(‘esx_vehicleshop:giveBackVehicle’, function (source, cb, plate)
MySQL.Async.fetchAll(‘SELECT * FROM rented_vehicles WHERE plate = @plate’, {
[’@plate’] = plate
}, function (result)
if result[1] ~= nil then
local vehicle = result[1].vehicle
local basePrice = result[1].base_price

		MySQL.Async.execute('INSERT INTO cardealer_vehicles (vehicle, price) VALUES (@vehicle, @price)', {
			['@vehicle'] = vehicle,
			['@price']   = basePrice
		})

		MySQL.Async.execute('DELETE FROM rented_vehicles WHERE plate = @plate', {
			['@plate'] = plate
		})

		RemoveOwnedVehicle(plate)
		cb(true)
	else
		cb(false)
	end
end)

end)


change it to :

ESX.RegisterServerCallback(‘esx_vehicleshop:giveBackVehicle’, function (source, cb, plate)
MySQL.Async.fetchAll(‘SELECT * FROM rented_vehicles WHERE plate = @plate’, {
[’@plate’] = plate
}, function (result)
if result[1] ~= nil then
local vehicle = result[1].vehicle
local basePrice = result[1].base_price

		MySQL.Async.execute('INSERT INTO cardealer_vehicles2 (vehicle, price) VALUES (@vehicle, @price)', {
			['@vehicle'] = vehicle,
			['@price']   = basePrice
		})

		MySQL.Async.execute('DELETE FROM rented_vehicles2 WHERE plate = @plate', {
			['@plate'] = plate
		})

		RemoveOwnedVehicle(plate)
		cb(true)
	else
		cb(false)
	end
end)

end)


go to the next Line ***342-419***:

ESX.RegisterServerCallback(‘esx_vehicleshop: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_vehicleshop: %s attempted to sell an unknown vehicle!'):format(GetPlayerIdentifiers(source)[1]))
	cb(false)
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 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)
						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 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
										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 model mismatch!'):format(xPlayer.identifier))
									cb(false)
								end
							else
								cb(false)
							end
						end)
					else
						cb(false)
					end
				end
			end)
		end
	end)
end

end)


change it to :

ESX.RegisterServerCallback(‘esx_vehicleshop: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_vehicleshop: %s attempted to sell an unknown vehicle!'):format(GetPlayerIdentifiers(source)[1]))
	cb(false)
else
	MySQL.Async.fetchAll('SELECT * FROM rented_vehicles2 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_vehicles2 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)
						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 model mismatch!'):format(xPlayer.identifier))
						cb(false)
					end
				else
					if xPlayer.job.grade_name == 'boss' then
						MySQL.Async.fetchAll('SELECT * FROM owned_vehicles2 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)
									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 model mismatch!'):format(xPlayer.identifier))
									cb(false)
								end
							else
								cb(false)
							end
						end)
					else
						cb(false)
					end
				end
			end)
		end
	end)
end

end)


go to the next line 422-494:

ESX.RegisterServerCallback(‘esx_vehicleshop:getStockItems’, function (source, cb)
TriggerEvent(‘esx_addoninventory:getSharedInventory’, ‘society_cardealer’, function(inventory)
cb(inventory.items)
end)
end)

ESX.RegisterServerCallback(‘esx_vehicleshop:getPlayerInventory’, function (source, cb)
local xPlayer = ESX.GetPlayerFromId(source)
local items = xPlayer.inventory

cb({items = items})

end)

ESX.RegisterServerCallback(‘esx_vehicleshop:isPlateTaken’, function (source, cb, plate)
MySQL.Async.fetchAll(‘SELECT 1 FROM owned_vehicles WHERE plate = @plate’, {
[’@plate’] = plate
}, function (result)
cb(result[1] ~= nil)
end)
end)

ESX.RegisterServerCallback(‘esx_vehicleshop:retrieveJobVehicles’, function (source, cb, type)
local xPlayer = ESX.GetPlayerFromId(source)

MySQL.Async.fetchAll('SELECT * FROM owned_vehicles WHERE owner = @owner AND type = @type AND job = @job', {
	['@owner'] = xPlayer.identifier,
	['@type'] = type,
	['@job'] = xPlayer.job.name
}, function (result)
	cb(result)
end)

end)

RegisterServerEvent(‘esx_vehicleshop:setJobVehicleState’)
AddEventHandler(‘esx_vehicleshop:setJobVehicleState’, function(plate, state)
local xPlayer = ESX.GetPlayerFromId(source)

MySQL.Async.execute('UPDATE owned_vehicles SET `stored` = @stored WHERE plate = @plate AND job = @job', {
	['@stored'] = state,
	['@plate'] = plate,
	['@job'] = xPlayer.job.name
}, function(rowsChanged)
	if rowsChanged == 0 then
		print(('esx_vehicleshop: %s exploited the garage!'):format(xPlayer.identifier))
	end
end)

end)

function PayRent(d, h, m)
MySQL.Async.fetchAll(‘SELECT * FROM rented_vehicles’, {}, function (result)
for i=1, #result, 1 do
local xPlayer = ESX.GetPlayerFromIdentifier(result[i].owner)

		-- message player if connected
		if xPlayer ~= nil then
			xPlayer.removeAccountMoney('bank', result[i].rent_price)
			TriggerClientEvent('esx:showNotification', xPlayer.source, _U('paid_rental', ESX.Math.GroupDigits(result[i].rent_price)))
		else -- pay rent either way
			MySQL.Sync.execute('UPDATE users SET bank = bank - @bank WHERE identifier = @identifier',
			{
				['@bank']       = result[i].rent_price,
				['@identifier'] = result[i].owner
			})
		end

		TriggerEvent('esx_addonaccount:getSharedAccount', 'society_cardealer', function(account)
			account.addMoney(result[i].rent_price)
		end)
	end
end)

end

TriggerEvent(‘cron:runAt’, 22, 00, PayRent)


change it to : 

ESX.RegisterServerCallback(‘esx_vehicleshop:getStockItems’, function (source, cb)
TriggerEvent(‘esx_addoninventory:getSharedInventory’, ‘society_cardealer’, function(inventory)
cb(inventory.items)
end)
end)

ESX.RegisterServerCallback(‘esx_vehicleshop:getPlayerInventory’, function (source, cb)
local xPlayer = ESX.GetPlayerFromId(source)
local items = xPlayer.inventory

cb({items = items})

end)

ESX.RegisterServerCallback(‘esx_vehicleshop:isPlateTaken’, function (source, cb, plate)
MySQL.Async.fetchAll(‘SELECT 1 FROM owned_vehicles2 WHERE plate = @plate’, {
[’@plate’] = plate
}, function (result)
cb(result[1] ~= nil)
end)
end)

ESX.RegisterServerCallback(‘esx_vehicleshop:retrieveJobVehicles’, function (source, cb, type)
local xPlayer = ESX.GetPlayerFromId(source)

MySQL.Async.fetchAll('SELECT * FROM owned_vehicles2 WHERE owner = @owner AND type = @type AND job = @job', {
	['@owner'] = xPlayer.identifier,
	['@type'] = type,
	['@job'] = xPlayer.job.name
}, function (result)
	cb(result)
end)

end)

RegisterServerEvent(‘esx_vehicleshop:setJobVehicleState’)
AddEventHandler(‘esx_vehicleshop:setJobVehicleState’, function(plate, state)
local xPlayer = ESX.GetPlayerFromId(source)

MySQL.Async.execute('UPDATE owned_vehicles2 SET `stored` = @stored WHERE plate = @plate AND job = @job', {
	['@stored'] = state,
	['@plate'] = plate,
	['@job'] = xPlayer.job.name
}, function(rowsChanged)
	if rowsChanged == 0 then
		print(('esx_vehicleshop: %s exploited the garage!'):format(xPlayer.identifier))
	end
end)

end)

function PayRent(d, h, m)
MySQL.Async.fetchAll(‘SELECT * FROM rented_vehicles2’, {}, function (result)
for i=1, #result, 1 do
local xPlayer = ESX.GetPlayerFromIdentifier(result[i].owner)

		-- message player if connected
		if xPlayer ~= nil then
			xPlayer.removeAccountMoney('bank', result[i].rent_price)
			TriggerClientEvent('esx:showNotification', xPlayer.source, _U('paid_rental', ESX.Math.GroupDigits(result[i].rent_price)))
		else -- pay rent either way
			MySQL.Sync.execute('UPDATE users SET bank = bank - @bank WHERE identifier = @identifier',
			{
				['@bank']       = result[i].rent_price,
				['@identifier'] = result[i].owner
			})
		end

		TriggerEvent('esx_addonaccount:getSharedAccount', 'society_cardealer', function(account)
			account.addMoney(result[i].rent_price)
		end)
	end
end)

end

TriggerEvent(‘cron:runAt’, 22, 00, PayRent)


Alle done you can youse your second cardealer
4 Likes

lol thank you for helping these guys, i had trouble when i first started with this too. simple but tricky when you first start xD