# <img src='/images/wheelclamp.webp'/> Wheel clamp
Documentation relating to the jo_wheellock.

:::: tabs
::: tab BUY
[Buy the script](https://jumpon-studios.com/fivem/wheel-clamp)
:::

::: tab PREVIEW
<iframe width="560" height="315" src="https://www.youtube.com/embed/rccp5TI9q6Y?si=E4muYL9-q__TX3os" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
:::
::::

## 1. Installation
jo_wheellock is a standalone script. So you don't need a specific framework to use it. It's also mean it works with all framework (Esx, QBCore, VRP, DRP, …).

- Drag and drop the resource in your resources folder
  - jo_wheellock
- Add this ensure in your server.cfg
  - `ensure jo_wheellock`
- Congratulation, the Wheel lock script is ready to be use !

## 2. Usage
You have twos way to put/remove the wheel lock on the car in front of you :
- Use the command : /wheellock
- Use the client event : 'jo_wheellock:action'

## 3. Config.lua

The configuration file is `config.lua` in the resource root. **Do not edit this file directly** as your changes may be lost during updates. Instead, use `overwriteConfig.lua` to store your customizations.

- **`config.lua`** - Default configuration maintained by developers. **Do not modify this file.**
- **`overwriteConfig.lua`** - This is where you place only the values you want to override.

### How to customize the configuration

1. Open `jo_wheellock/overwriteConfig.lua`
2. Find the value you want to change in `config.lua` (e.g., `Config.language`)
3. Copy only that line into `overwriteConfig.lua`
4. Edit the copied value to your liking

The script loads `config.lua` first, then `overwriteConfig.lua` overwrites only the values you redefine. This ensures your customizations are preserved when updating the script.

`jo_wheellock/shared/config.lua`

```lua
-------------------------------
-- DOCUMENTATION : https://docs.kaddarem.com/
--------------------------------

-------------------------------------------
-- DON'T EDIT THIS FILE
-- TO OVERWRITE CONFIG VALUE, USE overwriteConfig.lua file instead
-------------------------------------------
Config = {}

Config.command = "wheellock" --put false to disable it
Config.maxTimeToMove = 7000  --max duration to go near the vehicle
Config.debug = false         --display debug message
Config.stateBagKey = "jo_wheellock_bone"

Config.offsets = {
  default = {
    all = vector4(-0.125, 0.0, 0.0, -180.0)
  },
}

---------------------------------
-- CLIENT SIDE
---------------------------------

-- Function to display message
-- @param message The string message
Config.message = function(message)
  print(message)
end

-- Fire when player start taking the wheel lock
-- @param vehicle The vehicle ID where the wheellock was removed
-- @param wheellockObj The wheel lock object
-- @param bone The bone name where the wheellockObj is placed
Config.startTaking = function(vehicle, wheellockObj, bone)
end

-- Fire when wheellock is removed
-- @param vehicle The vehicle ID where the wheellock was removed
Config.takeWheellock = function(vehicle)
  Config.message(Lang.takeWheellock)

  --Make the vehicle driveable
  NetworkRequestControlOfEntity(vehicle)
  while not NetworkHasControlOfEntity(vehicle) do
    Wait(0)
  end
  SetVehicleUndriveable(vehicle, false)
  FreezeEntityPosition(vehicle, false)
end

-- Fire when player start putting the wheel lock
-- @param vehicle The vehicle ID where the wheellock will be put
Config.startPutting = function(vehicle)
end

-- Fire when wheellock is put
-- @param vehicle The vehicle ID where the wheellock was put
-- @param wheellockObj The wheel lock object
-- @param bone The bone name where the wheellockObj was put
Config.putWheellock = function(vehicle, wheellockObj, bone)
  Config.message(Lang.putWheellock)

  --Make the vehicle undriveable
  NetworkRequestControlOfEntity(vehicle)
  while not NetworkHasControlOfEntity(vehicle) do
    Wait(0)
  end
  SetVehicleUndriveable(vehicle, true)
  FreezeEntityPosition(vehicle, true)
end

----------------------------------
-- SERVER SIDE
----------------------------------

-- Use to restrick the script to specific players
-- return true if player can use wheellock, else return false
Config.canUseWheellock = function(source)
  return true
end
```

`jo_wheellock/shared/lang.lua`

```lua
-------------------------------------------
-- DON'T EDIT THIS FILE
-- TO TRANSLATE THE SCRIPT, USE overwriteLang.lua file instead
-------------------------------------------
Lang = {}

Lang.nocar = 'No car front of you'
Lang.wrongModel = "Wrong prop model"
Lang.takeWheellock = "You took the wheel lock"
Lang.putWheellock = "You put the wheel lock"
Lang.alreadyHave = "This car already have a wheel lock"
Lang.notHave = "This car have no wheel lock"
```

## 4. For developer
Spawn the wheel lock on car without player animation :
```lua
-- @param vehNet : Server ID of the vehicle
-- @param boneName : Name of the bone where the wheel lock is
-- @side : Client side
TriggerEvent("jo_wheellock:addLockedCars", vehNet, 0, boneName)

```
Use event to put/remove the wheel lock :
```lua
-- @side : Client side
TriggerEvent('jo_wheellock:action')       -- Put or remove the wheel lock
TriggerEvent('jo_wheellock:actionPut')    -- Only Put the wheel lock
TriggerEvent('jo_wheellock:actionRemove') -- Only Remove the wheel lock

```

## 5. Snippets
### `[ESX]` Restrict the wheellock with job
Use this canUseWheellock function in the configuration
```lua
ESX = exports['es_extended']:getSharedObject()
Config.canUseWheellock = function(source)
    local xPlayer = ESX.GetPlayerFromId(source)
    return (xPlayer.getJob().name == "police")
end

```
### `[QBcore]` Restrict the wheellock with job
Use this canUseWheellock function in the configuration
```lua
QBCore = exports['qb-core']:GetCoreObject()
Config.canUseWheellock = function(source)
    local Player = QBCore.Functions.GetPlayer(source)
    return (Player.PlayerData.job.type == "police" or Player.PlayerData.job.type == "mechanic")
end

```
