# Functions/Events

### client/editable-main.lua

### AI Mechanic Rules

#### Event

```lua
'enyo-aimechanic:client:isMechDispatchAllowed'
```

#### Description

Determines if the AI mechanic is allowed to respond to a player request.

#### Custom Rules (Examples)

You can customize AI restrictions by editing the logic:

```lua
-- Prevent if in combat
if IsPedInCombat(playerPed) then allowed = false end

-- Prevent if in water
if IsEntityInWater(playerPed) then allowed = false end
```

***

### Vehicle Repair Options

#### Quick Fix

```lua
function quickFix(vehicle)
```

Repairs:

* Engine +20% (max 1000)
* Body +20% (max 1000)
* Petrol tank to 1000 health

***

#### Full Repair

```lua
function fullRepair(vehicle)
```

Fully restores vehicle:

* Fixes all parts
* Removes body deformation
* Removes dirt

***

### Police Tow

#### Function

```lua
function policetow(vehicle)
```

#### Description

Flags a vehicle for police towing. If the player is on foot, they perform a writing animation.

***

### Vehicle Storage & Impound

#### Store Vehicle

```lua
function storeVehicle(vehicle)
```

Deletes the vehicle by default. Replace with your garage system

Example:

```lua
exports['my-garage']:storeVehicle(vehicle)
```

***

#### Impound Vehicle

```lua
function impoundVehicle(vehicle)
```

Also deletes the vehicle. Replace with your impound logic.

Example:

```lua
exports['police']:impoundVehicle(vehicle)
```

***

### server/editable-main.lua

### Mechanic Player Count

#### QB-Core Version

```lua
luaCopyEditRegisterServerEvent('countMechPlayers_QB')
AddEventHandler('countMechPlayers_QB', function()
  -- logic here...
end)
```

Connects to **QB-Core** to count players with the mechanic job.

> Increments count only if `PlayerData.job.onduty` is `true` or not explicitly `false`.

***

#### ESX Version

```lua
luaCopyEditRegisterServerEvent('countMechPlayers_ESX')
AddEventHandler('countMechPlayers_ESX', function()
  -- logic here...
end)
```

Uses `ESX.GetExtendedPlayers()` to count mechanics with the defined job name.

***

#### Standalone Version

```lua
luaCopyEditRegisterServerEvent('countMechPlayers_standalone')
AddEventHandler('countMechPlayers_standalone', function()
  -- logic here...
end)
```

> Placeholder logic. Customize based on your standalone player tracking method.

***

### Billing System

#### ESX Version

```lua
luaCopyEditRegisterNetEvent('enyo-aimechanic:esx-billing:sendBill')
AddEventHandler('enyo-aimechanic:esx-billing:sendBill', function(amount, reason)
  -- logic here...
end)
```

* Removes money from bank account.
* Sends notification via `esx:showNotification`.

***

#### QB-Core Version

```lua
luaCopyEditRegisterNetEvent('enyo-aimechanic:qb-billing:sendBill')
AddEventHandler('enyo-aimechanic:qb-billing:sendBill', function(amount, reason)
  -- logic here...
end)
```

* Charges the player through `RemoveMoney('bank')`.
* Uses `QBCore:Notify` for feedback.

***

#### Standalone Version

```lua
luaCopyEditRegisterNetEvent('enyo-aimechanic:billing:sendBill')
AddEventHandler('enyo-aimechanic:billing:sendBill', function(amount, reason)
  -- custom logic placeholder...
end)
```

> Add your custom billing logic here.

***

### Police Permission Check

#### Function: `isAuthorized(source)`

Checks if a player is allowed to use special tow commands.

**ESX Logic**:\
Allowed if:

* Player’s job is in `Config.TowingPermission.jobs`
* Player’s group is in `Config.TowingPermission.groups`

**QB-Core Logic**:\
Allowed if:

* `PlayerData.job.name` is authorized
* Player has admin permission in `Config.TowingPermission.groups`

**Standalone Logic**:\
Allowed if player's identifier is in `Config.TowingPermission.identifiers`

***

#### Event: Police Tow Access

```lua
luaCopyEditRegisterNetEvent("enyo-aimechanic:checkPermissionToTow")
AddEventHandler("enyo-aimechanic:checkPermissionToTow", function()
  -- logic here...
end)
```

* Calls `isAuthorized()` to determine access
* Triggers client event to enable police towing


---

# 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://enyo-scripts.gitbook.io/documentations/fivem-scripts/ai-mechanic-and-towing/functions-events.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.
