> 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-weapon-studio/installation.md).

# Installation

Install CAS Weapon Studio on a RedM server. Requirements, server.cfg, staff permission, restart times, the AI key, the database tables and the first start.

## What you need

| Requirement           | Notes                                                                                               |
| --------------------- | --------------------------------------------------------------------------------------------------- |
| RedM server           | The resource is server and client side                                                              |
| oxmysql               | Required. The resource will not start without it                                                    |
| VORP Core or RSG Core | For characters, money, jobs and handing over bought guns. Optional: the script also runs standalone |
| Outside tools         | None. No CodeWalker, no OpenIV                                                                      |

## Install

1. Put the `cas-weaponstudio` folder into your `resources` folder.
2. Add the lines below to `server.cfg`.
3. Give your staff the permission (see [Who may open the studio](#who-may-open-the-studio)).
4. Start the server. The database tables are made on the first start.

{% hint style="warning" %}
Keep the folder name `cas-weaponstudio`. The server side listens on events with that name, so a renamed folder gets no answer from the server.
{% endhint %}

## server.cfg

```cfg
ensure oxmysql
# ... your framework ...
ensure cas-weaponstudio

# who may open the studio (framework admin groups in config.lua work too)
add_ace group.admin cas.weaponstudio allow

# when your server restarts (server local time); shown as "live after the next restart"
set ws_restart_times "06:00,18:00"

# optional: AI Design with your own key (fal, google or openai)
set ws_ai_provider "fal"
set ws_ai_key "YOUR_KEY"
# set ws_ai_model ""   (only to use another model than the default)
```

Start order matters. `oxmysql` and your framework (`vorp_core` or `rsg-core`) must be started before `cas-weaponstudio`: the script looks for the framework once, when it starts.

| Convar             | What it does                                                                                                                                                                                                       |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `ws_restart_times` | Your restart times as `HH:MM`, comma separated, server local time. Only shown in the studio ("Next restart 06:00, in 2 h 10 min"). The script never restarts anything. When set, it replaces `Config.RestartTimes` |
| `ws_ai_provider`   | `fal`, `google` or `openai`. Empty: AI Design is off                                                                                                                                                               |
| `ws_ai_key`        | Your key at that provider. Empty: AI Design is off                                                                                                                                                                 |
| `ws_ai_model`      | Optional. A model other than the provider's default                                                                                                                                                                |

Already running CAS Clothing Studio with an AI key? The Weapon Studio uses `cs_ai_provider`, `cs_ai_key` and `cs_ai_model` when the `ws_ai_*` ones are not set. One key serves every CAS studio.

{% hint style="info" %}
Set the AI key in `server.cfg` only, never in `config.lua`.
{% endhint %}

## Who may open the studio

A player may open the studio when one of these is true:

* They have the ACE `cas.weaponstudio` (`add_ace group.admin cas.weaponstudio allow`). This always works.
* Their framework group is in `Config.AdminGroups` (default `admin`, `superadmin`).

| Framework  | How the group is checked                               |
| ---------- | ------------------------------------------------------ |
| VORP       | The character's group                                  |
| RSG        | `HasPermission` for each group in `Config.AdminGroups` |
| Standalone | No groups: only the ACE works                          |

## Frameworks

The script picks the framework by itself and prints it in the server console: `[cas-weaponstudio] framework: vorp`.

|                   | VORP                                                  | RSG                                            | Standalone                              |
| ----------------- | ----------------------------------------------------- | ---------------------------------------------- | --------------------------------------- |
| Found when        | `vorp_core` is started                                | `rsg-core` is started                          | Neither is started                      |
| A character is    | The selected character                                | The citizen id                                 | The player's license                    |
| Money             | Dollars of the character                              | Cash                                           | Nothing is charged: every price is free |
| Jobs              | The character's job and job grade                     | The job name and grade level                   | No jobs: the job hand-out never matches |
| Bought custom gun | `vorp_inventory` weapon with its name and description | The weapon item with its name in the item info | The weapon is given to the player's ped |

Handing over a custom gun on RSG and on standalone is code only, not verified in game. See [Custom weapons](/script-documentation/cas-weapon-studio/custom-weapons.md).

## The database

These tables are made on the first start. You do not import anything.

| Table                          | What it holds                                                              |
| ------------------------------ | -------------------------------------------------------------------------- |
| `cas_weaponskin_designs`       | The designs: weapon, layers, name, slot and status                         |
| `cas_weaponskin_handout`       | How each skin is handed out: gunsmith towns and price, jobs, players       |
| `cas_weaponskin_pictures`      | The pictures in a design (uploads, AI answers), one per row                |
| `cas_weaponskin_owned`         | Which character owns which skin, and how (bought, gift, with a custom gun) |
| `cas_weaponskin_applied`       | Which skin is on which weapon model of each character                      |
| `cas_weaponskin_kills`         | The kill notches of each character's weapon models                         |
| `cas_weaponskin_editions`      | The custom guns                                                            |
| `cas_weaponskin_edition_owned` | Who bought which custom gun                                                |

Pictures are stored one per row, so each query stays under 1 MB, the default `max_allowed_packet` of XAMPP. If a save still says the database refused the design, raise it in `my.ini` under `[mysqld]` and restart MySQL:

```ini
max_allowed_packet=16M
```

## The first start

The server console shows:

```
[cas-weaponstudio] framework: vorp
[cas-weaponstudio] 0 live skin(s)
[cas-weaponstudio] ready: 73 weapons, 60 free skin slots of 60, AI off
```

Then, in game:

1. Type `/weaponstudio`. The studio opens on the Weapons tab.
2. Pick a weapon, build a skin, press Export. See [Designing skins](/script-documentation/cas-weapon-studio/designing.md) and [Exporting and handing out](/script-documentation/cas-weapon-studio/exporting.md).
3. Restart the server. The skin is live.
4. Stand at a gunsmith with that weapon in your hand and type `/weaponskins`. See [The skin book](/script-documentation/cas-weapon-studio/skin-book.md).

{% hint style="warning" %}
After an export, restart the server as you always do. Do not restart only this resource while players are online: streamed files that change under a running game can crash clients.
{% endhint %}

## Where the skins live

The server builds every exported skin into `cas-weaponstudio/stream/designs/`. The folder is made by the script.

When you replace the resource folder with a new copy, keep `stream/designs/`. A live skin whose files are gone is marked NEEDS EXPORT at the next start: it is not sold and not shown until you export it again.
