> 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-shooting-range/installation.md).

# Installation

Install the RedM Shooting Range & Competition script on VORP Core or RSG Core. server.cfg order, admin permission, Range Token item, Steam avatars and updating.

## Before you start

You need:

* A RedM server running **VORP Core** or **RSG Core**.
* [oxmysql](https://github.com/overextended/oxmysql). The resource stores profiles, match history, practice records and held stakes in MySQL.
* Your framework's inventory: `vorp_inventory` on VORP, `rsg-inventory` on RSG. It is used for Range Tokens (and for gold on RSG).
* On RSG Core, `ox_lib`. Notifications outside the menu are sent through `ox_lib`, which RSG Core already uses.
* Access to `server.cfg` and your database.

You do not need Node.js. The menu ships already built in `web/dist`. You only need Node if you want to [edit the interface](/script-documentation/cas-shooting-range/interface.md).

## 1. Place the folder

Copy `cas-shootingcompetition` into your `resources` folder.

{% hint style="info" %}
Keep the `web/dist` folder. It is the built menu. Without it the range menu cannot open.
{% endhint %}

## 2. Add it to server.cfg

Start it **after** oxmysql and your framework:

```cfg
ensure oxmysql
ensure vorp_core
ensure vorp_inventory
ensure cas-shootingcompetition
```

On RSG Core:

```cfg
ensure oxmysql
ensure ox_lib
ensure rsg-core
ensure rsg-inventory
ensure cas-shootingcompetition
```

## 3. Grant the admin permission

```cfg
add_ace group.admin shootingrange.admin allow
```

Players do not need any permission to shoot, wager or join tournaments. This one is only for `/shootingadmin` and the admin buttons in the menu. See [Permissions and Admin Commands](/script-documentation/cas-shooting-range/permissions.md).

## 4. Add the Range Token item

Range Tokens are the third wager currency. They are a normal inventory item named `range_token`. If you want to use them, add the item to your inventory. If you do not, turn them off in `shared/config.lua` instead:

```lua
Config.Currencies = {
    money  = { enabled = true },
    gold   = { enabled = true, rsgItem = 'gold_bar' },
    custom = { enabled = false, item = 'range_token' },
}
```

**VORP Core**, in the `items` table:

```sql
INSERT INTO `items` (`item`, `label`, `limit`, `can_remove`, `type`, `usable`, `desc`)
VALUES ('range_token', 'Range Token', 200, 1, 'item_standard', 0, 'A token accepted at the shooting range.');
```

Columns can differ between VORP versions. Use an existing row in your table as a reference. To give the item an inventory image, add `vorp_inventory/html/img/items/range_token.png`.

**RSG Core**, in `rsg-core/shared/items.lua`:

```lua
range_token = { name = 'range_token', label = 'Range Token', weight = 0, type = 'item', image = 'range_token.png', unique = false, useable = false, shouldClose = true, description = 'A token accepted at the shooting range.' },
```

### Gold on RSG Core

On VORP, gold is the character's gold currency and needs nothing extra. RSG Core has no gold currency, so gold wagers use an inventory item instead, `gold_bar` by default. If your item list has no `gold_bar`, add it or point `rsgItem` at the gold item you already use. You can also turn gold off with `gold = { enabled = false }`.

## 5. Optional: Steam profile pictures

Player portraits in the menu, on the leaderboards and in the tournament bracket use Steam profile pictures. Add a Steam Web API key for the most reliable result:

```cfg
set steam_webApiKey "YOUR_STEAM_WEB_API_KEY"
```

Without a key, the resource reads the picture from the player's public Steam profile instead. Players without Steam, or with a private profile, get the game's default silhouette. Nothing else is affected.

## 6. Start the server

The five database tables are created on the first start:

| Table               | Holds                                                                              |
| ------------------- | ---------------------------------------------------------------------------------- |
| `shooting_profiles` | Rating, wins, losses, streaks, accuracy totals, personal bests, challenge progress |
| `shooting_history`  | One row per shooter per finished match                                             |
| `shooting_practice` | One row per practice run                                                           |
| `shooting_escrow`   | Stakes and entry fees held for matches and tournaments in progress                 |
| `shooting_pending`  | Payments owed to players who were offline or had a full inventory                  |

There is no SQL file to import. Watch your console. You should see:

```
[shooting] framework: vorp
```

or `[shooting] framework: rsg` on RSG Core. If you see `No supported framework found`, check the `ensure` order above, or set the framework by hand in `shared/config.lua`:

```lua
Config.Framework = 'vorp'   -- 'auto' | 'vorp' | 'rsg'
```

## 7. Check it in game

1. Load a character and open the map. A **Shooting Range** marker sits at the Blackwater Fairground range.
2. Ride there. The range master stands at the menu point.
3. Walk up to him and hold **E** to open the range menu, or hold **G** to go straight to practice.

If the menu opens, the install is done.

## Updating

1. Back up your `shared/config.lua` and any language files you changed in `locales/`.
2. Replace the resource folder with the new version.
3. Put your changes back, or copy the new settings into your backup. New versions can add new settings, and a missing setting in an old config can break a feature.
4. Restart the resource.

Your players' ratings, history, records and challenge progress live in the database and are kept.

{% hint style="warning" %}
Restarting the resource ends every match, lobby and tournament in progress. Every stake and entry fee that was held is refunded automatically the next time each player loads a character. See [Wagers, Entry Fees and Payouts](/script-documentation/cas-shooting-range/wagers.md#restarts-and-crashes).
{% endhint %}
