# Client

## **IsVehicleOnCarJack**

Returns whether a given vehicle entity is on a car jack or not.

```lua
exports["t1ger_mechanic"]:IsVehicleOnCarJack(vehicle)
```

#### **Parameters**

* **`vehicle`***(number)* – The vehicle entity handle.

#### **Returns**

* `boolean` – `true` if vehicle is on car jack, otherwise `false`.

***

## IsWorkflowActive

Returns whether the mechanic workflow UI is currently active and open.

```lua
exports["t1ger_mechanic"]:IsWorkflowActive()
```

**Returns**

* `boolean` – `true` if the workflow UI is open, otherwise `false`.

***

## CreateCarLift

Spawns a car lift at the player's current position and rotation, then triggers the server to create and sync it for all clients.

```lua
exports["t1ger_mechanic"]:CreateCarLift()
```

***

## IsCarryingBodyPart

Checks whether the player is currently carrying a body part prop (e.g., door, hood, etc.).

```lua
exports["t1ger_mechanic"]:IsCarryingBodyPart()
```

**Returns**

* `boolean` – `true` if the player is carrying a body part, otherwise `false`.

***

## IsCarryingComponent

Checks whether the player is currently carrying a component prop (core or service part).

```lua
exports["t1ger_mechanic"]:IsCarryingComponent()
```

**Returns**

* `boolean` – `true` if the player is carrying a component, otherwise `false`.

***

## CancelBodyPartInstallation

Cancels an ongoing body part installation.\
Clears the player's animation and deletes any carried body part prop.

```lua
exports["t1ger_mechanic"]:CancelBodyPartInstallation()
```

***

## CancelComponentRepair

Cancels an in-progress component repair by removing any carried props and clearing the player's tasks.

```lua
exports["t1ger_mechanic"]:CancelComponentRepair()
```

***

## CancelInspection

Cancels an ongoing vehicle body inspection by setting the internal inspection flag.

```lua
exports["t1ger_mechanic"]:CancelInspection()
```

***

## QuickRepair

Fully repairs the vehicle the player is currently inside, including body, engine, and optionally fuel and part states based on config settings.

```lua
exports["t1ger_mechanic"]:QuickRepair()
```

***

## CreateShop

Opens the admin-only shop creation interface to create a new mechanic shop at the player’s current location.

```lua
exports["t1ger_mechanic"]:CreateShop(returnMenu)
```

**Parameters**

* `returnMenu` (`string`, optional) – The `ox_lib` context menu ID to return to if the dialog is canceled.

{% hint style="warning" %}
Only works for players with admin permissions (`_API.Player.isAdmin` must return `true`).
{% endhint %}

***

## ViewShops

Displays a list of all mechanic shops in a context menu using `ox_lib`.

```lua
exports["t1ger_mechanic"]:ViewShops(returnMenu)
```

**Parameters**

* `returnMenu` (`string`) – Menu ID to return to if no shops exist or the list is exited.

***

## BillingMain

Opens the mechanic shop billing interface for viewing and/or creating invoices.\
Only available to mechanic players if billing is enabled in the config.

```lua
exports["t1ger_mechanic"]:BillingMain(returnMenu)
```

**Parameters**

* `returnMenu` (`string`, optional) – Menu ID to return to if the billing interface is exited.

***

## IsPlayerEmployee

Checks whether the local player is employed at a specific mechanic shop or any shop.

```lua
exports["t1ger_mechanic"]:IsPlayerEmployee(shopId)
```

**Parameters**

* `shopId` (`number|nil`) – *(Optional)* Shop ID to check. If omitted, all shops are checked.

**Returns**

* `boolean` – `true` if the player is an employee, otherwise `false`.
* `number|nil` – The ID of the shop the player is employed at, or `nil` if not found.

***

## IsPlayerMechanic

Checks whether the local player has a mechanic job assigned to any registered shop.

```lua
exports["t1ger_mechanic"]:IsPlayerMechanic(shopId)
```

**Parameters**

* `shopId` (`number|nil`) – *(Optional)* Shop ID to check. If omitted, all shops are checked.

**Returns**

* `boolean` – `true` if the player has a mechanic job, otherwise `false`.
* `number|nil` – The ID of the matching shop, or `nil` if not found.

***

## IsPlayerMechanicBoss

Checks whether the local player holds a boss-grade mechanic job in a specific shop or any shop.

```lua
exports["t1ger_mechanic"]:IsPlayerMechanicBoss(shopId)
```

**Parameters**

* `shopId` (`number|nil`) – *(Optional)* Shop ID to check. If omitted, all shops are checked.

**Returns**

* `boolean` – `true` if the player is a boss-grade mechanic, otherwise `false`.
* `number|nil` – The ID of the shop where the player is a boss, or `nil` if not found.

***

## IsPlayerShopOwner

Checks whether the local player is the owner of a specific mechanic shop or any shop.

```lua
exports["t1ger_mechanic"]:IsPlayerShopOwner(shopId)
```

**Parameters**

* `shopId` (`number|nil`) – *(Optional)* Shop ID to check. If omitted, all shops are checked.

**Returns**

* `boolean` – `true` if the player is the owner of a shop, otherwise `false`.
* `number|nil` – The ID of the shop the player owns, or `nil` if not found.

***

## **IsPlayerDiagnosing**

Returns whether the player is currently diagnosing or inspecting a vehicle.

```lua
exports["t1ger_mechanic"]:IsPlayerDiagnosing()
```

#### **Returns**

* `boolean`

***

## GetVehicleData

Retrieves stored mechanic data for a given vehicle from its statebag.

```lua
exports["t1ger_mechanic"]:GetVehicleData(vehicle)
```

**Parameters**

* `vehicle` (`integer`) – The vehicle entity handle.

**Returns**

* `table|nil` – Returns a table containing vehicle data if found, otherwise `nil`.
* Returned structure:

  ```
  {
      mileage = number, -- total mileage in km
      service_parts = {
          [partName] = number, -- mileage since last replacement
          ...
      },
      core_parts = {
          [partName] = number, -- health (0–100)
          ...
      }
  }
  ```

***

## SetVehicleData

Sets or updates mechanic data for a vehicle using the statebag. Validates the structure before applying.

```lua
exports["t1ger_mechanic"]:SetVehicleData(vehicle, data, replicate)
```

**Parameters**

* `vehicle` (`integer`) – The vehicle entity handle.
* `data` (`table`) – Vehicle data to apply (must include `mileage`, `service_parts`, and `core_parts`).
* `replicate` (`boolean`) – *(Optional)* Whether to replicate the state to clients. Defaults to `true`.

**Returns**

* `boolean` – `true` if the data was set successfully, otherwise throws an error.
* Expected `data` structure:

  ```lua
  {
      mileage = number,
      service_parts = {
          [partName] = number
      },
      core_parts = {
          [partName] = number
      }
  }
  ```

***

## SaveVehicleData

Saves vehicle data client-side and sends it to the server for persistence.

```lua
exports["t1ger_mechanic"]:SaveVehicleData(vehicle)
```

#### Parameters

* `vehicle` *(number)* – The vehicle entity handle (must be valid and exist).

{% hint style="info" %}
Intended for use in garage scripts that delete the vehicle before the server can catch it (e.g., `entityRemoved` not triggered in time).
{% endhint %}

***

## **GetVehicleMileage**

Returns the current mileage of a given vehicle entity.

```lua
exports["t1ger_mechanic"]:GetVehicleMileage(vehicle)
```

#### **Parameters**

* **`vehicle`***(number)* – The vehicle entity handle.

#### **Returns**

* `number`– The vehicle mileage

***

## SetVehicleMileage

Sets the mileage value for a vehicle safely and updates it in the statebag.

```lua
luaKopiérRedigerexports["t1ger_mechanic"]:SetVehicleMileage(vehicle, mileage)
```

**Parameters**

* `vehicle` (`integer`) – The vehicle entity handle.
* `mileage` (`number`) – New mileage value to set. Must be a non-negative number.

**Returns**

* `boolean` – `true` if mileage was set successfully, otherwise `false`.

***

## GetCorePartHealth

Returns the current health value of a specific core part on a given vehicle.

```lua
exports["t1ger_mechanic"]:GetCorePartHealth(vehicle, part)
```

**Parameters**

* `vehicle` (`integer`) – The vehicle entity handle.
* `part` (`string`) – The name of the core part (e.g., `"radiator"`, `"brakes"`).

**Returns**

* `number` – Health value of the part (`0–100`), or `-1` if not found.

***

## SetCorePartHealth

Sets the health value for a specific core part on a given vehicle. The value is clamped between `0` and `100`.

```lua
exports["t1ger_mechanic"]:SetCorePartHealth(vehicle, part, health)
```

**Parameters**

* `vehicle` (`integer`) – The vehicle entity handle.
* `part` (`string`) – The name of the core part.
* `health` (`number`) – New health value (clamped between 0 and 100).

**Returns**

* `boolean` – `true` if the part was updated successfully, otherwise `false`.

***

## SetAllCorePartsHealth

Sets all core parts of the given vehicle to a specified health value — but only if their current health is lower than the new value.

```lua
exports["t1ger_mechanic"]:SetAllCorePartsHealth(vehicle, value)
```

**Parameters**

* `vehicle` (`integer`) – The vehicle entity handle.
* `value` (`number`) – New health value to apply. Clamped between `0.0` and `100.0`.

**Returns**

* `boolean` – `true` if updated successfully, otherwise `false`.

***

## GetServicePartMileage

Returns the current mileage driven since installation of a specific service part on a vehicle.

```lua
exports["t1ger_mechanic"]:GetServicePartMileage(vehicle, part)
```

**Parameters**

* `vehicle` (`integer`) – The vehicle entity handle.
* `part` (`string`) – The name of the service part (e.g., `"oil_filter"`, `"brake_fluid"`).

**Returns**

* `number` – Mileage driven for the part, or `-1` if the part is not found.

***

## SetServicePartMileage

Sets the mileage value for a specific service part on a vehicle.

```lua
exports["t1ger_mechanic"]:SetServicePartMileage(vehicle, part, mileage)
```

**Parameters**

* `vehicle` (`integer`) – The vehicle entity handle.
* `part` (`string`) – The name of the service part.
* `mileage` (`number`) – New mileage value. Negative values are clamped to `0`.

**Returns**

* `boolean` – `true` if updated successfully, otherwise `false`.

***

## SetAllServicePartsMileage

Sets all service parts to a specified mileage — only affects parts currently above that value.

```lua
exports["t1ger_mechanic"]:SetAllServicePartsMileage(vehicle, value)
```

**Parameters**

* `vehicle` (`integer`) – The vehicle entity handle.
* `value` (`number`) – New mileage value to apply (must be ≥ `0`).

**Returns**

* `boolean` – `true` if updated successfully, otherwise `false`.

***

## GetComponentType

Returns the part category type (`"core_parts"` or `"service_parts"`) for a given part name.

```lua
exports["t1ger_mechanic"]:GetComponentType(part)
```

**Parameters**

* `part` (`string`) – The name of the part (e.g., `"radiator"`, `"oil_filter"`).

**Returns**

* `string|nil` – Returns `"core_parts"` or `"service_parts"` if found, otherwise `nil`.

***

## SetComponentFixed

Fully restores a specified vehicle component by automatically determining its type (`core` or `service`).

{% hint style="info" %}

* **Core parts**: health is set to `100.0` via `SetCorePartHealth`.
* **Service parts**: mileage is reset to `0.0` via `SetServicePartMileage`.
* Adds a service history entry and updates the workflow task if applicable.
  {% endhint %}

```lua
exports["t1ger_mechanic"]:SetComponentFixed(vehicle, partName, partType)
```

**Parameters**

* `vehicle` (`number`) – The vehicle entity handle.
* `partName` (`string`) – The name of the part to restore (e.g., `"radiator"`, `"oil_filter"`).
* `partType` (`string`, optional) – `"core_parts"` or `"service_parts"`. If omitted, the function auto-detects using `GetComponentType`.

***

## IsVehicleElectric

Determines whether a given vehicle is electric.\
Uses native `GetIsVehicleElectric` on game builds `3258+`, otherwise checks the config-defined list.

```lua
exports["t1ger_mechanic"]:IsVehicleElectric(vehicle)
```

**Parameters**

* `vehicle` (`integer`) – The vehicle entity handle.

**Returns**

* `boolean` – `true` if the vehicle is electric, otherwise `false`.

***

## GetMechanicVehicleType

Returns the mechanic-specific vehicle type for the given vehicle: `"electric"` or `"gas"`.

```lua
exports["t1ger_mechanic"]:GetMechanicVehicleType(vehicle)
```

**Parameters**

* `vehicle` (`integer`) – The vehicle entity handle.

**Returns**

* `string` – `"electric"` if the vehicle is electric, otherwise `"gas"`.

***

## IsTrackableVehicle

Checks whether the given vehicle should be tracked for mileage, degradation, and service.\
Excludes blacklisted models and non-trackable vehicle classes (e.g., boats, aircraft, trailers, bicycles).

```lua
exports["t1ger_mechanic"]:IsTrackableVehicle(vehicle)
```

**Parameters**

* `vehicle` (`integer`) – The vehicle entity handle.

**Returns**

* `boolean` – `true` if the vehicle is trackable, otherwise `false`.

***

## DoesVehicleHaveFailuredParts

Checks whether the vehicle has at least one core part in a **failed** condition (`isFailured = true`) based on type compatibility.

```lua
exports["t1ger_mechanic"]:DoesVehicleHaveFailuredParts(vehicle)
```

**Parameters**

* `vehicle` (`integer`) – The vehicle entity handle.

**Returns**

* `boolean` – `true` if one or more core parts are in failure state, otherwise `false`.

***

## ApplyCollisionDegradation

Applies random degradation to core parts of a vehicle as a result of collision, based on compatibility and configuration values. Can be used as integration into existing vehicle-failure-damage scripts

```lua
exports["t1ger_mechanic"]:ApplyCollisionDegradation(vehicle)
```

**Parameters**

* `vehicle` (`entity`) – The vehicle entity handle.

{% hint style="info" %}

* Only applies if:
  * The vehicle is trackable (`IsTrackableVehicle` returns `true`).
  * The local player is the driver.
  * `currentVehicleData` is valid.
* Selects a random number of compatible core parts (gas/electric/shared) and reduces their health by a random percentage within the configured range (`MinPercent`–`MaxPercent`).
* Uses `Config.VehicleCollision.PartCount` to determine how many parts are affected.
  {% endhint %}

***
