Skip to content

Commit

Permalink
Update 0.7.6
Browse files Browse the repository at this point in the history
-Added that if a vehicle isn't owned, it doesn't save its mileage.
  • Loading branch information
Muhaddil committed Oct 20, 2024
1 parent 65c1b74 commit 6d9ee76
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 24 deletions.
12 changes: 12 additions & 0 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
69 changes: 46 additions & 23 deletions server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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

Expand Down Expand Up @@ -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

0 comments on commit 6d9ee76

Please sign in to comment.