> For the complete documentation index, see [llms.txt](https://code-after-sex.gitbook.io/script-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://code-after-sex.gitbook.io/script-documentation/cas-redm-cars/installation.md).

# Installation

Install CAS RedM Cars on a RedM server. Requirements, start order, database tables, the Repair Kit item and the first checks.

## Requirements

* A RedM server with OneSync.
* [oxmysql](https://github.com/overextended/oxmysql).
* VORP Core with `vorp_inventory`. The dealership, garage, fuel and repair scripts detect the framework by themselves (`Config.Framework = "auto"`). They also carry an RSG Core bridge.

## The eight resources

| Resource         | What it does                                                                                                                                         | Needs                                                  |
| ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------ |
| `cas-carplates`  | The licence plate props (six state styles)                                                                                                           |                                                        |
| `cas-car1910`    | The engine of the system: runs every car (parts, engine, fuel, damage, sounds, animations, paint, plates, odometer) and streams the 1910 Touring Car | `cas-carplates`                                        |
| `cas-carpack`    | The 19 other cars as add-on vehicles                                                                                                                 | `cas-car1910`                                          |
| `cas-fuel`       | The fuel pumps                                                                                                                                       | `cas-car1910`                                          |
| `cas-vehiclehud` | The speedometer HUD                                                                                                                                  | `cas-car1910`                                          |
| `cas-dealership` | The dealerships                                                                                                                                      | `oxmysql`, the framework, `cas-car1910`, `cas-carpack` |
| `cas-garage`     | The garages                                                                                                                                          | `oxmysql`, the framework, `cas-dealership`             |
| `cas-carrepair`  | Engine repair with the Repair Kit                                                                                                                    | the framework, `cas-car1910`                           |

## Start order

Put the resources in your `resources` folder and start them in this order, after oxmysql and your framework:

```
ensure oxmysql
ensure vorp_core
ensure vorp_inventory

ensure cas-carplates
ensure cas-car1910
ensure cas-carpack
ensure cas-fuel
ensure cas-vehiclehud
ensure cas-dealership
ensure cas-garage
ensure cas-carrepair
```

## Database

`cas-dealership` and `cas-garage` create their tables on their first start. There is nothing to import.

| Table                       | Holds                                                                                    |
| --------------------------- | ---------------------------------------------------------------------------------------- |
| `cas_dealership_vehicles`   | Every owned car: owner, model, nickname, plate, garage, paint, fuel, engine and odometer |
| `cas_dealership_finance`    | Financed cars and their installments                                                     |
| `cas_dealership_stock`      | Stock per dealership and model                                                           |
| `cas_dealership_reputation` | Each character's reputation per dealership                                               |
| `cas_dealership_favorites`  | Favourite models in the showroom                                                         |
| `cas_garage_state`          | Where each car is: stored, out, lost, destroyed or impounded                             |

## The Repair Kit item

The repair script uses one inventory item, `repair_kit`. Add it to the VORP `items` table with the file that ships in `cas-carrepair/install/repair_kit.sql`:

```sql
INSERT INTO `items` (`item`, `label`, `limit`, `can_remove`, `type`, `usable`, `desc`, `weight`, `metadata`)
VALUES ('repair_kit', 'Repair Kit', 5, 1, 'item_standard', 1,
        'Spanners, a hammer, an oil can and rags for putting a motor car engine right by the roadside.', 1.5, '{}')
ON DUPLICATE KEY UPDATE `label` = VALUES(`label`);
```

Copy the icon `cas-carrepair/install/repair_kit.png` to `vorp_inventory/html/img/items/repair_kit.png`.

{% hint style="warning" %}
vorp\_inventory reads the items table only when it starts. Restart the whole server after adding the item. Do not restart vorp\_inventory on its own: every other script that registered usable items (food, medicine, tools) loses them until it restarts too.
{% endhint %}

## First checks

After the server starts, the console should show:

```
[cas-carrepair] ready (vorp)
[cas-garage] ready (vorp, 1 garages)
[cas-dealership] ready (vorp)
```

In game:

1. As staff, spawn a car with `/carpack` (it lists the cars) and `/carpack duval`.
2. Get in with **E**, start the engine with **X** and drive.
3. Walk to the Saint Denis dealership (map icon) and browse the cars.

## Updating and restarting

{% hint style="danger" %}
`cas-car1910` and `cas-carpack` stream models and data files. Restarting either of them while players are in game can crash those players' games. Restart the server, or make sure nobody is online first. The dealership, garage, HUD and repair scripts can be restarted while players are online.
{% endhint %}

When you restart `cas-car1910`, also start `cas-fuel` again: it stops with it.
