> For the complete documentation index, see [llms.txt](https://aero-labs.gitbook.io/aero-labs-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://aero-labs.gitbook.io/aero-labs-docs/scripts/avehicleclasses.md).

# AVehicleClasses

Cap vehicle top speeds by class, with a global speed limit for everything else.

![AVehicleClasses](https://3178353394-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fm2Hc1pmEtJtEBI0blIeE%2Fuploads%2Fy7vpq2vt5McUkReF9ZAy%2FAVehicleClasses.jpg?alt=media)

Give every vehicle a top speed based on its class. Sort spawn codes into classes (A, B, C…), give each class a cap in **mph**, and set a global cap for any vehicle you haven't listed. It works the moment a player gets into a vehicle, with no commands needed.

## Requirements

| Dependency                                        | Required | Notes         |
| ------------------------------------------------- | -------- | ------------- |
| [ox\_lib](https://github.com/overextended/ox_lib) | Yes      | Vehicle cache |

AVehicleClasses is **client-side only** and works with any framework.

## Installation

1. Drag the `AVehicleClasses` folder into your `resources` folder.
2. Add it to your `server.cfg` after ox\_lib:

   ```cfg
   ensure ox_lib
   ensure AVehicleClasses
   ```
3. Add your vehicles to the classes in `config.lua`.

## Configuration

```lua
Config.mphValue    = 2.23694 -- m/s to mph conversion, don't change
Config.MaxSpeedCap = 160     -- mph cap for any vehicle NOT listed below

Config.VehicleSpeeds = {
    ["A"] = {
        speed = 155,
        vehicles = { "g920s", "gx135i" },
    },
    ["B"] = {
        speed = 145,
        vehicles = { "blista" },
    },
    -- add as many classes as you like
}
```

| Option                          | Description                                                                |
| ------------------------------- | -------------------------------------------------------------------------- |
| `Config.MaxSpeedCap`            | The overall limit. Unlisted vehicles use it, and no class can go above it. |
| `VehicleSpeeds[class].speed`    | Top speed for that class in mph.                                           |
| `VehicleSpeeds[class].vehicles` | Vehicle names in that class, in **lowercase**.                             |

### Adding a vehicle

1. Pick the class it belongs to, or add a new one such as `["F"] = { speed = 60, vehicles = {} }`.
2. Add the vehicle's name in lowercase.
3. Restart the resource.

{% hint style="warning" %}
The script matches the vehicle's **game name** (the `gameName` value in `vehicles.meta`), not the spawn code. They are usually the same. If a car ignores its class, check its `gameName` and add that instead.
{% endhint %}

## Usage

Nothing to do in game. Get in a vehicle and it is limited to its class speed automatically.
