> 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-advanced-inventory/weapons.md).

# Weapons

The weapon screen of CAS Advanced Inventory for RedM. The gun's real 3D model, parts as items, inspect with the game camera, cleaning, unloading, serial and history, weapon limits, CAS Gunsmith and vo

## The weapon screen

Right click a gun in the satchel and choose **INSPECT**. The rider holds the gun up with the game's own inspect camera, and the weapon screen opens beside the satchel:

* **The gun in 3D**, built from the game's own models and textures with every part it carries. Drag to turn it, scroll to zoom, double click to reset.
* **Parts:** scope, sight, barrel, grip, stock and forend slots around the gun, each with its name.
* **How it shoots:** range, accuracy, damage, fire rate and reload, with what each fitted part adds.
* **Upkeep:** condition, dirt and soot.
* **History:** the last things that happened to this gun (bought, given, found, parts changed), with the serial number.

### Keys while the gun is held up

The keys show at the bottom of the screen as game prompts.

| Key   | Action                                                          |
| ----- | --------------------------------------------------------------- |
| V     | Toggle the camera view                                          |
| Z     | Zoom (sidearms)                                                 |
| E     | Aim down the sights                                             |
| R     | Clean the gun (uses one `gun_oil`)                              |
| SPACE | Flip the gun (long guns)                                        |
| H     | Hide the panels for a clean look at the gun, H again shows them |
| F     | Back: puts the gun away and closes the weapon screen            |
| U     | Unload: the rounds go back into the gunbelt                     |
| ESC   | Close the weapon screen                                         |

## Parts are items

Scopes, sights, barrels, grips, stocks and forends are items in the satchel. One item per kind of part: `wpart_scope`, `wpart_sight`, `wpart_barrel`, `wpart_grip`, `wpart_stock`, `wpart_forend`. Which part it is (and for which gun) is in the item's metadata, so a "Gun Barrel" for a Cattleman and one for a Schofield are different stacks.

* **Fit a part:** drag the part item from the satchel onto its slot or onto the gun. While you drag, the screen shows what it changes. The part it replaces goes back into the satchel.
* **Take a part off:** right click a fitted part. It goes into the satchel and the gun gets its factory part back.
* **Factory parts** (the parts a new gun comes with) are free and never become items. They cannot be taken off, only replaced.
* **Parts the game refuses on a gun are never offered** (for example the long scope on repeaters). A gun stored with a part it can no longer take (an old save, a change in `config/parts.lua`) gives that part back into the satchel the next time it is used or inspected, and the rider is told.
* Each change is one transaction: a part is never in two places, and a full satchel refuses the change instead of losing the part.
* Paint, engraving, rifling and wraps are done at a gunsmith, not in the satchel.

The parts list lives in `config/parts.lua` ([Configuration](/script-documentation/cas-advanced-inventory/configuration.md)). The `wpart_*` rows are added to the VORP `items` table on start when they are missing; on RSG they are added to the shared items.

{% hint style="info" %}
Players get part items by taking parts off guns. To sell parts in a shop, give the `wpart_*` item with the part in its metadata: `{ comp = 'COMPONENT_RIFLE_SCOPE02', weapon = 'WEAPON_RIFLE_SPRINGFIELD' }`. A gunsmith bench can use the exports in [For developers](/script-documentation/cas-advanced-inventory/developers.md#weapon-parts-vorp-and-rsg).
{% endhint %}

## Condition, cleaning and ammo

* Guns lose condition and gather dirt and soot as they are used. The client reports it every `Config.Weapons.SyncSeconds` (5 s) while a gun is out.
* **Cleaning** uses one `Config.Weapons.CleanItem` (`gun_oil`), takes off all dirt and soot and gives back `Config.Weapons.CleanRestores` (25 %) condition.
* **Ammo lives in the gunbelt**, not in the satchel. The satchel shows the rounds per ammo type, and the rounds for the gun under the mouse. Ammo caps per type are in `config/ammo.lua`, under the game's names (`AMMO_22` for the Varmint rifle). Ammo box items (vorp\_weaponsv2's, xakra\_weapons', for example) fill the belt when used.
* The server keeps the count. Each ammo type may only go down between two reports; a type that went up in the game (rounds a script gave straight to the ped) is put back to what the satchel holds, and the other guns are left as they are.
* A gun keeps the rounds loaded in it. **Unload** (U) moves them back to the belt.

## How many guns

| Option                        | Default                                        | Meaning                                        |
| ----------------------------- | ---------------------------------------------- | ---------------------------------------------- |
| `Config.Weapons.MaxLong`      | `2`                                            | Long arms equipped at once                     |
| `Config.Weapons.MaxShort`     | `2`                                            | Sidearms equipped at once                      |
| `Config.Weapons.DualWield`    | `true`                                         | Two sidearms at the same time                  |
| `ServerConfig.MaxWeapons`     | `10`                                           | Weapons a character may carry. `-1` = no limit |
| `ServerConfig.MaxWeaponsJobs` | `{ sheriff = 15, police = 15 }`                | Jobs with their own limit                      |
| `ServerConfig.WeaponNoCount`  | binoculars, lanterns, knife, lasso, camera ... | Tools that never count toward the limit        |

## The 3D models

The models are in `html/assets/w3d` (54 weapons, about 28 MB with their textures). Each player downloads them once with the resource. A gun without a model shows its picture instead.

## CAS Gunsmith

With [CAS Gunsmith](https://codeaftersex.com) on the server (`Config.Weapons.Gunsmith = 'cas-gunsmith'`), the bench and the satchel share the parts: a part taken off at the bench lands in the satchel as an item and can be fitted again from the weapon screen.

## vorp\_weaponsv2

* Without CAS Gunsmith, a gun whose parts all come from vorp\_weaponsv2's own bench is handed back to vorp\_weaponsv2 when drawn, as before. The satchel fits every other gun itself.
* **Turn off vorp\_weaponsv2's customization benches** (`customizationLocations = {}` in its config) when you use parts as items. Its bench writes parts straight into the database, past the satchel, so the two can disagree about what is on a gun.

## RSG Core

`rsg-weapons` draws, fires and repairs the guns, so the weapon screen is a VORP feature. The parts exports work on RSG too (the parts are kept in the weapon's `info.componentshash`), so a gunsmith bench can fit and take off parts as items there.
