Hello, how can I update the following code for the latest esx version so that I don’t need mysql-async?
Server:
ESX = exports[“es_extended”]:getSharedObject()
ESX.RegisterServerCallback(‘carlock:isVehicleOwner’, function(source, cb, plate)
local identifier = GetPlayerIdentifier(source, 0)
MySQL.Async.fetchAll('SELECT owner FROM owned_vehicles WHERE owner = @owner AND plate = @plate', {
['@owner'] = identifier,
['@plate'] = plate
}, function(result)
if result[1] then
cb(result[1].owner == identifier)
else
cb(false)
end
end)
end)
Client:
ESX = exports[“es_extended”]:getSharedObject()
Citizen.CreateThread(function()
local dict = “anim@mp_player_intmenu@key_fob@”
RequestAnimDict(dict)
while not HasAnimDictLoaded(dict) do
Citizen.Wait(0)
end
while true do
Citizen.Wait(0)
if (IsControlJustPressed(1, 303)) then
local coords = GetEntityCoords(GetPlayerPed(-1))
local hasAlreadyLocked = false
cars = ESX.Game.GetVehiclesInArea(coords, 30)
local carstrie = {}
local cars_dist = {}
notowned = 0
if cars == 0 then
ESX.ShowNotification(“No vehicles to lock nearby.”)
else
for j=1, cars, 1 do
local coordscar = GetEntityCoords(cars[j])
local distance = Vdist(coordscar.x, coordscar.y, coordscar.z, coords.x, coords.y, coords.z)
table.insert(cars_dist, {cars[j], distance})
end
for k=1, #cars_dist, 1 do
local z = -1
local distance, car = 999
for l=1, #cars_dist, 1 do
if cars_dist[l][2] < distance then
distance = cars_dist[l][2]
car = cars_dist[l][1]
z = l
end
end
if z ~= -1 then
table.remove(cars_dist, z)
table.insert(carstrie, car)
end
end
for i=1, #carstrie, 1 do
local plate = ESX.Math.Trim(GetVehicleNumberPlateText(carstrie[i]))
ESX.TriggerServerCallback(‘carlock:isVehicleOwner’, function(owner)
if owner and hasAlreadyLocked ~= true then
local vehicleLabel = GetDisplayNameFromVehicleModel(GetEntityModel(carstrie[i]))
vehicleLabel = GetLabelText(vehicleLabel)
local lock = GetVehicleDoorLockStatus(carstrie[i])
if lock == 1 or lock == 0 then
SetVehicleDoorShut(carstrie[i], 0, false)
SetVehicleDoorShut(carstrie[i], 1, false)
SetVehicleDoorShut(carstrie[i], 2, false)
SetVehicleDoorShut(carstrie[i], 3, false)
SetVehicleDoorsLocked(carstrie[i], 2)
PlayVehicleDoorCloseSound(carstrie[i], 1)
ESX.ShowNotification(‘You have ~r~locked~s~ your ~y~’…vehicleLabel…‘~s~.’)
if not IsPedInAnyVehicle(PlayerPedId(), true) then
TaskPlayAnim(PlayerPedId(), dict, “fob_click_fp”, 8.0, 8.0, -1, 48, 1, false, false, false)
end
SetVehicleLights(carstrie[i], 2)
Citizen.Wait(150)
SetVehicleLights(carstrie[i], 0)
Citizen.Wait(150)
SetVehicleLights(carstrie[i], 2)
Citizen.Wait(150)
SetVehicleLights(carstrie[i], 0)
hasAlreadyLocked = true
elseif lock == 2 then
SetVehicleDoorsLocked(carstrie[i], 1)
PlayVehicleDoorOpenSound(carstrie[i], 0)
ESX.ShowNotification(‘You have ~g~unlocked~s~ your ~y~’…vehicleLabel…‘~s~.’)
if not IsPedInAnyVehicle(PlayerPedId(), true) then
TaskPlayAnim(PlayerPedId(), dict, “fob_click_fp”, 8.0, 8.0, -1, 48, 1, false, false, false)
end
SetVehicleLights(carstrie[i], 2)
Citizen.Wait(150)
SetVehicleLights(carstrie[i], 0)
Citizen.Wait(150)
SetVehicleLights(carstrie[i], 2)
Citizen.Wait(150)
SetVehicleLights(carstrie[i], 0)
hasAlreadyLocked = true
end
else
notowned = notowned + 1
end
if notowned == #carstrie then
ESX.ShowNotification(“No vehicles to lock nearby.”)
end
end, plate)
end
end
end
end
end)