# Server

## **TrimPlate**

Trims a given plate.&#x20;

```lua
exports["t1ger_mechanic"]:TrimPlate(plate)
```

#### **Parameters**

* **`plate`***(string)* – The vehicle number plate.

#### **Returns**

* `string` – The trimmed plate.

***

## **IsPlayerEmployee**

Checks if player is an employee of a specific shop or any shop.

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

#### **Parameters**

* **`src`***(number)* – The player source.
* **`shopId?`***(number)* – The ID of the shop you check for. If shopId is nil, it checks all shops.

#### **Returns**

* `boolean` – `true` if employee, otherwise `false`.
* `number|nil`– If employee, then Shop ID is also returne, otherwise `nil`.

***

## IsPlayerMechanicBoss

Checks whether a player is a boss-grade mechanic in a specific mechanic shop or any shop.

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

**Parameters**

* `src` (`number`) – The player's source ID.
* `shopId` (`number|nil`) – *(Optional)* Specific 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` – Shop ID where the player is a boss, or `nil` if not applicable.

***

## IsPlayerShopOwner

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

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

**Parameters**

* `src` (`number`) – The player's source ID.
* `shopId` (`number|nil`) – *(Optional)* Specific 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` – Shop ID the player owns, or `nil` if not applicable.

***

## **RegisterVehicleData**

Registers mileage, core- and service-parts data to database in t1ger\_vehicledata table for a given plate. This can be used when purchasing a car from vehicleshop or using command to turn a vehicle into an owned one.

```lua
exports["t1ger_mechanic"]:RegisterVehicleData(plate)
```

#### **Parameters**

* **`plate`***(string)* – The plate of the vehicle.

***

## **SaveVehicleData**

Saves the vehicle's vehicle-data for given vehicle entity in `t1ger_vehicledata` table in database. Useful if u want to force save a vehicle's vehicle-data.

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

#### **Parameters**

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

#### **Returns**

* `boolean` – `true` if saved succesfully, otherwise `false`.

***

## **UpdateVehicleDataPlate**

Updates a given plate in the `t1ger_vehicledata` table to a new plate. Usefull if using fake plates or plate changer scripts and so on.

```lua
exports["t1ger_mechanic"]:UpdateVehicleDataPlate(currentPlate, newPlate)
```

#### **Parameters**

* **`currentPlate`***(string)* – The current plate to be replaced by `newPlate`
* **`newPlate`***(string)* – The new plate to replace with the `currentPlate`

#### **Returns**

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

***

## AddServiceHistory

Adds a new service history entry to the `t1ger_servicehistory` table in the database for a given vehicle plate.\
This should be used whenever a mechanic performs service on a part and you want to log the action along with mileage, mechanic, and shop data.

```lua
exports["t1ger_mechanic"]:AddServiceHistory(plate, part, mileage, mechanic, shop)
```

**Parameters**

* `plate` (`string`) – The plate of the vehicle.
* `part` (`string`) – The label of the part that was serviced.
* `mileage` (`number`) – The vehicle's mileage at the time of service.
* `mechanic` (`string`) – Identifier of the mechanic who performed the service.
* `shop` (`string`) – Label of the shop or job where the service took place.

**Returns**

* `boolean` – `true` if the history entry was successfully inserted, otherwise `false`.

{% hint style="info" %}

* Only works on vehicles that are already registered (owned).
* Automatically adds the current date (`YYYY-MM-DD`) to the entry.
  {% endhint %}

***

## GetVehicleServiceHistory

Retrieves all recorded service history entries for a specific vehicle plate from the `t1ger_servicehistory` table.\
Only works on owned vehicles and returns entries in reverse chronological order.

```lua
exports["t1ger_mechanic"]:GetVehicleServiceHistory(plate)
```

**Parameters**

* `plate` (`string`) – The plate of the vehicle.

**Returns**

* `table|nil` – A table of service history entries if found, otherwise `nil`.

Each entry contains:

```lua
{
    id = number,
    part = string,
    mileage = number,
    mechanic = string,
    shop = string,
    date = string -- format: YYYY-MM-DD
}
```

***
