diff --git a/client.lua b/client.lua index c5b552a..30aeb8a 100644 --- a/client.lua +++ b/client.lua @@ -177,6 +177,11 @@ local function hideNUI() }) end +local function isVehicleOwned(plate) + local isOwned = lib.callback.await("realistic-vehicle:isVehOwned", false, plate) + return isOwned or false +end + -- Main thread to update kilometers and handle breakdowns Citizen.CreateThread(function() while true do @@ -188,6 +193,13 @@ Citizen.CreateThread(function() if vehicle ~= 0 then local plate = GetVehicleNumberPlateText(vehicle) local currentCoords = GetEntityCoords(playerPed) + + -- Verificar si el vehículo no tiene dueño + if not isVehicleOwned(plate) then + DebugPrint('Vehículo no es de nadie, no se actualizarán los kilómetros') + goto continueLoop + end + if isVehicleExcluded(plate) or isVehicleExcludedPrefix(plate) then DebugPrint('Vehículo excluido') goto continueLoop diff --git a/fxmanifest.lua b/fxmanifest.lua index 1b3c994..2fd374b 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -4,7 +4,7 @@ lua54 'yes' author 'Muhaddil' description 'Mileage-based vehicle breakdown system for ESX&QBCore' -version 'v0.7.5-beta' +version 'v0.7.6-beta' shared_script 'config.lua' client_script 'client.lua' diff --git a/server.lua b/server.lua index ca38664..40af35c 100644 --- a/server.lua +++ b/server.lua @@ -75,7 +75,28 @@ end) lib.callback.register("realistic-vehicle:get-mileage-JG", function(_, plate) local distance, unit = exports["jg-vehiclemileage"]:GetMileage(plate) return { mileage = distance, unit = unit } - end) +end) + +lib.callback.register("realistic-vehicle:isVehOwned", function(_, plate) + local isOwned = false + + if Config.FrameWork == "esx" then + local result = MySQL.Sync.fetchAll("SELECT * FROM " .. ESX.VehiclesTable .. " WHERE plate = @plate", { + ['@plate'] = plate + }) + + isOwned = #result > 0 + + elseif Config.FrameWork == "qb" then + local result = MySQL.Sync.fetchAll("SELECT * FROM " .. QBCore.VehiclesTable .. " WHERE plate = @plate", { + ['@plate'] = plate + }) + + isOwned = #result > 0 + end + + return isOwned +end) if Config.DebugMode then RegisterServerEvent('realistic-vehicle:testBreakdown') @@ -99,23 +120,24 @@ end) if Config.AutoRunSQL then if not pcall(function() - local fileName = "InstallSQL.sql" - local file = assert(io.open(GetResourcePath(GetCurrentResourceName()) .. "/" .. fileName, "rb")) - local sql = file:read("*all") - file:close() - - MySQL.query.await(sql) - end) then - print("^1[SQL ERROR] There was an error while automatically running the required SQL. Don't worry, you just need to run the SQL file. If you've already ran the SQL code previously, and this error is annoying you, set Config.AutoRunSQL = false^0") + local fileName = "InstallSQL.sql" + local file = assert(io.open(GetResourcePath(GetCurrentResourceName()) .. "/" .. fileName, "rb")) + local sql = file:read("*all") + file:close() + + MySQL.query.await(sql) + end) then + print( + "^1[SQL ERROR] There was an error while automatically running the required SQL. Don't worry, you just need to run the SQL file. If you've already ran the SQL code previously, and this error is annoying you, set Config.AutoRunSQL = false^0") end - end +end -- Función para calcular la diferencia en días local function daysAgo(dateStr) local year, month, day = dateStr:match("(%d+)-(%d+)-(%d+)") - local releaseTime = os.time({year = year, month = month, day = day}) + local releaseTime = os.time({ year = year, month = month, day = day }) local currentTime = os.time() - local difference = os.difftime(currentTime, releaseTime) / (60 * 60 * 24) -- Diferencia en días + local difference = os.difftime(currentTime, releaseTime) / (60 * 60 * 24) -- Diferencia en días return math.floor(difference) end @@ -203,25 +225,26 @@ if Config.AutoVersionChecker then if latestVersion ~= currentVersion then print('╭────────────────────────────────────────────────────╮') - printCentered('[FiveM-MilageVehicleFailure] - New Version Available', boxWidth, '34') -- Blue - printWrapped('Current version: ' .. currentVersion, boxWidth, '32') -- Green - printWrapped('Latest version: ' .. latestVersion, boxWidth, '33') -- Yellow - printWrapped('Released: ' .. formattedDate, boxWidth, '33') -- Yellow - printWrapped('Notes: ' .. shortenedNotes, boxWidth, '33') -- Yellow - printWrapped('Download: ' .. shortenedUrl, boxWidth, '32') -- Green + printCentered('[FiveM-MilageVehicleFailure] - New Version Available', boxWidth, '34') -- Blue + printWrapped('Current version: ' .. currentVersion, boxWidth, '32') -- Green + printWrapped('Latest version: ' .. latestVersion, boxWidth, '33') -- Yellow + printWrapped('Released: ' .. formattedDate, boxWidth, '33') -- Yellow + printWrapped('Notes: ' .. shortenedNotes, boxWidth, '33') -- Yellow + printWrapped('Download: ' .. shortenedUrl, boxWidth, '32') -- Green print('╰────────────────────────────────────────────────────╯') else print('╭────────────────────────────────────────────────────╮') - printWrapped('[FiveM-MilageVehicleFailure] - Up-to-date', boxWidth, '32') -- Green - printWrapped('Current version: ' .. currentVersion, boxWidth, '32') -- Green + printWrapped('[FiveM-MilageVehicleFailure] - Up-to-date', boxWidth, '32') -- Green + printWrapped('Current version: ' .. currentVersion, boxWidth, '32') -- Green print('╰────────────────────────────────────────────────────╯') end else - printWithColor('[FiveM-MilageVehicleFailure] - Error: The JSON structure is not as expected.', '31') -- Red - printWithColor('GitHub API Response: ' .. response, '31') -- Red + printWithColor('[FiveM-MilageVehicleFailure] - Error: The JSON structure is not as expected.', '31') -- Red + printWithColor('GitHub API Response: ' .. response, '31') -- Red end else - printWithColor('[FiveM-MilageVehicleFailure] - Failed to check for latest version. Status code: ' .. statusCode, '31') -- Red + printWithColor( + '[FiveM-MilageVehicleFailure] - Failed to check for latest version. Status code: ' .. statusCode, '31') -- Red end end, 'GET') end