🛠ī¸Installation

Run the SQL:

CREATE TABLE `mCarRental_vehicles` (
  `rental_id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  `plate` varchar(255) DEFAULT NULL,
  `label` varchar(255) DEFAULT NULL,
  `category` varchar(255) NOT NULL,
  `passengers` int(11) NOT NULL,
  `top_speed` int(11) NOT NULL,
  `price` int(11) NOT NULL,
  `owner` varchar(255) DEFAULT NULL,
  `owner_name` varchar(255) DEFAULT NULL,
  `rental_owner` varchar(255) DEFAULT NULL,
  `date_limit` varchar(255) DEFAULT NULL,
  `available` int(1) DEFAULT NULL
);

CREATE TABLE `mCarRental_history`(
  `identifier` varchar(255) NOT NULL,
  `identifier_name` varchar(255) NOT NULL,
  `vehicle_name` varchar(255) NOT NULL,
  `type` varchar(255) NOT NULL,
  `price` varchar(255) NOT NULL,
  `days` varchar(255) NOT NULL,
  `date` varchar(255) NOT NULL
);

ALTER TABLE owned_vehicles
ADD rental_owner VARCHAR(50) NOT NULL,
ADD rental_mods LONGTEXT NOT NULL,
ADD isRented int(1) NOT NULL;

ALTER TABLE users
ADD img_avatar LONGTEXT NOT NULL;

ALTER TABLE owned_vehicles
ADD model_name VARCHAR(50) NOT NULL;

Snippets for Vehicleshops:

  1. okokVehicleShop

Search Config.EventPrefix..':setVehicleOwned and replace with:

RegisterServerEvent(Config.EventPrefix..':setVehicleOwned')
AddEventHandler(Config.EventPrefix..':setVehicleOwned', function (vehicleProps, model, id)
  local _source = source
  local xPlayer = ESX.GetPlayerFromId(_source)

  if Config.Boats[model] == true then
      MySQL.Async.execute('INSERT INTO owned_vehicles (owner, plate, vehicle, type) VALUES (@owner, @plate, @vehicle, @type)', {
          ['@owner'] = xPlayer.identifier,
          ['@plate'] = vehicleProps.plate,
          ['@vehicle'] = json.encode(vehicleProps),
          ['@type'] = 'boat',
          ['@model_name'] = model
      }, function (rowsChanged)
      end)
  elseif Config.Aircrafts[model] == true then
      MySQL.Async.execute('INSERT INTO owned_vehicles (owner, plate, vehicle, type) VALUES (@owner, @plate, @vehicle, @type)', {
          ['@owner'] = xPlayer.identifier,
          ['@plate'] = vehicleProps.plate,
          ['@vehicle'] = json.encode(vehicleProps),
          ['@type'] = 'air',
          ['@model_name'] = model
      }, function (rowsChanged)
      end)
  else
      MySQLexecute('INSERT INTO owned_vehicles (owner, plate, vehicle, model_name) VALUES (@owner, @plate, @vehicle, @model_name)',
      {
          ['@owner'] = xPlayer.identifier,
          ['@plate'] = vehicleProps.plate:match( "^%s*(.-)%s*$" ),
          ['@vehicle'] = json.encode(vehicleProps),
          ['@model_name'] = model
      }, function (rowsChanged)
      end)    
  end
  1. esx_vehicleshop

Search: esx_vehicleshop:setVehicleOwnedPlayerId and replace with:

RegisterNetEvent('esx_vehicleshop:setVehicleOwnedPlayerId')
AddEventHandler('esx_vehicleshop:setVehicleOwnedPlayerId', function(playerId, vehicleProps, model, label)
    local xPlayer, xTarget = ESX.GetPlayerFromId(source), ESX.GetPlayerFromId(playerId)
    local modelName = getVehicleFromModel(model).name
    if xPlayer.job.name ~= 'cardealer' or not xTarget then
        return
    end

    MySQL.scalar('SELECT id FROM cardealer_vehicles WHERE vehicle = ?', {model},
    function(id)
        if not id then
            return
        end

        MySQL.update('DELETE FROM cardealer_vehicles WHERE id = ?', {id},
        function(rowsChanged)
            if rowsChanged == 1 then
                MySQL.insert('INSERT INTO owned_vehicles (owner, model_name, plate, vehicle) VALUES (?, ?, ?, ?)', {xTarget.identifier, modelName, vehicleProps.plate, json.encode(vehicleProps)},
                function(id)
                    xPlayer.showNotification(TranslateCap('vehicle_set_owned', vehicleProps.plate, xTarget.getName()))
                    xTarget.showNotification(TranslateCap('vehicle_belongs', vehicleProps.plate))
                end)

                MySQL.insert('INSERT INTO vehicle_sold (client, model, plate, soldby, date) VALUES (?, ?, ?, ?, ?)', {xTarget.getName(), label, vehicleProps.plate, xPlayer.getName(), os.date('%Y-%m-%d %H:%M')})
            end
        end)
    end)
end)

Search: esx_vehicleshop:buyVehicle and replace with:

ESX.RegisterServerCallback('esx_vehicleshop:buyVehicle', function(source, cb, model, plate)
    local xPlayer = ESX.GetPlayerFromId(source)
    local modelPrice = getVehicleFromModel(model).price
    local modelName = getVehicleFromModel(model).model
    if modelPrice and xPlayer.getMoney() >= modelPrice then
        xPlayer.removeMoney(modelPrice, "Vehicle Purchase")
        MySQL.insert('INSERT INTO owned_vehicles (owner, model_name, plate, vehicle) VALUES (?, ?, ?, ?)', {xPlayer.identifier, modelName, plate, json.encode({model = joaat(model), plate = plate})
        }, function(rowsChanged)
            xPlayer.showNotification(TranslateCap('vehicle_belongs', plate))
            ESX.OneSync.SpawnVehicle(joaat(model), Config.Zones.ShopOutside.Pos, Config.Zones.ShopOutside.Heading,{plate = plate}, function(vehicle)
                Wait(100)
                local vehicle = NetworkGetEntityFromNetworkId(vehicle)
                Wait(300)
                TaskWarpPedIntoVehicle(GetPlayerPed(source), vehicle, -1)
            end)
            cb(true)
        end)
    else
        cb(false)
    end
end)

Last updated