[QBCore/ESX] CAR RENTAL + RENTED CARS COULD BE PARKED

As a player, you will enjoy a seamless and user-friendly UI.

  • You can rent the vehicle for 1, 3, 7, and 14 days.
  • You can add as much cars as you want.
  • You can store your rented vehicle in your garage.
  • Once the rental period is over, the vehicle will be removed from the database and deleted in-game upon the first car usage.
  • The car rental receipt includes all the necessary information.

Code is accessible Partially
Subscription-based No
Lines (approximately) 10000+
Requirements qb-core/esx
Support Yes
  • Config.lua
Config = {}

Config.Framework    = "qbcore" -- esx
Config.Fuel         = 'LegacyFuel'
Config.Debug        = false
Config.Currency     = "$" -- €, £
Config.UseSteamName = false -- Only for QBCere
Config.ReturnBonus  = 5 --$
Config.BlipSprite = 672
Config.BlipColor = 1
Config.BlipText = "Car Rental"

-- "Compacts" "Sedans" "SUVs" "Coupes" "Muscle" "Sports Classics" "Sports" "Super" "Vans" "Motorcycles" "Off-Road" "Cycles"
Config.VehicleList = {
    [1]     = {id = 1, name = "Glendale",   image = "https://docs.fivem.net/vehicles/glendale.webp", price = 800, category = "Sedans"},
    [2]     = {id = 2, name = "Seminole",   image = "https://docs.fivem.net/vehicles/seminole.webp", price = 600, category = "SUVs"},
    [3]     = {id = 3, name = "Ingot",      image = "https://docs.fivem.net/vehicles/ingot.webp", price = 600, category = "Sedans"},
    [4]     = {id = 4, name = "Speedo",     image = "https://docs.fivem.net/vehicles/speedo.webp", price = 1400, category = "Vans"},
    [5]     = {id = 5, name = "Blista",     image = "https://docs.fivem.net/vehicles/blista.webp", price = 800, category = "Compacts"},
    [6]     = {id = 6, name = "Club",       image = "https://docs.fivem.net/vehicles/club.webp", price = 850, category = "Compacts"},
}

Config.Locations = {
    [1] = {
        NPCModel = "a_m_y_business_03",
        NPCCoords = vector4(-747.63, -1056.85, 11.01, 297.25),
        CarSpawn = vector4(-744.55, -1055.49, 12.09, 206.29)
    }
}




2 Likes

Question - for the delating of the vehicle from the database, is it looking specifically for the rented plate?

Concern here would be, a player selling the car to another player (illegally obviously since its a rental) - and if its not looking for the vehicle plate - basically a player could rent a car, and sell it and now that injects a cheap or free car into the enconomy.

If its searching by the plate then that issue should be fine, because after the time period still, it would delete from the DB. The player who bought the car from the player who rented it, would lose their car - but that can atleast be RP’ed as repo’ed because it was technically a rental.

1 Like

That is a good point !!!
All the rental vehicle plates Starts with RENT****, so they can disable it from the selling command inbetween players, or add the rentingStart/End time to the sold vehicle.
But i really like what you said !

So just to clarify, when the vehicles time is over - the sql fetch to delete from the owned vehicles table is based on plate correct? not plate & owner?

If its plate & owners citizen id, passing through the sql check for deleting, then thats gunna be a problem for abuse. BUT if its only passing for the plate - then it should be fine and can be handled in server via Repo RP.

Just wanna make sure we arnt accidently introducing a way to keep rental cars via exploit. (common problem it seems with a lot of rental car scripts… bought 3 and all of them were checking for plate & owner match… which means if a player sold to another player, it wouldnt delete the vehicle after the time expires… very frustrating lol)

Yes it is based on the plate. So no worries !

Just make sure that the vehicle sell script (between players) doesn’t delete the vehicle data from DB and creates another line with same data, because in that case the rental periode will be lost.

The vehicle sell Script shall update the data (citizenid etc…) which is logic and used in default qb and esx vehicleshop scripts.

1 Like

oh good call, ill go check that! Hopefully it doesnt delete when selling but rather just changes the citizen ID. I know milage transfers with selling so i think its just a db owner swap not a line delete.

If its the ladder, then ill for sure be picking this script up tonight… rental cars for new players at LSIA (our intro point) has been a serious missing gap in server haha.

1 Like

here is the code part of checking periode:

RegisterNetEvent("zat-carrental:server:CheckRentalPeriode", function(plate)
    local src = source
    local currentdate = os.time()
    if Config.Framework == "qbcore" then
        MySQL.query('SELECT * FROM player_vehicles WHERE plate = ?', {plate}, function(result)
            if result[1] ~= nil then
                if (os.difftime(currentdate, result[1].loandate)) >= (result[1].loanperiode * 86400) then
                    MySQL.query('DELETE FROM player_vehicles WHERE plate = ?',{plate})
                    TriggerClientEvent("zat-carrental:client:RemoveVehicle", src, plate)
                    TriggerClientEvent("QBCore:Notify", src, "Renting Periode is Over...", 'primary', 5000)
                end
            end
        end)
    elseif Config.Framework == "esx" then
        MySQL.query('SELECT * FROM owned_vehicles WHERE plate = ?', {plate}, function(result)
            if result[1] ~= nil then
                if (os.difftime(currentdate, result[1].loandate)) >= (result[1].loanperiode * 86400) then
                    MySQL.query('DELETE FROM owned_vehicles WHERE plate = ?',{plate})
                    TriggerClientEvent("zat-carrental:client:RemoveVehicle", src, plate)
                    TriggerClientEvent("esx:showNotification", src, "Renting Periode is Over...")
                end
            end
        end)
    end
end)
1 Like

can create multiple location but with different vehicle list?

1 Like

Maybe i will do that in future updates.

bravo zat :heart: ama sbe9tek :rofl: :heart:

1 Like

Thanks :sparkling_heart: on what sbe9tni ?

Rental 4.0

can create multiple location but with different vehicle list?
Yes

Config.Locations = {
[1] = {
NPCModel = “a_m_y_business_03”,
NPCCoords = vector4(-747.63, -1056.85, 11.01, 297.25),
CarSpawn = vector4(-744.55, -1055.49, 12.09, 206.29)
},
[2] = {
NPCModel = “a_m_y_business_03”,
NPCCoords = vector4(-1229.83, -176.95, 38.33, 234.43),
CarSpawn = vector4(-1225.95, -179.33, 38.75, 125.98)
},
[3] = {
NPCModel = “a_m_y_business_03”,
NPCCoords = vector4(231.05, -753.01, 33.64, 329.85),
CarSpawn = vector4(234.49, -751.2, 34.2, 69.92)
}

}
Can you edit the code so that the name can be changed?
at the NPC when renting and returning the vehicle

Done !
Just Update to latest version.

Config.CarrentText = "Rent a car"
Config.CarrentIcon = 'fa-solid fa-car'
Config.CarreturnText = "Return a car"
Config.carreturnIcon = 'fa-solid fa-car'

Im having an issue where the cars will not garage