# Installation

## Run the SQL:

```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 <mark style="color:blue;">**Config.EventPrefix..':setVehicleOwned**</mark> and replace with:

```lua
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
```

2. esx\_vehicleshop

Search: <mark style="color:blue;">**esx\_vehicleshop:setVehicleOwnedPlayerId**</mark> and replace with:

```lua
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: <mark style="color:blue;">**esx\_vehicleshop:buyVehicle**</mark> and replace with:

```lua
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)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mscripts.gitbook.io/docs/esx/general/esx-car-rental/installation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
