What was the error
Hello, I just bought a vehicle and selling it does not let me lock or unlock it until the server restarts! I use the latest version of esx_vehicleshop … any solution for this?
Hey, I got a great idea what would make your graduation system even more awesome.
Can you set up a system where you have vehicle registration and keys that you can make and issue and management?
–> Key Menu
–> Vehicle documents(Get it when you buy)
–> key system (manufacture)
Feature:
Vehicle documents:
- With this feature you can hand over the vehicle to someone else by handing over the vehicle documents to them.
Key system
- You can create keys while loading keys in a menu you can give these keys to players so that they can unlock and lock the vehicle.
For those with the new Version of Vehicle Shop
Server/main.lua
Find
RegisterNetEvent('esx_vehicleshop:setVehicleOwnedPlayerId')
AddEventHandler('esx_vehicleshop:setVehicleOwnedPlayerId', function(playerId, vehicleProps, model, label)
local xPlayer, xTarget = ESX.GetPlayerFromId(source), ESX.GetPlayerFromId(playerId)
if xPlayer.job.name == 'cardealer' and xTarget then
MySQL.Async.fetchAll('SELECT id FROM cardealer_vehicles WHERE vehicle = @vehicle LIMIT 1', {
['@vehicle'] = model
}, function(result)
if result[1] then
local id = result[1].id
MySQL.Async.execute('DELETE FROM cardealer_vehicles WHERE id = @id', {
['@id'] = id
}, function(rowsChanged)
if rowsChanged == 1 then
MySQL.Async.execute('INSERT INTO owned_vehicles (owner, plate, vehicle) VALUES (@owner, @plate, @vehicle)', {
['@owner'] = xTarget.identifier,
['@plate'] = vehicleProps.plate,
['@vehicle'] = json.encode(vehicleProps)
}, function(rowsChanged)
xPlayer.showNotification(_U('vehicle_set_owned', vehicleProps.plate, xTarget.getName()))
xTarget.showNotification(_U('vehicle_belongs', vehicleProps.plate))
end)
local dateNow = os.date('%Y-%m-%d %H:%M')
MySQL.Async.execute('INSERT INTO vehicle_sold (client, model, plate, soldby, date) VALUES (@client, @model, @plate, @soldby, @date)', {
['@client'] = xTarget.getName(),
['@model'] = label,
['@plate'] = vehicleProps.plate,
['@soldby'] = xPlayer.getName(),
['@date'] = dateNow
})
end
end)
end
end)
> ADD THIS HERE
> TriggerEvent('shorty_slocks:transferOwner', vehicleProps.plate, playerId)
end
end)
That should work for you
I may look into this after i have completed the vehicle theft system, along with 10 other projects currently on the go 
I already found fix. If anybody facing same problem with me here how to fix:
If Config.EnablePlayerManagement = true
RegisterNetEvent('esx_vehicleshop:setVehicleOwnedPlayerId')
AddEventHandler('esx_vehicleshop:setVehicleOwnedPlayerId', function(playerId, vehicleProps, model, label)
local xPlayer, xTarget = ESX.GetPlayerFromId(source), ESX.GetPlayerFromId(playerId)
if xPlayer.job.name == 'cardealer' and xTarget then
MySQL.Async.fetchAll('SELECT id FROM cardealer_vehicles WHERE vehicle = @vehicle LIMIT 1', {
['@vehicle'] = model
}, function(result)
if result[1] then
local id = result[1].id
MySQL.Async.execute('DELETE FROM cardealer_vehicles WHERE id = @id', {
['@id'] = id
}, function(rowsChanged)
if rowsChanged == 1 then
MySQL.Async.execute('INSERT INTO owned_vehicles (owner, plate, vehicle) VALUES (@owner, @plate, @vehicle)', {
['@owner'] = xTarget.identifier,
['@plate'] = vehicleProps.plate,
['@vehicle'] = json.encode(vehicleProps)
}, function(rowsChanged)
xPlayer.showNotification(_U('vehicle_set_owned', vehicleProps.plate, xTarget.getName()))
xTarget.showNotification(_U('vehicle_belongs', vehicleProps.plate))
end)
local dateNow = os.date('%Y-%m-%d %H:%M')
MySQL.Async.execute('INSERT INTO vehicle_sold (client, model, plate, soldby, date) VALUES (@client, @model, @plate, @soldby, @date)', {
['@client'] = xTarget.getName(),
['@model'] = label,
['@plate'] = vehicleProps.plate,
['@soldby'] = xPlayer.getName(),
['@date'] = dateNow
})
end
end)
end
end)
end
TriggerEvent('shorty_slocks:transferOwner', vehicleProps.plate, playerId)
end)
If Config.EnablePlayerManagement = false
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)
MySQL.Async.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))
cb(true)
end)
else
cb(false)
end
TriggerEvent('shorty_slocks:transferOwner', plate, source)
end)
Thank you for sharing nice script op
The remote keyfob from outside the vehicle only locks police vehicles & not regular civilian vehicles along with the animation playing?
Civilian vehicles i can’t lock from the outside i have to be inside the car.
Are you trying to lock civilian cars as a police officer if so the script isn’t designed to do that, if not can u give me more Info
Yeah i was trying to lock a car bought from pdm on a cop character, but also seems it only works at certain times with certain jobs
Seems it works sometimes with the police job but sometimes doesn’t work at all doesn’t matter what job you have
When you sell a car at pdm you need to call the lock script and update the table, if you read through this topic there are several examples of how to do this, unfortunatly without constantly calling the database my script cannot detect when u have a new owner of a vehicle.
With so many people having issues with this I will add this as a setting in the config file.
so i have config.EnablePlayerManagaement set to true and i have imported the line into the correct spot. or some reason when i sell a car to player and transfer the ownership over to them the key transferowner line doesnt work and the locks on the car dont seem to work at all even the in car locks
RegisterNetEvent('esx_vehicleshop:setVehicleOwnedPlayerId')
AddEventHandler('esx_vehicleshop:setVehicleOwnedPlayerId', function(playerId, vehicleProps, model, label)
local xPlayer, xTarget = ESX.GetPlayerFromId(source), ESX.GetPlayerFromId(playerId)
if xPlayer.job.name == 'cardealer' and xTarget then
MySQL.Async.fetchAll('SELECT id FROM cardealer_vehicles WHERE vehicle = @vehicle LIMIT 1', {
['@vehicle'] = model
}, function(result)
if result[1] then
local id = result[1].id
MySQL.Async.execute('DELETE FROM cardealer_vehicles WHERE id = @id', {
['@id'] = id
}, function(rowsChanged)
if rowsChanged == 1 then
MySQL.Async.execute('INSERT INTO owned_vehicles (owner, plate, vehicle) VALUES (@owner, @plate, @vehicle)', {
['@owner'] = xTarget.identifier,
['@plate'] = vehicleProps.plate,
['@vehicle'] = json.encode(vehicleProps)
}, function(rowsChanged)
xPlayer.showNotification(_U('vehicle_set_owned', vehicleProps.plate, xTarget.getName()))
xTarget.showNotification(_U('vehicle_belongs', vehicleProps.plate))
end)
local dateNow = os.date('%Y-%m-%d %H:%M')
MySQL.Async.execute('INSERT INTO vehicle_sold (client, model, plate, soldby, date) VALUES (@client, @model, @plate, @soldby, @date)', {
['@client'] = xTarget.getName(),
['@model'] = label,
['@plate'] = vehicleProps.plate,
['@soldby'] = xPlayer.getName(),
['@date'] = dateNow
})
end
end)
end
end)
TriggerEvent('shorty_slocks:transferOwner', vehicleProps.plate, playerId)
end
end)
RegisterNetEvent('esx_vehicleshop:setVehicleOwnedPlayerId')
AddEventHandler('esx_vehicleshop:setVehicleOwnedPlayerId', function(playerId, vehicleProps, model, label)
local xPlayer, xTarget = ESX.GetPlayerFromId(source), ESX.GetPlayerFromId(playerId)
if xPlayer.job.name == 'cardealer' and xTarget then
MySQL.Async.fetchAll('SELECT id FROM cardealer_vehicles WHERE vehicle = @vehicle LIMIT 1', {
['@vehicle'] = model
}, function(result)
if result[1] then
local id = result[1].id
MySQL.Async.execute('DELETE FROM cardealer_vehicles WHERE id = @id', {
['@id'] = id
}, function(rowsChanged)
if rowsChanged == 1 then
MySQL.Async.execute('INSERT INTO owned_vehicles (owner, plate, vehicle) VALUES (@owner, @plate, @vehicle)', {
['@owner'] = xTarget.identifier,
['@plate'] = vehicleProps.plate,
['@vehicle'] = json.encode(vehicleProps)
}, function(rowsChanged)
xPlayer.showNotification(_U('vehicle_set_owned', vehicleProps.plate, xTarget.getName()))
xTarget.showNotification(_U('vehicle_belongs', vehicleProps.plate))
end)
local dateNow = os.date('%Y-%m-%d %H:%M')
MySQL.Async.execute('INSERT INTO vehicle_sold (client, model, plate, soldby, date) VALUES (@client, @model, @plate, @soldby, @date)', {
['@client'] = xTarget.getName(),
['@model'] = label,
['@plate'] = vehicleProps.plate,
['@soldby'] = xPlayer.getName(),
['@date'] = dateNow
})
end
end)
end
end)
end
TriggerEvent('shorty_slocks:transferOwner', vehicleProps.plate, playerId)
end)
Try here.
Not working with kashacters. Is it possible to run with kashacters?
I get this error after server run couple of hours:
@svehiclelocks/client/main.lua:145: attempt to index a nil value (upvalue ‘ESX’)
Have any idea how to solve this? Thank you.
I get another problem, if player in the same job (e.g: esx_jobs = miner) they can unlock another player vehicle if they vehicle not nearby.
Hy , i have problem. Lock didnt working , but console not writing any problem. Did you help me?
Actually it doesn’t lock any of npc vehicles even I set true on config. For lock npc cars I can lock it in the car but that not effect anything ( I can open and close the door even its locked).
I’ve been using this script for a while now and it’s pretty awesome, there’s only more issue I didn’t manage to work out though.
When you try to force open a vehicle using the mobile interactions from esx_policejob or esx_mechanicjob the doors don’t unlock. The animation completes and sometimes you manage to open the door, but you can’t get in.
Seems like the vehicles lock themselves immediately after forcing them open.
Does anyone have any ideas?
You are, literally the best human to be ever born. Thank you SO MUCH!!! <33