From 6e4d9bc1d7bb83741b8c55ef39a3b3f0edef9ef2 Mon Sep 17 00:00:00 2001 From: oosayeroo <98313914+oosayeroo@users.noreply.github.com> Date: Thu, 4 Sep 2025 17:22:36 +0100 Subject: [PATCH] Update vehicles.lua --- shared/vehicles.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/shared/vehicles.lua b/shared/vehicles.lua index 98c5606..b6a2337 100644 --- a/shared/vehicles.lua +++ b/shared/vehicles.lua @@ -299,4 +299,34 @@ function getClosestVehicle(coords, src) end return closestVehicle, closestDistance +end + +--- Checks whether a vehicle is owned or not using the plate as reference +--- +--- @param plate string The plate of the vehicle to check +--- @return boolean whether vehicle is owned +--- +--- @usage +--- ```lua +--- local plate = "ABCD1234" +--- local isVehicleOwned = isVehicleOwned(plate) +--- ``` +local vehiclesOwned = {} + +function isVehicleOwned(plate) + vehDatabase = "player_vehicles" + if isStarted(ESXExport) then vehDatabase = "owned_vehicles" + elseif isStarted(OXCoreExport) then vehDatabase = "vehicles" end + + if vehiclesOwned[plate] == true then + return true + else + local result = MySQL.query.await("SELECT 1 from "..vehDatabase.." WHERE plate = ?", { plate }) + if json.encode(result) ~= "[]" then + vehiclesOwned[plate] = true + return true + else + return false + end + end end \ No newline at end of file